@matheusbsbs / matheus-bagliano / commits / 7f4bd5d831
Fork 0

rebase: one safety net, one bugfix and one optimization.

When a .dotest from a previously failed rebase or patch application exists, rebase got confused and tried to apply mixture of what was already there and what is being rebased. Check the existence of the directory and barf. It failed with an mysterious "fatal: cannot read mbox" message if the branch being rebased is fully in sync with the base. Also if the branch is a proper descendant of the base, there is no need to run rebase logic. Prevent these from happening by checking where the merge-base is. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Nov 28, 2005 at 13:00 UTC 7f4bd5d831ea838668d1de5f5af022f763230eee
1 file changed +27 -1
git-rebase.sh
+27 -1
@@ -5,9 +5,25 @@
5
6 . git-sh-setup
7
8 -# The other head is given
8 +# Make sure we do not have .dotest
9 +if mkdir .dotest
10 +then
11 + rmdir .dotest
12 +else
13 + echo >&2 '
14 +It seems that I cannot create a .dotest directory, and I wonder if you
15 +are in the middle of patch application or another rebase. If that is not
16 +the case, please rm -fr .dotest and run me again. I am stopping in case
17 +you still have something valuable there.'
18 + exit 1
19 +fi
20 +
21 +# The other head is given. Make sure it is valid.
22 other=$(git-rev-parse --verify "$1^0") || exit
23
24 +# Make sure we have HEAD that is valid.
25 +head=$(git-rev-parse --verify "HEAD^0") || exit
26 +
27 # The tree must be really really clean.
28 git-update-index --refresh || exit
29 diff=$(git-diff-index --cached --name-status -r HEAD)
@@ -23,6 +39,16 @@ case "$#" in
39 git-checkout "$2" || exit
40 esac
41
42 +# If the HEAD is a proper descendant of $other, we do not even need
43 +# to rebase. Make sure we do not do needless rebase. In such a
44 +# case, merge-base should be the same as "$other".
45 +mb=$(git-merge-base "$other" "$head")
46 +if test "$mb" = "$other"
47 +then
48 + echo >&2 "Current branch `git-symbolic-ref HEAD` is up to date."
49 + exit 0
50 +fi
51 +
52 # Rewind the head to "$other"
53 git-reset --hard "$other"
54 git-format-patch -k --stdout --full-index "$other" ORIG_HEAD |