Merge branch 'rs/diff-parseopts-cleanup'
[git/gitster.git] / t / t3407-rebase-abort.sh
blob9f49c4228b629589d7bfcf3435fda8e7c4b308be
1 #!/bin/sh
3 test_description='git rebase --abort tests'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 . ./test-lib.sh
10 test_expect_success setup '
11 test_commit a a a &&
12 git branch to-rebase &&
14 test_commit --annotate b a b &&
15 test_commit --annotate c a c &&
17 git checkout to-rebase &&
18 test_commit "merge should fail on this" a d d &&
19 test_commit --annotate "merge should fail on this, too" a e pre-rebase
22 # Check that HEAD is equal to "pre-rebase" and the current branch is
23 # "to-rebase"
24 check_head() {
25 test_cmp_rev HEAD pre-rebase^{commit} &&
26 test "$(git symbolic-ref HEAD)" = refs/heads/to-rebase
29 testrebase() {
30 type=$1
31 state_dir=$2
33 test_expect_success "rebase$type --abort" '
34 # Clean up the state from the previous one
35 git reset --hard pre-rebase &&
36 test_must_fail git rebase$type main &&
37 test_path_is_dir "$state_dir" &&
38 git rebase --abort &&
39 check_head &&
40 test_path_is_missing "$state_dir"
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
58 test_expect_success "rebase$type --abort after --skip" '
59 # Clean up the state from the previous one
60 git checkout -B to-rebase pre-rebase &&
61 test_must_fail git rebase$type main &&
62 test_path_is_dir "$state_dir" &&
63 test_must_fail git rebase --skip &&
64 test_cmp_rev HEAD main &&
65 git rebase --abort &&
66 check_head &&
67 test_path_is_missing "$state_dir"
70 test_expect_success "rebase$type --abort after --continue" '
71 # Clean up the state from the previous one
72 git reset --hard pre-rebase &&
73 test_must_fail git rebase$type main &&
74 test_path_is_dir "$state_dir" &&
75 echo c > a &&
76 echo d >> a &&
77 git add a &&
78 test_must_fail git rebase --continue &&
79 test_cmp_rev ! HEAD main &&
80 git rebase --abort &&
81 check_head &&
82 test_path_is_missing "$state_dir"
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
95 test_expect_success "rebase$type --abort does not update reflog" '
96 # Clean up the state from the previous one
97 git reset --hard pre-rebase &&
98 git reflog show to-rebase > reflog_before &&
99 test_must_fail git rebase$type main &&
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
106 test_expect_success 'rebase --abort can not be used with other options' '
107 # Clean up the state from the previous one
108 git reset --hard pre-rebase &&
109 test_must_fail git rebase$type main &&
110 test_must_fail git rebase -v --abort &&
111 test_must_fail git rebase --abort -v &&
112 git rebase --abort
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
128 testrebase " --apply" .git/rebase-apply
129 testrebase " --merge" .git/rebase-merge
131 test_done