Merge branch 'fixes/2.45.1/2.41' into fixes/2.45.1/2.42
[alt-git.git] / t / t3407-rebase-abort.sh
blobebbaed147a6ce2156472f45d88a0d300ec6612ac
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 "rebase$type --abort after --skip" '
44 # Clean up the state from the previous one
45 git reset --hard pre-rebase &&
46 test_must_fail git rebase$type main &&
47 test_path_is_dir "$state_dir" &&
48 test_must_fail git rebase --skip &&
49 test_cmp_rev HEAD main &&
50 git rebase --abort &&
51 check_head &&
52 test_path_is_missing "$state_dir"
55 test_expect_success "rebase$type --abort after --continue" '
56 # Clean up the state from the previous one
57 git reset --hard pre-rebase &&
58 test_must_fail git rebase$type main &&
59 test_path_is_dir "$state_dir" &&
60 echo c > a &&
61 echo d >> a &&
62 git add a &&
63 test_must_fail git rebase --continue &&
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 when checking out a tag" '
71 test_when_finished "git symbolic-ref HEAD refs/heads/to-rebase" &&
72 git reset --hard a -- &&
73 test_must_fail git rebase$type --onto b c pre-rebase &&
74 test_cmp_rev HEAD b^{commit} &&
75 git rebase --abort &&
76 test_cmp_rev HEAD pre-rebase^{commit} &&
77 ! git symbolic-ref HEAD
80 test_expect_success "rebase$type --abort does not update reflog" '
81 # Clean up the state from the previous one
82 git reset --hard pre-rebase &&
83 git reflog show to-rebase > reflog_before &&
84 test_must_fail git rebase$type main &&
85 git rebase --abort &&
86 git reflog show to-rebase > reflog_after &&
87 test_cmp reflog_before reflog_after &&
88 rm reflog_before reflog_after
91 test_expect_success 'rebase --abort can not be used with other options' '
92 # Clean up the state from the previous one
93 git reset --hard pre-rebase &&
94 test_must_fail git rebase$type main &&
95 test_must_fail git rebase -v --abort &&
96 test_must_fail git rebase --abort -v &&
97 git rebase --abort
100 test_expect_success "rebase$type --quit" '
101 test_when_finished "git symbolic-ref HEAD refs/heads/to-rebase" &&
102 # Clean up the state from the previous one
103 git reset --hard pre-rebase &&
104 test_must_fail git rebase$type main &&
105 test_path_is_dir $state_dir &&
106 head_before=$(git rev-parse HEAD) &&
107 git rebase --quit &&
108 test_cmp_rev HEAD $head_before &&
109 test_path_is_missing .git/rebase-apply
113 testrebase " --apply" .git/rebase-apply
114 testrebase " --merge" .git/rebase-merge
116 test_done