Raw
1 #!/bin/sh
2
3 test_description='git rebase --continue 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_DIRECTORY"/lib-rebase.sh
11
12 set_fake_editor
13
14 test_expect_success 'setup' '
15 test_commit "commit-new-file-F1" F1 1 &&
16 test_commit "commit-new-file-F2" F2 2 &&
17
18 git checkout -b topic HEAD^ &&
19 test_commit "commit-new-file-F2-on-topic-branch" F2 22 &&
20
21 git checkout main
22 '
23
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 &&
28
29 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
30 test-tool chmtime =-60 F1 &&
31 git rebase --continue
32 '
33
34 test_expect_success 'merge based rebase --continue removes .git/MERGE_MSG' '
35 git checkout -f --detach topic &&
36
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
42 '
43
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 &&
48
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
54 '
55
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
59 '
60
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 &&
67
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
73
74 cat >expect <<-\EOF &&
75 [7]
76 [--option=arg with space]
77 [--op"tion\]
78 [--new
79 line ]
80 [--]
81 EOF
82
83 rm -f actual &&
84 (
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 &&
93 (
94 PATH=./test-bin:$PATH &&
95 git rebase --continue
96 ) &&
97 test_cmp expect actual
98 '
99
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
112 '
113
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 1" wants-fixup.t 1 wants-fixup-1 &&
119 test_commit "fixup 2" wants-fixup.t 2 wants-fixup-2 &&
120 test_commit "fixup 3" 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 &&
123
124 : now there is a conflict, and comments in the commit message &&
125 test_commit_message HEAD <<-\EOF &&
126 # This is a combination of 2 commits.
127 # This is the 1st commit message:
128
129 wants-fixup
130
131 # The commit message #2 will be skipped:
132
133 # fixup 1
134 EOF
135
136 : skip and continue &&
137 test_config commit.status false &&
138 echo "cp \"\$1\" .git/copy.txt" | write_script copy-editor.sh &&
139 (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) &&
140
141 : the user should not have had to edit the commit message &&
142 test_path_is_missing .git/copy.txt &&
143
144 : now the comments in the commit message should have been cleaned up &&
145 test_commit_message HEAD -m wants-fixup &&
146
147 : now, let us ensure that "squash" is handled correctly &&
148 git reset --hard wants-fixup-3 &&
149 test_must_fail env \
150 FAKE_LINES="1 squash 2 squash 1 squash 3 squash 1 squash 4 squash 1" \
151 git rebase -i HEAD~4 &&
152
153 : the second squash failed, but there are two more in the chain &&
154 (test_set_editor "$PWD/copy-editor.sh" &&
155 test_must_fail git rebase --skip) &&
156
157 : not the final squash, no need to edit the commit message &&
158 test_path_is_missing .git/copy.txt &&
159
160 : The first and third squashes succeeded, therefore: &&
161 test_commit_message HEAD <<-\EOF &&
162 # This is a combination of 3 commits.
163 # This is the 1st commit message:
164
165 wants-fixup
166
167 # This is the commit message #2:
168
169 fixup 1
170
171 # This is the commit message #3:
172
173 fixup 2
174 EOF
175
176 (test_set_editor "$PWD/copy-editor.sh" &&
177 test_must_fail git rebase --skip) &&
178 : not the final squash, no need to edit the commit message &&
179 test_path_is_missing .git/copy.txt &&
180
181 : The first, third and fifth squashes succeeded, therefore: &&
182 cat >expect <<-\EOF &&
183 # This is a combination of 4 commits.
184 # This is the 1st commit message:
185
186 wants-fixup
187
188 # This is the commit message #2:
189
190 fixup 1
191
192 # This is the commit message #3:
193
194 fixup 2
195
196 # This is the commit message #4:
197
198 fixup 3
199 EOF
200 test_commit_message HEAD expect &&
201
202 (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) &&
203 test_commit_message HEAD <<-\EOF &&
204 wants-fixup
205
206 fixup 1
207
208 fixup 2
209
210 fixup 3
211 EOF
212
213 : Final squash failed, but there was still a squash &&
214 test_cmp expect .git/copy.txt
215 '
216
217 test_expect_success 'setup rerere database' '
218 rm -fr .git/rebase-* &&
219 git reset --hard commit-new-file-F3-on-topic-branch &&
220 git checkout main &&
221 test_commit "commit-new-file-F3" F3 3 &&
222 test_config rerere.enabled true &&
223 git update-ref refs/heads/topic commit-new-file-F3-on-topic-branch &&
224 test_must_fail git rebase -m main topic &&
225 echo "Resolved" >F2 &&
226 cp F2 expected-F2 &&
227 git add F2 &&
228 test_must_fail git rebase --continue &&
229 echo "Resolved" >F3 &&
230 cp F3 expected-F3 &&
231 git add F3 &&
232 git rebase --continue &&
233 git reset --hard topic@{1}
234 '
235
236 prepare () {
237 rm -fr .git/rebase-* &&
238 git reset --hard commit-new-file-F3-on-topic-branch &&
239 git checkout main &&
240 test_config rerere.enabled true
241 }
242
243 test_rerere_autoupdate () {
244 action=$1 &&
245 test_expect_success "rebase $action --continue remembers --rerere-autoupdate" '
246 prepare &&
247 test_must_fail git rebase $action --rerere-autoupdate main topic &&
248 test_cmp expected-F2 F2 &&
249 git diff-files --quiet &&
250 test_must_fail git rebase --continue &&
251 test_cmp expected-F3 F3 &&
252 git diff-files --quiet &&
253 git rebase --continue
254 '
255
256 test_expect_success "rebase $action --continue honors rerere.autoUpdate" '
257 prepare &&
258 test_config rerere.autoupdate true &&
259 test_must_fail git rebase $action main topic &&
260 test_cmp expected-F2 F2 &&
261 git diff-files --quiet &&
262 test_must_fail git rebase --continue &&
263 test_cmp expected-F3 F3 &&
264 git diff-files --quiet &&
265 git rebase --continue
266 '
267
268 test_expect_success "rebase $action --continue remembers --no-rerere-autoupdate" '
269 prepare &&
270 test_config rerere.autoupdate true &&
271 test_must_fail git rebase $action --no-rerere-autoupdate main topic &&
272 test_cmp expected-F2 F2 &&
273 test_must_fail git diff-files --quiet &&
274 git add F2 &&
275 test_must_fail git rebase --continue &&
276 test_cmp expected-F3 F3 &&
277 test_must_fail git diff-files --quiet &&
278 git add F3 &&
279 git rebase --continue
280 '
281 }
282
283 test_rerere_autoupdate --apply
284 test_rerere_autoupdate -m
285 GIT_SEQUENCE_EDITOR=: && export GIT_SEQUENCE_EDITOR
286 test_rerere_autoupdate -i
287 unset GIT_SEQUENCE_EDITOR
288
289 test_expect_success 'the todo command "break" works' '
290 rm -f execed &&
291 FAKE_LINES="break b exec_>execed" git rebase -i HEAD &&
292 test_path_is_missing execed &&
293 git rebase --continue &&
294 test_path_is_missing execed &&
295 git rebase --continue &&
296 test_path_is_file execed
297 '
298
299 test_expect_success 'patch file is removed before break command' '
300 test_when_finished "git rebase --abort" &&
301 cat >todo <<-\EOF &&
302 pick commit-new-file-F2-on-topic-branch
303 break
304 EOF
305
306 (
307 set_replace_editor todo &&
308 test_must_fail git rebase -i --onto commit-new-file-F2 HEAD
309 ) &&
310 test_path_is_file .git/rebase-merge/patch &&
311 echo 22>F2 &&
312 git add F2 &&
313 git rebase --continue &&
314 test_path_is_missing .git/rebase-merge/patch
315 '
316
317 test_expect_success '--reschedule-failed-exec' '
318 test_when_finished "git rebase --abort" &&
319 test_must_fail git rebase -x false --reschedule-failed-exec HEAD^ &&
320 test_grep "^exec false" .git/rebase-merge/git-rebase-todo &&
321 git rebase --abort &&
322 test_must_fail git -c rebase.rescheduleFailedExec=true \
323 rebase -x false HEAD^ 2>err &&
324 test_grep "^exec false" .git/rebase-merge/git-rebase-todo &&
325 test_grep "has been rescheduled" err
326 '
327
328 test_expect_success 'rebase.rescheduleFailedExec only affects `rebase -i`' '
329 test_config rebase.rescheduleFailedExec true &&
330 test_must_fail git rebase -x false HEAD^ &&
331 test_grep "^exec false" .git/rebase-merge/git-rebase-todo &&
332 git rebase --abort &&
333 git rebase HEAD^
334 '
335
336 test_expect_success 'rebase.rescheduleFailedExec=true & --no-reschedule-failed-exec' '
337 test_when_finished "git rebase --abort" &&
338 test_config rebase.rescheduleFailedExec true &&
339 test_must_fail git rebase -x false --no-reschedule-failed-exec HEAD~2 &&
340 test_must_fail git rebase --continue 2>err &&
341 test_grep ! "has been rescheduled" err
342 '
343
344 test_expect_success 'new rebase.rescheduleFailedExec=true setting in an ongoing rebase is ignored' '
345 test_when_finished "git rebase --abort" &&
346 test_must_fail git rebase -x false HEAD~2 &&
347 test_config rebase.rescheduleFailedExec true &&
348 test_must_fail git rebase --continue 2>err &&
349 test_grep ! "has been rescheduled" err
350 '
351
352 test_expect_success 'there is no --no-reschedule-failed-exec in an ongoing rebase' '
353 test_when_finished "git rebase --abort" &&
354 test_must_fail git rebase -x false HEAD~2 &&
355 test_expect_code 129 git rebase --continue --no-reschedule-failed-exec &&
356 test_expect_code 129 git rebase --edit-todo --no-reschedule-failed-exec
357 '
358
359 test_expect_success !WITH_BREAKING_CHANGES 'no change in comment character due to conflicts markers with core.commentChar=auto' '
360 git checkout -b branch-a &&
361 test_commit A F1 &&
362 git checkout -b branch-b HEAD^ &&
363 test_commit B F1 &&
364 test_must_fail git rebase branch-a &&
365 printf "B\nA\n" >F1 &&
366 git add F1 &&
367 GIT_EDITOR="cat >actual" git -c core.commentChar=auto rebase --continue &&
368 # Check that "#" is still the comment character.
369 test_grep "^# Changes to be committed" actual
370 '
371
372 test_orig_head_helper () {
373 test_when_finished 'git rebase --abort &&
374 git checkout topic &&
375 git reset --hard commit-new-file-F2-on-topic-branch' &&
376 git update-ref -d ORIG_HEAD &&
377 test_must_fail git rebase "$@" &&
378 test_cmp_rev ORIG_HEAD commit-new-file-F2-on-topic-branch
379 }
380
381 test_orig_head () {
382 type=$1
383 test_expect_success "rebase $type sets ORIG_HEAD correctly" '
384 git checkout topic &&
385 git reset --hard commit-new-file-F2-on-topic-branch &&
386 test_orig_head_helper $type main
387 '
388
389 test_expect_success "rebase $type <upstream> <branch> sets ORIG_HEAD correctly" '
390 git checkout main &&
391 test_orig_head_helper $type main topic
392 '
393 }
394
395 test_orig_head --apply
396 test_orig_head --merge
397
398 test_done