]>
Commit | Line | Data |
---|---|---|
3ebfe63a MH |
1 | #!/bin/sh |
2 | ||
3 | test_description='git rebase --abort tests' | |
4 | ||
d1c02d93 | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
7 | ||
3ebfe63a MH |
8 | . ./test-lib.sh |
9 | ||
10 | test_expect_success setup ' | |
e505f452 | 11 | test_commit a a a && |
3ebfe63a MH |
12 | git branch to-rebase && |
13 | ||
7740ac69 PW |
14 | test_commit --annotate b a b && |
15 | test_commit --annotate c a c && | |
3ebfe63a MH |
16 | |
17 | git checkout to-rebase && | |
e505f452 | 18 | test_commit "merge should fail on this" a d d && |
7740ac69 | 19 | test_commit --annotate "merge should fail on this, too" a e pre-rebase |
3ebfe63a MH |
20 | ' |
21 | ||
1e14bc11 PW |
22 | # Check that HEAD is equal to "pre-rebase" and the current branch is |
23 | # "to-rebase" | |
24 | check_head() { | |
7740ac69 | 25 | test_cmp_rev HEAD pre-rebase^{commit} && |
1e14bc11 PW |
26 | test "$(git symbolic-ref HEAD)" = refs/heads/to-rebase |
27 | } | |
28 | ||
4947cf9c MH |
29 | testrebase() { |
30 | type=$1 | |
54627db0 | 31 | state_dir=$2 |
3ebfe63a | 32 | |
4947cf9c MH |
33 | test_expect_success "rebase$type --abort" ' |
34 | # Clean up the state from the previous one | |
97b88dd5 | 35 | git reset --hard pre-rebase && |
d1c02d93 | 36 | test_must_fail git rebase$type main && |
54627db0 | 37 | test_path_is_dir "$state_dir" && |
4947cf9c | 38 | git rebase --abort && |
1e14bc11 | 39 | check_head && |
0b7ae738 | 40 | test_path_is_missing "$state_dir" |
4947cf9c | 41 | ' |
3ebfe63a | 42 | |
bc7f5db8 PW |
43 | test_expect_success "pre rebase$type head is marked as reachable" ' |
44 | # Clean up the state from the previous one | |
45 | git checkout -f --detach pre-rebase && | |
46 | test_tick && | |
47 | git commit --amend --only -m "reworded" && | |
48 | orig_head=$(git rev-parse HEAD) && | |
49 | test_must_fail git rebase$type main && | |
50 | # Stop ORIG_HEAD marking $state_dir/orig-head as reachable | |
51 | git update-ref -d ORIG_HEAD && | |
52 | git reflog expire --expire="$GIT_COMMITTER_DATE" --all && | |
53 | git prune --expire=now && | |
54 | git rebase --abort && | |
55 | test_cmp_rev $orig_head HEAD | |
56 | ' | |
57 | ||
4947cf9c MH |
58 | test_expect_success "rebase$type --abort after --skip" ' |
59 | # Clean up the state from the previous one | |
bc7f5db8 | 60 | git checkout -B to-rebase pre-rebase && |
d1c02d93 | 61 | test_must_fail git rebase$type main && |
54627db0 | 62 | test_path_is_dir "$state_dir" && |
4947cf9c | 63 | test_must_fail git rebase --skip && |
7390c65d | 64 | test_cmp_rev HEAD main && |
0cb0e143 | 65 | git rebase --abort && |
1e14bc11 | 66 | check_head && |
0b7ae738 | 67 | test_path_is_missing "$state_dir" |
4947cf9c | 68 | ' |
3ebfe63a | 69 | |
4947cf9c MH |
70 | test_expect_success "rebase$type --abort after --continue" ' |
71 | # Clean up the state from the previous one | |
97b88dd5 | 72 | git reset --hard pre-rebase && |
d1c02d93 | 73 | test_must_fail git rebase$type main && |
54627db0 | 74 | test_path_is_dir "$state_dir" && |
4947cf9c MH |
75 | echo c > a && |
76 | echo d >> a && | |
77 | git add a && | |
78 | test_must_fail git rebase --continue && | |
7390c65d | 79 | test_cmp_rev ! HEAD main && |
4947cf9c | 80 | git rebase --abort && |
1e14bc11 | 81 | check_head && |
0b7ae738 | 82 | test_path_is_missing "$state_dir" |
4947cf9c | 83 | ' |
729ec9e2 | 84 | |
7740ac69 PW |
85 | test_expect_success "rebase$type --abort when checking out a tag" ' |
86 | test_when_finished "git symbolic-ref HEAD refs/heads/to-rebase" && | |
87 | git reset --hard a -- && | |
88 | test_must_fail git rebase$type --onto b c pre-rebase && | |
89 | test_cmp_rev HEAD b^{commit} && | |
90 | git rebase --abort && | |
91 | test_cmp_rev HEAD pre-rebase^{commit} && | |
92 | ! git symbolic-ref HEAD | |
93 | ' | |
94 | ||
729ec9e2 | 95 | test_expect_success "rebase$type --abort does not update reflog" ' |
729ec9e2 MZ |
96 | # Clean up the state from the previous one |
97 | git reset --hard pre-rebase && | |
98 | git reflog show to-rebase > reflog_before && | |
d1c02d93 | 99 | test_must_fail git rebase$type main && |
729ec9e2 MZ |
100 | git rebase --abort && |
101 | git reflog show to-rebase > reflog_after && | |
102 | test_cmp reflog_before reflog_after && | |
103 | rm reflog_before reflog_after | |
104 | ' | |
95135b06 MZ |
105 | |
106 | test_expect_success 'rebase --abort can not be used with other options' ' | |
95135b06 MZ |
107 | # Clean up the state from the previous one |
108 | git reset --hard pre-rebase && | |
d1c02d93 | 109 | test_must_fail git rebase$type main && |
95135b06 MZ |
110 | test_must_fail git rebase -v --abort && |
111 | test_must_fail git rebase --abort -v && | |
112 | git rebase --abort | |
113 | ' | |
d045719a PW |
114 | |
115 | test_expect_success "rebase$type --quit" ' | |
116 | test_when_finished "git symbolic-ref HEAD refs/heads/to-rebase" && | |
117 | # Clean up the state from the previous one | |
118 | git reset --hard pre-rebase && | |
119 | test_must_fail git rebase$type main && | |
120 | test_path_is_dir $state_dir && | |
121 | head_before=$(git rev-parse HEAD) && | |
122 | git rebase --quit && | |
123 | test_cmp_rev HEAD $head_before && | |
124 | test_path_is_missing .git/rebase-apply | |
125 | ' | |
4947cf9c | 126 | } |
3ebfe63a | 127 | |
10cdb9f3 | 128 | testrebase " --apply" .git/rebase-apply |
28ed6e7b | 129 | testrebase " --merge" .git/rebase-merge |
3ebfe63a MH |
130 | |
131 | test_done |