Merge branch 'cl/config-regexp-docfix' into maint-2.46
[git/gitster.git] / t / t3407-rebase-abort.sh
blob2c3f38d45a848260995967cfce91a38cacfe82ee
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_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 test_expect_success setup '
12 test_commit a a a &&
13 git branch to-rebase &&
15 test_commit --annotate b a b &&
16 test_commit --annotate c a c &&
18 git checkout to-rebase &&
19 test_commit "merge should fail on this" a d d &&
20 test_commit --annotate "merge should fail on this, too" a e pre-rebase
23 # Check that HEAD is equal to "pre-rebase" and the current branch is
24 # "to-rebase"
25 check_head() {
26 test_cmp_rev HEAD pre-rebase^{commit} &&
27 test "$(git symbolic-ref HEAD)" = refs/heads/to-rebase
30 testrebase() {
31 type=$1
32 state_dir=$2
34 test_expect_success "rebase$type --abort" '
35 # Clean up the state from the previous one
36 git reset --hard pre-rebase &&
37 test_must_fail git rebase$type main &&
38 test_path_is_dir "$state_dir" &&
39 git rebase --abort &&
40 check_head &&
41 test_path_is_missing "$state_dir"
44 test_expect_success "pre rebase$type head is marked as reachable" '
45 # Clean up the state from the previous one
46 git checkout -f --detach pre-rebase &&
47 test_tick &&
48 git commit --amend --only -m "reworded" &&
49 orig_head=$(git rev-parse HEAD) &&
50 test_must_fail git rebase$type main &&
51 # Stop ORIG_HEAD marking $state_dir/orig-head as reachable
52 git update-ref -d ORIG_HEAD &&
53 git reflog expire --expire="$GIT_COMMITTER_DATE" --all &&
54 git prune --expire=now &&
55 git rebase --abort &&
56 test_cmp_rev $orig_head HEAD
59 test_expect_success "rebase$type --abort after --skip" '
60 # Clean up the state from the previous one
61 git checkout -B to-rebase pre-rebase &&
62 test_must_fail git rebase$type main &&
63 test_path_is_dir "$state_dir" &&
64 test_must_fail git rebase --skip &&
65 test_cmp_rev HEAD main &&
66 git rebase --abort &&
67 check_head &&
68 test_path_is_missing "$state_dir"
71 test_expect_success "rebase$type --abort after --continue" '
72 # Clean up the state from the previous one
73 git reset --hard pre-rebase &&
74 test_must_fail git rebase$type main &&
75 test_path_is_dir "$state_dir" &&
76 echo c > a &&
77 echo d >> a &&
78 git add a &&
79 test_must_fail git rebase --continue &&
80 test_cmp_rev ! HEAD main &&
81 git rebase --abort &&
82 check_head &&
83 test_path_is_missing "$state_dir"
86 test_expect_success "rebase$type --abort when checking out a tag" '
87 test_when_finished "git symbolic-ref HEAD refs/heads/to-rebase" &&
88 git reset --hard a -- &&
89 test_must_fail git rebase$type --onto b c pre-rebase &&
90 test_cmp_rev HEAD b^{commit} &&
91 git rebase --abort &&
92 test_cmp_rev HEAD pre-rebase^{commit} &&
93 ! git symbolic-ref HEAD
96 test_expect_success "rebase$type --abort does not update reflog" '
97 # Clean up the state from the previous one
98 git reset --hard pre-rebase &&
99 git reflog show to-rebase > reflog_before &&
100 test_must_fail git rebase$type main &&
101 git rebase --abort &&
102 git reflog show to-rebase > reflog_after &&
103 test_cmp reflog_before reflog_after &&
104 rm reflog_before reflog_after
107 test_expect_success 'rebase --abort can not be used with other options' '
108 # Clean up the state from the previous one
109 git reset --hard pre-rebase &&
110 test_must_fail git rebase$type main &&
111 test_must_fail git rebase -v --abort &&
112 test_must_fail git rebase --abort -v &&
113 git rebase --abort
116 test_expect_success "rebase$type --quit" '
117 test_when_finished "git symbolic-ref HEAD refs/heads/to-rebase" &&
118 # Clean up the state from the previous one
119 git reset --hard pre-rebase &&
120 test_must_fail git rebase$type main &&
121 test_path_is_dir $state_dir &&
122 head_before=$(git rev-parse HEAD) &&
123 git rebase --quit &&
124 test_cmp_rev HEAD $head_before &&
125 test_path_is_missing .git/rebase-apply
129 testrebase " --apply" .git/rebase-apply
130 testrebase " --merge" .git/rebase-merge
132 test_done