]> git.ipfire.org Git - thirdparty/git.git/blob - t/t3407-rebase-abort.sh
t3905: move all commands into test cases
[thirdparty/git.git] / t / t3407-rebase-abort.sh
1 #!/bin/sh
2
3 test_description='git rebase --abort tests'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 . ./test-lib.sh
9
10 ### Test that we handle space characters properly
11 work_dir="$(pwd)/test dir"
12
13 test_expect_success setup '
14 mkdir -p "$work_dir" &&
15 cd "$work_dir" &&
16 git init &&
17 echo a > a &&
18 git add a &&
19 git commit -m a &&
20 git branch to-rebase &&
21
22 echo b > a &&
23 git commit -a -m b &&
24 echo c > a &&
25 git commit -a -m c &&
26
27 git checkout to-rebase &&
28 echo d > a &&
29 git commit -a -m "merge should fail on this" &&
30 echo e > a &&
31 git commit -a -m "merge should fail on this, too" &&
32 git branch pre-rebase
33 '
34
35 testrebase() {
36 type=$1
37 dotest=$2
38
39 test_expect_success "rebase$type --abort" '
40 cd "$work_dir" &&
41 # Clean up the state from the previous one
42 git reset --hard pre-rebase &&
43 test_must_fail git rebase$type main &&
44 test_path_is_dir "$dotest" &&
45 git rebase --abort &&
46 test $(git rev-parse to-rebase) = $(git rev-parse pre-rebase) &&
47 test ! -d "$dotest"
48 '
49
50 test_expect_success "rebase$type --abort after --skip" '
51 cd "$work_dir" &&
52 # Clean up the state from the previous one
53 git reset --hard pre-rebase &&
54 test_must_fail git rebase$type main &&
55 test_path_is_dir "$dotest" &&
56 test_must_fail git rebase --skip &&
57 test $(git rev-parse HEAD) = $(git rev-parse main) &&
58 git rebase --abort &&
59 test $(git rev-parse to-rebase) = $(git rev-parse pre-rebase) &&
60 test ! -d "$dotest"
61 '
62
63 test_expect_success "rebase$type --abort after --continue" '
64 cd "$work_dir" &&
65 # Clean up the state from the previous one
66 git reset --hard pre-rebase &&
67 test_must_fail git rebase$type main &&
68 test_path_is_dir "$dotest" &&
69 echo c > a &&
70 echo d >> a &&
71 git add a &&
72 test_must_fail git rebase --continue &&
73 test $(git rev-parse HEAD) != $(git rev-parse main) &&
74 git rebase --abort &&
75 test $(git rev-parse to-rebase) = $(git rev-parse pre-rebase) &&
76 test ! -d "$dotest"
77 '
78
79 test_expect_success "rebase$type --abort does not update reflog" '
80 cd "$work_dir" &&
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
89 '
90
91 test_expect_success 'rebase --abort can not be used with other options' '
92 cd "$work_dir" &&
93 # Clean up the state from the previous one
94 git reset --hard pre-rebase &&
95 test_must_fail git rebase$type main &&
96 test_must_fail git rebase -v --abort &&
97 test_must_fail git rebase --abort -v &&
98 git rebase --abort
99 '
100 }
101
102 testrebase " --apply" .git/rebase-apply
103 testrebase " --merge" .git/rebase-merge
104
105 test_expect_success 'rebase --apply --quit' '
106 cd "$work_dir" &&
107 # Clean up the state from the previous one
108 git reset --hard pre-rebase &&
109 test_must_fail git rebase --apply main &&
110 test_path_is_dir .git/rebase-apply &&
111 head_before=$(git rev-parse HEAD) &&
112 git rebase --quit &&
113 test $(git rev-parse HEAD) = $head_before &&
114 test ! -d .git/rebase-apply
115 '
116
117 test_expect_success 'rebase --merge --quit' '
118 cd "$work_dir" &&
119 # Clean up the state from the previous one
120 git reset --hard pre-rebase &&
121 test_must_fail git rebase --merge main &&
122 test_path_is_dir .git/rebase-merge &&
123 head_before=$(git rev-parse HEAD) &&
124 git rebase --quit &&
125 test $(git rev-parse HEAD) = $head_before &&
126 test ! -d .git/rebase-merge
127 '
128
129 test_done