]> git.ipfire.org Git - thirdparty/git.git/blame - git-rebase.sh
pack-objects: hash basename and direname a bit differently.
[thirdparty/git.git] / git-rebase.sh
CommitLineData
59e6b23a
JH
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano.
4#
5
3ae39ab2 6USAGE='<upstream> [<head>]'
ae2b0f15 7. git-sh-setup
4282c4fb 8
2db8aaec
JH
9case $# in 1|2) ;; *) usage ;; esac
10
7f4bd5d8
JH
11# Make sure we do not have .dotest
12if mkdir .dotest
13then
14 rmdir .dotest
15else
16 echo >&2 '
17It seems that I cannot create a .dotest directory, and I wonder if you
18are in the middle of patch application or another rebase. If that is not
19the case, please rm -fr .dotest and run me again. I am stopping in case
20you still have something valuable there.'
21 exit 1
22fi
23
7f59dbbb 24# The tree must be really really clean.
215a7ad1 25git-update-index --refresh || exit
7f59dbbb 26diff=$(git-diff-index --cached --name-status -r HEAD)
32d99544 27case "$diff" in
7f59dbbb
JH
28?*) echo "$diff"
29 exit 1
30 ;;
31esac
99a92f92 32
32d99544
LS
33# The other head is given. Make sure it is valid.
34other=$(git-rev-parse --verify "$1^0") || usage
35
36# Make sure the branch to rebase is valid.
37head=$(git-rev-parse --verify "${2-HEAD}^0") || exit
38
9a111c91
JH
39# If a hook exists, give it a chance to interrupt
40if test -x "$GIT_DIR/hooks/pre-rebase"
41then
42 "$GIT_DIR/hooks/pre-rebase" ${1+"$@"} || {
43 echo >&2 "The pre-rebase hook refused to rebase."
44 exit 1
45 }
46fi
47
7f59dbbb 48# If the branch to rebase is given, first switch to it.
59e6b23a 49case "$#" in
7f59dbbb 502)
3ae39ab2 51 git-checkout "$2" || usage
59e6b23a
JH
52esac
53
7f4bd5d8 54mb=$(git-merge-base "$other" "$head")
32d99544
LS
55
56# Check if we are already based on $other.
7f4bd5d8
JH
57if test "$mb" = "$other"
58then
59 echo >&2 "Current branch `git-symbolic-ref HEAD` is up to date."
60 exit 0
61fi
62
7f59dbbb
JH
63# Rewind the head to "$other"
64git-reset --hard "$other"
32d99544
LS
65
66# If the $other is a proper descendant of the tip of the branch, then
67# we just fast forwarded.
68if test "$mb" = "$head"
69then
70 echo >&2 "Fast-forwarded $head to $other."
71 exit 0
72fi
73
7f59dbbb
JH
74git-format-patch -k --stdout --full-index "$other" ORIG_HEAD |
75git am --binary -3 -k