Skip to content

Commit 32d9954

Browse files
Lukas SandströmJunio C Hamano
authored andcommitted
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>
1 parent e0e3ba2 commit 32d9954

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

git-rebase.sh

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,30 @@ you still have something valuable there.'
2121
exit 1
2222
fi
2323

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-
3024
# The tree must be really really clean.
3125
git-update-index --refresh || exit
3226
diff=$(git-diff-index --cached --name-status -r HEAD)
33-
case "$different" in
27+
case "$diff" in
3428
?*) echo "$diff"
3529
exit 1
3630
;;
3731
esac
3832

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+
3939
# If the branch to rebase is given, first switch to it.
4040
case "$#" in
4141
2)
42-
head=$(git-rev-parse --verify "$2^") || usage
4342
git-checkout "$2" || usage
4443
esac
4544

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".
4945
mb=$(git-merge-base "$other" "$head")
46+
47+
# Check if we are already based on $other.
5048
if test "$mb" = "$other"
5149
then
5250
echo >&2 "Current branch `git-symbolic-ref HEAD` is up to date."
@@ -55,5 +53,14 @@ fi
5553

5654
# Rewind the head to "$other"
5755
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+
5865
git-format-patch -k --stdout --full-index "$other" ORIG_HEAD |
5966
git am --binary -3 -k

0 commit comments

Comments
 (0)