@matheusbsbs / matheus-bagliano / commits / 32d9954478
Fork 0

Bugfixes for git-rebase

Fix bugs in git-rebase wrt rebasing another branch than the current HEAD, rebasing with a dirty working dir, and rebasing a proper decendant of the target branch. [jc: with a bit of hand-merging] Signed-off-by: Lukas Sandström <lukass@etek.chalmers.se> Signed-off-by: Junio C Hamano <junkio@cox.net>

Lukas Sandström committed Dec 15, 2005 at 00:36 UTC 32d9954478734da4062cf2ffc2faf2d057e47fb6
1 file changed +18 -11
git-rebase.sh
+18 -11
@@ -21,32 +21,30 @@ you still have something valuable there.'
21 exit 1
22 fi
23
24 -# The other head is given. Make sure it is valid.
25 -other=$(git-rev-parse --verify "$1^0") || usage
26 -
27 -# Make sure we have HEAD that is valid.
28 -head=$(git-rev-parse --verify "HEAD^0") || exit
29 -
24 # The tree must be really really clean.
25 git-update-index --refresh || exit
26 diff=$(git-diff-index --cached --name-status -r HEAD)
33 -case "$different" in
27 +case "$diff" in
28 ?*) echo "$diff"
29 exit 1
30 ;;
31 esac
32
33 +# The other head is given. Make sure it is valid.
34 +other=$(git-rev-parse --verify "$1^0") || usage
35 +
36 +# Make sure the branch to rebase is valid.
37 +head=$(git-rev-parse --verify "${2-HEAD}^0") || exit
38 +
39 # If the branch to rebase is given, first switch to it.
40 case "$#" in
41 2)
42 - head=$(git-rev-parse --verify "$2^") || usage
42 git-checkout "$2" || usage
43 esac
44
46 -# If the HEAD is a proper descendant of $other, we do not even need
47 -# to rebase. Make sure we do not do needless rebase. In such a
48 -# case, merge-base should be the same as "$other".
45 mb=$(git-merge-base "$other" "$head")
46 +
47 +# Check if we are already based on $other.
48 if test "$mb" = "$other"
49 then
50 echo >&2 "Current branch `git-symbolic-ref HEAD` is up to date."
@@ -55,5 +53,14 @@ fi
53
54 # Rewind the head to "$other"
55 git-reset --hard "$other"
56 +
57 +# If the $other is a proper descendant of the tip of the branch, then
58 +# we just fast forwarded.
59 +if test "$mb" = "$head"
60 +then
61 + echo >&2 "Fast-forwarded $head to $other."
62 + exit 0
63 +fi
64 +
65 git-format-patch -k --stdout --full-index "$other" ORIG_HEAD |
66 git am --binary -3 -k