]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3418-rebase-continue.sh
Sync with Git 2.45.1
[thirdparty/git.git] / t / t3418-rebase-continue.sh
CommitLineData
25e93250
DK
1#!/bin/sh
2
3test_description='git rebase --continue tests'
4
d1c02d93 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
25e93250
DK
8. ./test-lib.sh
9
10. "$TEST_DIRECTORY"/lib-rebase.sh
11
12set_fake_editor
13
14test_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
d1c02d93 21 git checkout main
25e93250
DK
22'
23
bed9b4e3 24test_expect_success 'merge based rebase --continue with works with touched file' '
25e93250
DK
25 rm -fr .git/rebase-* &&
26 git reset --hard &&
d1c02d93 27 git checkout main &&
25e93250
DK
28
29 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
0e496492 30 test-tool chmtime =-60 F1 &&
25e93250
DK
31 git rebase --continue
32'
33
e5ee33e8
PW
34test_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
bed9b4e3 44test_expect_success 'apply based rebase --continue works with touched file' '
25e93250
DK
45 rm -fr .git/rebase-* &&
46 git reset --hard &&
d1c02d93 47 git checkout main &&
25e93250 48
bed9b4e3 49 test_must_fail git rebase --apply --onto main main topic &&
25e93250
DK
50 echo "Resolved" >F2 &&
51 git add F2 &&
0e496492 52 test-tool chmtime =-60 F1 &&
25e93250
DK
53 git rebase --continue
54'
55
95135b06
MZ
56test_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
80ff4795
MZ
61test_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 &&
4960e5c7 65 test_when_finished "rm -fr test-bin" &&
80ff4795 66 mkdir test-bin &&
4960e5c7
PW
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 "$@"
80ff4795 72 EOF
4960e5c7
PW
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 &&
80ff4795 84 (
3ea67379 85 PATH=./test-bin:$PATH &&
4960e5c7
PW
86 test_must_fail git rebase -s funny -X"option=arg with space" \
87 -Xop\"tion\\ -X"new${LF}line " main topic
80ff4795 88 ) &&
4960e5c7
PW
89 test_cmp expect actual &&
90 rm actual &&
80ff4795
MZ
91 echo "Resolved" >F2 &&
92 git add F2 &&
93 (
3ea67379 94 PATH=./test-bin:$PATH &&
80ff4795
MZ
95 git rebase --continue
96 ) &&
4960e5c7 97 test_cmp expect actual
80ff4795 98'
dd6fb005 99
a63f990d
JS
100test_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
dd6fb005 112'
d5bc6f29 113
15ef6931 114test_expect_success '--skip after failed fixup cleans commit message' '
d5bc6f29
JS
115 test_when_finished "test_might_fail git rebase --abort" &&
116 git checkout -b with-conflicting-fixup &&
117 test_commit wants-fixup &&
6ce7afe1
PW
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 &&
15ef6931 121 test_must_fail env FAKE_LINES="1 fixup 2 squash 4" \
d5bc6f29
JS
122 git rebase -i HEAD~4 &&
123
124 : now there is a conflict, and comments in the commit message &&
6ce7afe1
PW
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
d5bc6f29
JS
135
136 : skip and continue &&
15ef6931
JS
137 echo "cp \"\$1\" .git/copy.txt" | write_script copy-editor.sh &&
138 (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) &&
139
140 : the user should not have had to edit the commit message &&
141 test_path_is_missing .git/copy.txt &&
d5bc6f29
JS
142
143 : now the comments in the commit message should have been cleaned up &&
6ce7afe1 144 test_commit_message HEAD -m wants-fixup &&
15ef6931
JS
145
146 : now, let us ensure that "squash" is handled correctly &&
147 git reset --hard wants-fixup-3 &&
6ce7afe1 148 test_must_fail env FAKE_LINES="1 squash 2 squash 1 squash 3 squash 1" \
15ef6931
JS
149 git rebase -i HEAD~4 &&
150
6ce7afe1 151 : the second squash failed, but there are two more in the chain &&
15ef6931
JS
152 (test_set_editor "$PWD/copy-editor.sh" &&
153 test_must_fail git rebase --skip) &&
154
155 : not the final squash, no need to edit the commit message &&
156 test_path_is_missing .git/copy.txt &&
157
6ce7afe1
PW
158 : The first and third squashes succeeded, therefore: &&
159 test_commit_message HEAD <<-\EOF &&
160 # This is a combination of 3 commits.
161 # This is the 1st commit message:
162
163 wants-fixup
164
165 # This is the commit message #2:
166
167 fixup 1
168
169 # This is the commit message #3:
170
171 fixup 2
172 EOF
15ef6931
JS
173
174 (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) &&
6ce7afe1
PW
175 test_commit_message HEAD <<-\EOF &&
176 wants-fixup
177
178 fixup 1
179
180 fixup 2
181 EOF
15ef6931
JS
182
183 : Final squash failed, but there was still a squash &&
6ce7afe1 184 head -n1 .git/copy.txt >first-line &&
6789275d
JH
185 test_grep "# This is a combination of 3 commits" first-line &&
186 test_grep "# This is the commit message #3:" .git/copy.txt
d5bc6f29 187'
80ff4795 188
5fb415b5 189test_expect_success 'setup rerere database' '
b3e4847e
MZ
190 rm -fr .git/rebase-* &&
191 git reset --hard commit-new-file-F3-on-topic-branch &&
d1c02d93 192 git checkout main &&
b3e4847e 193 test_commit "commit-new-file-F3" F3 3 &&
5fb415b5 194 test_config rerere.enabled true &&
5ee4ef8b 195 git update-ref refs/heads/topic commit-new-file-F3-on-topic-branch &&
d1c02d93 196 test_must_fail git rebase -m main topic &&
b3e4847e 197 echo "Resolved" >F2 &&
5fb415b5 198 cp F2 expected-F2 &&
b3e4847e
MZ
199 git add F2 &&
200 test_must_fail git rebase --continue &&
201 echo "Resolved" >F3 &&
5fb415b5 202 cp F3 expected-F3 &&
b3e4847e
MZ
203 git add F3 &&
204 git rebase --continue &&
5fb415b5 205 git reset --hard topic@{1}
b3e4847e
MZ
206'
207
5fb415b5
PW
208prepare () {
209 rm -fr .git/rebase-* &&
210 git reset --hard commit-new-file-F3-on-topic-branch &&
d1c02d93 211 git checkout main &&
5fb415b5
PW
212 test_config rerere.enabled true
213}
214
215test_rerere_autoupdate () {
216 action=$1 &&
217 test_expect_success "rebase $action --continue remembers --rerere-autoupdate" '
218 prepare &&
d1c02d93 219 test_must_fail git rebase $action --rerere-autoupdate main topic &&
5fb415b5
PW
220 test_cmp expected-F2 F2 &&
221 git diff-files --quiet &&
222 test_must_fail git rebase --continue &&
223 test_cmp expected-F3 F3 &&
224 git diff-files --quiet &&
225 git rebase --continue
226 '
227
228 test_expect_success "rebase $action --continue honors rerere.autoUpdate" '
229 prepare &&
230 test_config rerere.autoupdate true &&
d1c02d93 231 test_must_fail git rebase $action main topic &&
5fb415b5
PW
232 test_cmp expected-F2 F2 &&
233 git diff-files --quiet &&
234 test_must_fail git rebase --continue &&
235 test_cmp expected-F3 F3 &&
236 git diff-files --quiet &&
237 git rebase --continue
238 '
239
240 test_expect_success "rebase $action --continue remembers --no-rerere-autoupdate" '
241 prepare &&
242 test_config rerere.autoupdate true &&
d1c02d93 243 test_must_fail git rebase $action --no-rerere-autoupdate main topic &&
5fb415b5
PW
244 test_cmp expected-F2 F2 &&
245 test_must_fail git diff-files --quiet &&
246 git add F2 &&
247 test_must_fail git rebase --continue &&
248 test_cmp expected-F3 F3 &&
249 test_must_fail git diff-files --quiet &&
250 git add F3 &&
251 git rebase --continue
252 '
253}
254
bed9b4e3 255test_rerere_autoupdate --apply
5fb415b5 256test_rerere_autoupdate -m
9b6d7a62
PW
257GIT_SEQUENCE_EDITOR=: && export GIT_SEQUENCE_EDITOR
258test_rerere_autoupdate -i
71f82465
JS
259unset GIT_SEQUENCE_EDITOR
260
261test_expect_success 'the todo command "break" works' '
262 rm -f execed &&
3a4a4cab
JS
263 FAKE_LINES="break b exec_>execed" git rebase -i HEAD &&
264 test_path_is_missing execed &&
265 git rebase --continue &&
71f82465
JS
266 test_path_is_missing execed &&
267 git rebase --continue &&
268 test_path_is_file execed
269'
5fb415b5 270
206a78d7
PW
271test_expect_success 'patch file is removed before break command' '
272 test_when_finished "git rebase --abort" &&
273 cat >todo <<-\EOF &&
274 pick commit-new-file-F2-on-topic-branch
275 break
276 EOF
277
278 (
279 set_replace_editor todo &&
280 test_must_fail git rebase -i --onto commit-new-file-F2 HEAD
281 ) &&
282 test_path_is_file .git/rebase-merge/patch &&
283 echo 22>F2 &&
284 git add F2 &&
285 git rebase --continue &&
286 test_path_is_missing .git/rebase-merge/patch
287'
288
d421afa0
JS
289test_expect_success '--reschedule-failed-exec' '
290 test_when_finished "git rebase --abort" &&
291 test_must_fail git rebase -x false --reschedule-failed-exec HEAD^ &&
969de3ff
JS
292 grep "^exec false" .git/rebase-merge/git-rebase-todo &&
293 git rebase --abort &&
294 test_must_fail git -c rebase.rescheduleFailedExec=true \
295 rebase -x false HEAD^ 2>err &&
296 grep "^exec false" .git/rebase-merge/git-rebase-todo &&
6789275d 297 test_grep "has been rescheduled" err
d421afa0
JS
298'
299
cd663df7
ÆAB
300test_expect_success 'rebase.rescheduleFailedExec only affects `rebase -i`' '
301 test_config rebase.rescheduleFailedExec true &&
906b6394
JS
302 test_must_fail git rebase -x false HEAD^ &&
303 grep "^exec false" .git/rebase-merge/git-rebase-todo &&
304 git rebase --abort &&
305 git rebase HEAD^
306'
307
e5b32bff
ÆAB
308test_expect_success 'rebase.rescheduleFailedExec=true & --no-reschedule-failed-exec' '
309 test_when_finished "git rebase --abort" &&
310 test_config rebase.rescheduleFailedExec true &&
311 test_must_fail git rebase -x false --no-reschedule-failed-exec HEAD~2 &&
312 test_must_fail git rebase --continue 2>err &&
313 ! grep "has been rescheduled" err
314'
315
316test_expect_success 'new rebase.rescheduleFailedExec=true setting in an ongoing rebase is ignored' '
317 test_when_finished "git rebase --abort" &&
318 test_must_fail git rebase -x false HEAD~2 &&
319 test_config rebase.rescheduleFailedExec true &&
320 test_must_fail git rebase --continue 2>err &&
321 ! grep "has been rescheduled" err
322'
323
324test_expect_success 'there is no --no-reschedule-failed-exec in an ongoing rebase' '
325 test_when_finished "git rebase --abort" &&
326 test_must_fail git rebase -x false HEAD~2 &&
327 test_expect_code 129 git rebase --continue --no-reschedule-failed-exec &&
328 test_expect_code 129 git rebase --edit-todo --no-reschedule-failed-exec
329'
330
cd1528ef
PW
331test_orig_head_helper () {
332 test_when_finished 'git rebase --abort &&
333 git checkout topic &&
334 git reset --hard commit-new-file-F2-on-topic-branch' &&
335 git update-ref -d ORIG_HEAD &&
336 test_must_fail git rebase "$@" &&
337 test_cmp_rev ORIG_HEAD commit-new-file-F2-on-topic-branch
338}
339
340test_orig_head () {
341 type=$1
342 test_expect_success "rebase $type sets ORIG_HEAD correctly" '
343 git checkout topic &&
344 git reset --hard commit-new-file-F2-on-topic-branch &&
345 test_orig_head_helper $type main
346 '
347
348 test_expect_success "rebase $type <upstream> <branch> sets ORIG_HEAD correctly" '
349 git checkout main &&
350 test_orig_head_helper $type main topic
351 '
352}
353
354test_orig_head --apply
355test_orig_head --merge
356
25e93250 357test_done