rebase: remove a couple of redundant strategy tests
[git/gitster.git] / t / t3418-rebase-continue.sh
blob2d0789e554bf00a604a347ab0e9c7b3781e4a96a
1 #!/bin/sh
3 test_description='git rebase --continue tests'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 . ./test-lib.sh
10 . "$TEST_DIRECTORY"/lib-rebase.sh
12 set_fake_editor
14 test_expect_success 'setup' '
15 test_commit "commit-new-file-F1" F1 1 &&
16 test_commit "commit-new-file-F2" F2 2 &&
18 git checkout -b topic HEAD^ &&
19 test_commit "commit-new-file-F2-on-topic-branch" F2 22 &&
21 git checkout main
24 test_expect_success 'merge based rebase --continue with works with touched file' '
25 rm -fr .git/rebase-* &&
26 git reset --hard &&
27 git checkout main &&
29 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
30 test-tool chmtime =-60 F1 &&
31 git rebase --continue
34 test_expect_success 'merge based rebase --continue removes .git/MERGE_MSG' '
35 git checkout -f --detach topic &&
37 test_must_fail git rebase --onto main HEAD^ &&
38 git read-tree --reset -u HEAD &&
39 test_path_is_file .git/MERGE_MSG &&
40 git rebase --continue &&
41 test_path_is_missing .git/MERGE_MSG
44 test_expect_success 'apply based rebase --continue works with touched file' '
45 rm -fr .git/rebase-* &&
46 git reset --hard &&
47 git checkout main &&
49 test_must_fail git rebase --apply --onto main main topic &&
50 echo "Resolved" >F2 &&
51 git add F2 &&
52 test-tool chmtime =-60 F1 &&
53 git rebase --continue
56 test_expect_success 'rebase --continue can not be used with other options' '
57 test_must_fail git rebase -v --continue &&
58 test_must_fail git rebase --continue -v
61 test_expect_success 'rebase --continue remembers merge strategy and options' '
62 rm -fr .git/rebase-* &&
63 git reset --hard commit-new-file-F2-on-topic-branch &&
64 test_commit "commit-new-file-F3-on-topic-branch" F3 32 &&
65 test_when_finished "rm -fr test-bin" &&
66 mkdir test-bin &&
68 write_script test-bin/git-merge-funny <<-\EOF &&
69 printf "[%s]\n" $# "$1" "$2" "$3" "$5" >actual
70 shift 3 &&
71 exec git merge-recursive "$@"
72 EOF
74 cat >expect <<-\EOF &&
75 [7]
76 [--option=arg with space]
77 [--op"tion\]
78 [--new
79 line ]
80 [--]
81 EOF
83 rm -f actual &&
85 PATH=./test-bin:$PATH &&
86 test_must_fail git rebase -s funny -X"option=arg with space" \
87 -Xop\"tion\\ -X"new${LF}line " main topic
88 ) &&
89 test_cmp expect actual &&
90 rm actual &&
91 echo "Resolved" >F2 &&
92 git add F2 &&
94 PATH=./test-bin:$PATH &&
95 git rebase --continue
96 ) &&
97 test_cmp expect actual
100 test_expect_success 'rebase -r passes merge strategy options correctly' '
101 rm -fr .git/rebase-* &&
102 git reset --hard commit-new-file-F3-on-topic-branch &&
103 test_commit merge-theirs &&
104 git reset --hard HEAD^ &&
105 test_commit some-other-commit &&
106 test_tick &&
107 git merge --no-ff merge-theirs &&
108 FAKE_LINES="1 3 edit 4 5 7 8 9" git rebase -i -f -r -m \
109 -s recursive --strategy-option=theirs HEAD~2 &&
110 test_commit force-change-ours &&
111 git rebase --continue
114 test_expect_success '--skip after failed fixup cleans commit message' '
115 test_when_finished "test_might_fail git rebase --abort" &&
116 git checkout -b with-conflicting-fixup &&
117 test_commit wants-fixup &&
118 test_commit "fixup! wants-fixup" wants-fixup.t 1 wants-fixup-1 &&
119 test_commit "fixup! wants-fixup" wants-fixup.t 2 wants-fixup-2 &&
120 test_commit "fixup! wants-fixup" wants-fixup.t 3 wants-fixup-3 &&
121 test_must_fail env FAKE_LINES="1 fixup 2 squash 4" \
122 git rebase -i HEAD~4 &&
124 : now there is a conflict, and comments in the commit message &&
125 git show HEAD >out &&
126 grep "fixup! wants-fixup" out &&
128 : skip and continue &&
129 echo "cp \"\$1\" .git/copy.txt" | write_script copy-editor.sh &&
130 (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) &&
132 : the user should not have had to edit the commit message &&
133 test_path_is_missing .git/copy.txt &&
135 : now the comments in the commit message should have been cleaned up &&
136 git show HEAD >out &&
137 ! grep "fixup! wants-fixup" out &&
139 : now, let us ensure that "squash" is handled correctly &&
140 git reset --hard wants-fixup-3 &&
141 test_must_fail env FAKE_LINES="1 squash 4 squash 2 squash 4" \
142 git rebase -i HEAD~4 &&
144 : the first squash failed, but there are two more in the chain &&
145 (test_set_editor "$PWD/copy-editor.sh" &&
146 test_must_fail git rebase --skip) &&
148 : not the final squash, no need to edit the commit message &&
149 test_path_is_missing .git/copy.txt &&
151 : The first squash was skipped, therefore: &&
152 git show HEAD >out &&
153 test_i18ngrep "# This is a combination of 2 commits" out &&
154 test_i18ngrep "# This is the commit message #2:" out &&
156 (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) &&
157 git show HEAD >out &&
158 test_i18ngrep ! "# This is a combination" out &&
160 : Final squash failed, but there was still a squash &&
161 test_i18ngrep "# This is a combination of 2 commits" .git/copy.txt &&
162 test_i18ngrep "# This is the commit message #2:" .git/copy.txt
165 test_expect_success 'setup rerere database' '
166 rm -fr .git/rebase-* &&
167 git reset --hard commit-new-file-F3-on-topic-branch &&
168 git checkout main &&
169 test_commit "commit-new-file-F3" F3 3 &&
170 test_config rerere.enabled true &&
171 git update-ref refs/heads/topic commit-new-file-F3-on-topic-branch &&
172 test_must_fail git rebase -m main topic &&
173 echo "Resolved" >F2 &&
174 cp F2 expected-F2 &&
175 git add F2 &&
176 test_must_fail git rebase --continue &&
177 echo "Resolved" >F3 &&
178 cp F3 expected-F3 &&
179 git add F3 &&
180 git rebase --continue &&
181 git reset --hard topic@{1}
184 prepare () {
185 rm -fr .git/rebase-* &&
186 git reset --hard commit-new-file-F3-on-topic-branch &&
187 git checkout main &&
188 test_config rerere.enabled true
191 test_rerere_autoupdate () {
192 action=$1 &&
193 test_expect_success "rebase $action --continue remembers --rerere-autoupdate" '
194 prepare &&
195 test_must_fail git rebase $action --rerere-autoupdate main topic &&
196 test_cmp expected-F2 F2 &&
197 git diff-files --quiet &&
198 test_must_fail git rebase --continue &&
199 test_cmp expected-F3 F3 &&
200 git diff-files --quiet &&
201 git rebase --continue
204 test_expect_success "rebase $action --continue honors rerere.autoUpdate" '
205 prepare &&
206 test_config rerere.autoupdate true &&
207 test_must_fail git rebase $action main topic &&
208 test_cmp expected-F2 F2 &&
209 git diff-files --quiet &&
210 test_must_fail git rebase --continue &&
211 test_cmp expected-F3 F3 &&
212 git diff-files --quiet &&
213 git rebase --continue
216 test_expect_success "rebase $action --continue remembers --no-rerere-autoupdate" '
217 prepare &&
218 test_config rerere.autoupdate true &&
219 test_must_fail git rebase $action --no-rerere-autoupdate main topic &&
220 test_cmp expected-F2 F2 &&
221 test_must_fail git diff-files --quiet &&
222 git add F2 &&
223 test_must_fail git rebase --continue &&
224 test_cmp expected-F3 F3 &&
225 test_must_fail git diff-files --quiet &&
226 git add F3 &&
227 git rebase --continue
231 test_rerere_autoupdate --apply
232 test_rerere_autoupdate -m
233 GIT_SEQUENCE_EDITOR=: && export GIT_SEQUENCE_EDITOR
234 test_rerere_autoupdate -i
235 unset GIT_SEQUENCE_EDITOR
237 test_expect_success 'the todo command "break" works' '
238 rm -f execed &&
239 FAKE_LINES="break b exec_>execed" git rebase -i HEAD &&
240 test_path_is_missing execed &&
241 git rebase --continue &&
242 test_path_is_missing execed &&
243 git rebase --continue &&
244 test_path_is_file execed
247 test_expect_success '--reschedule-failed-exec' '
248 test_when_finished "git rebase --abort" &&
249 test_must_fail git rebase -x false --reschedule-failed-exec HEAD^ &&
250 grep "^exec false" .git/rebase-merge/git-rebase-todo &&
251 git rebase --abort &&
252 test_must_fail git -c rebase.rescheduleFailedExec=true \
253 rebase -x false HEAD^ 2>err &&
254 grep "^exec false" .git/rebase-merge/git-rebase-todo &&
255 test_i18ngrep "has been rescheduled" err
258 test_expect_success 'rebase.rescheduleFailedExec only affects `rebase -i`' '
259 test_config rebase.rescheduleFailedExec true &&
260 test_must_fail git rebase -x false HEAD^ &&
261 grep "^exec false" .git/rebase-merge/git-rebase-todo &&
262 git rebase --abort &&
263 git rebase HEAD^
266 test_expect_success 'rebase.rescheduleFailedExec=true & --no-reschedule-failed-exec' '
267 test_when_finished "git rebase --abort" &&
268 test_config rebase.rescheduleFailedExec true &&
269 test_must_fail git rebase -x false --no-reschedule-failed-exec HEAD~2 &&
270 test_must_fail git rebase --continue 2>err &&
271 ! grep "has been rescheduled" err
274 test_expect_success 'new rebase.rescheduleFailedExec=true setting in an ongoing rebase is ignored' '
275 test_when_finished "git rebase --abort" &&
276 test_must_fail git rebase -x false HEAD~2 &&
277 test_config rebase.rescheduleFailedExec true &&
278 test_must_fail git rebase --continue 2>err &&
279 ! grep "has been rescheduled" err
282 test_expect_success 'there is no --no-reschedule-failed-exec in an ongoing rebase' '
283 test_when_finished "git rebase --abort" &&
284 test_must_fail git rebase -x false HEAD~2 &&
285 test_expect_code 129 git rebase --continue --no-reschedule-failed-exec &&
286 test_expect_code 129 git rebase --edit-todo --no-reschedule-failed-exec
289 test_orig_head_helper () {
290 test_when_finished 'git rebase --abort &&
291 git checkout topic &&
292 git reset --hard commit-new-file-F2-on-topic-branch' &&
293 git update-ref -d ORIG_HEAD &&
294 test_must_fail git rebase "$@" &&
295 test_cmp_rev ORIG_HEAD commit-new-file-F2-on-topic-branch
298 test_orig_head () {
299 type=$1
300 test_expect_success "rebase $type sets ORIG_HEAD correctly" '
301 git checkout topic &&
302 git reset --hard commit-new-file-F2-on-topic-branch &&
303 test_orig_head_helper $type main
306 test_expect_success "rebase $type <upstream> <branch> sets ORIG_HEAD correctly" '
307 git checkout main &&
308 test_orig_head_helper $type main topic
312 test_orig_head --apply
313 test_orig_head --merge
315 test_done