@matheusbsbs / matheus-bagliano / commits / 4201bb5f7e
Fork 0

git rebase --abort: always restore the right commit

Previously, --abort would end by git resetting to ORIG_HEAD, but some commands, such as git reset --hard (which happened in git rebase --skip, but could just as well be typed by the user), would have already modified ORIG_HEAD. Just use the orig-head we store in $dotest instead. [jc: cherry-picked from 48411d and 4947cf9 on 'master'] Signed-off-by: Mike Hommey <mh@glandium.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Mike Hommey committed Mar 1, 2008 at 11:32 UTC 4201bb5f7e408143dc5bf35497cc82bc803fe9fb
2 files changed +73 -3
git-rebase.sh
+2 -3
@@ -208,16 +208,15 @@ do
208 if test -d "$dotest"
209 then
210 move_to_original_branch
211 - rm -r "$dotest"
211 elif test -d .dotest
212 then
213 dotest=.dotest
214 move_to_original_branch
216 - rm -r .dotest
215 else
216 die "No rebase in progress?"
217 fi
220 - git reset --hard ORIG_HEAD
218 + git reset --hard $(cat $dotest/orig-head)
219 + rm -r "$dotest"
220 exit
221 ;;
222 --onto)
t/t3407-rebase-abort.sh new
+71
@@ -0,0 +1,71 @@
1 +#!/bin/sh
2 +
3 +test_description='git rebase --abort tests'
4 +
5 +. ./test-lib.sh
6 +
7 +test_expect_success setup '
8 + echo a > a &&
9 + git add a &&
10 + git commit -m a &&
11 + git branch to-rebase &&
12 +
13 + echo b > a &&
14 + git commit -a -m b &&
15 + echo c > a &&
16 + git commit -a -m c &&
17 +
18 + git checkout to-rebase &&
19 + echo d > a &&
20 + git commit -a -m "merge should fail on this" &&
21 + echo e > a &&
22 + git commit -a -m "merge should fail on this, too" &&
23 + git branch pre-rebase
24 +'
25 +
26 +testrebase() {
27 + type=$1
28 + dotest=$2
29 +
30 + test_expect_success "rebase$type --abort" '
31 + # Clean up the state from the previous one
32 + git reset --hard pre-rebase
33 + test_must_fail git rebase'"$type"' master &&
34 + test -d '$dotest' &&
35 + git rebase --abort &&
36 + test $(git rev-parse to-rebase) = $(git rev-parse pre-rebase) &&
37 + test ! -d '$dotest'
38 + '
39 +
40 + test_expect_success "rebase$type --abort after --skip" '
41 + # Clean up the state from the previous one
42 + git reset --hard pre-rebase
43 + test_must_fail git rebase'"$type"' master &&
44 + test -d '$dotest' &&
45 + test_must_fail git rebase --skip &&
46 + test $(git rev-parse HEAD) = $(git rev-parse master) &&
47 + git-rebase --abort &&
48 + test $(git rev-parse to-rebase) = $(git rev-parse pre-rebase) &&
49 + test ! -d '$dotest'
50 + '
51 +
52 + test_expect_success "rebase$type --abort after --continue" '
53 + # Clean up the state from the previous one
54 + git reset --hard pre-rebase
55 + test_must_fail git rebase'"$type"' master &&
56 + test -d '$dotest' &&
57 + echo c > a &&
58 + echo d >> a &&
59 + git add a &&
60 + test_must_fail git rebase --continue &&
61 + test $(git rev-parse HEAD) != $(git rev-parse master) &&
62 + git rebase --abort &&
63 + test $(git rev-parse to-rebase) = $(git rev-parse pre-rebase) &&
64 + test ! -d '$dotest'
65 + '
66 +}
67 +
68 +testrebase "" .dotest
69 +testrebase " --merge" .git/.dotest-merge
70 +
71 +test_done