revision: fix leaking parents when simplifying commits
[git/gitster.git] / t / t3418-rebase-continue.sh
blobc0d29c2154f0b4eff481352fd1acb0bb1f3c2331
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_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 . "$TEST_DIRECTORY"/lib-rebase.sh
13 set_fake_editor
15 test_expect_success 'setup' '
16 test_commit "commit-new-file-F1" F1 1 &&
17 test_commit "commit-new-file-F2" F2 2 &&
19 git checkout -b topic HEAD^ &&
20 test_commit "commit-new-file-F2-on-topic-branch" F2 22 &&
22 git checkout main
25 test_expect_success 'merge based rebase --continue with works with touched file' '
26 rm -fr .git/rebase-* &&
27 git reset --hard &&
28 git checkout main &&
30 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
31 test-tool chmtime =-60 F1 &&
32 git rebase --continue
35 test_expect_success 'merge based rebase --continue removes .git/MERGE_MSG' '
36 git checkout -f --detach topic &&
38 test_must_fail git rebase --onto main HEAD^ &&
39 git read-tree --reset -u HEAD &&
40 test_path_is_file .git/MERGE_MSG &&
41 git rebase --continue &&
42 test_path_is_missing .git/MERGE_MSG
45 test_expect_success 'apply based rebase --continue works with touched file' '
46 rm -fr .git/rebase-* &&
47 git reset --hard &&
48 git checkout main &&
50 test_must_fail git rebase --apply --onto main main topic &&
51 echo "Resolved" >F2 &&
52 git add F2 &&
53 test-tool chmtime =-60 F1 &&
54 git rebase --continue
57 test_expect_success 'rebase --continue can not be used with other options' '
58 test_must_fail git rebase -v --continue &&
59 test_must_fail git rebase --continue -v
62 test_expect_success 'rebase --continue remembers merge strategy and options' '
63 rm -fr .git/rebase-* &&
64 git reset --hard commit-new-file-F2-on-topic-branch &&
65 test_commit "commit-new-file-F3-on-topic-branch" F3 32 &&
66 test_when_finished "rm -fr test-bin" &&
67 mkdir test-bin &&
69 write_script test-bin/git-merge-funny <<-\EOF &&
70 printf "[%s]\n" $# "$1" "$2" "$3" "$5" >actual
71 shift 3 &&
72 exec git merge-recursive "$@"
73 EOF
75 cat >expect <<-\EOF &&
76 [7]
77 [--option=arg with space]
78 [--op"tion\]
79 [--new
80 line ]
81 [--]
82 EOF
84 rm -f actual &&
86 PATH=./test-bin:$PATH &&
87 test_must_fail git rebase -s funny -X"option=arg with space" \
88 -Xop\"tion\\ -X"new${LF}line " main topic
89 ) &&
90 test_cmp expect actual &&
91 rm actual &&
92 echo "Resolved" >F2 &&
93 git add F2 &&
95 PATH=./test-bin:$PATH &&
96 git rebase --continue
97 ) &&
98 test_cmp expect actual
101 test_expect_success 'rebase -r passes merge strategy options correctly' '
102 rm -fr .git/rebase-* &&
103 git reset --hard commit-new-file-F3-on-topic-branch &&
104 test_commit merge-theirs &&
105 git reset --hard HEAD^ &&
106 test_commit some-other-commit &&
107 test_tick &&
108 git merge --no-ff merge-theirs &&
109 FAKE_LINES="1 3 edit 4 5 7 8 9" git rebase -i -f -r -m \
110 -s recursive --strategy-option=theirs HEAD~2 &&
111 test_commit force-change-ours &&
112 git rebase --continue
115 test_expect_success '--skip after failed fixup cleans commit message' '
116 test_when_finished "test_might_fail git rebase --abort" &&
117 git checkout -b with-conflicting-fixup &&
118 test_commit wants-fixup &&
119 test_commit "fixup 1" wants-fixup.t 1 wants-fixup-1 &&
120 test_commit "fixup 2" wants-fixup.t 2 wants-fixup-2 &&
121 test_commit "fixup 3" wants-fixup.t 3 wants-fixup-3 &&
122 test_must_fail env FAKE_LINES="1 fixup 2 squash 4" \
123 git rebase -i HEAD~4 &&
125 : now there is a conflict, and comments in the commit message &&
126 test_commit_message HEAD <<-\EOF &&
127 # This is a combination of 2 commits.
128 # This is the 1st commit message:
130 wants-fixup
132 # The commit message #2 will be skipped:
134 # fixup 1
137 : skip and continue &&
138 echo "cp \"\$1\" .git/copy.txt" | write_script copy-editor.sh &&
139 (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) &&
141 : the user should not have had to edit the commit message &&
142 test_path_is_missing .git/copy.txt &&
144 : now the comments in the commit message should have been cleaned up &&
145 test_commit_message HEAD -m wants-fixup &&
147 : now, let us ensure that "squash" is handled correctly &&
148 git reset --hard wants-fixup-3 &&
149 test_must_fail env FAKE_LINES="1 squash 2 squash 1 squash 3 squash 1" \
150 git rebase -i HEAD~4 &&
152 : the second squash failed, but there are two more in the chain &&
153 (test_set_editor "$PWD/copy-editor.sh" &&
154 test_must_fail git rebase --skip) &&
156 : not the final squash, no need to edit the commit message &&
157 test_path_is_missing .git/copy.txt &&
159 : The first and third squashes succeeded, therefore: &&
160 test_commit_message HEAD <<-\EOF &&
161 # This is a combination of 3 commits.
162 # This is the 1st commit message:
164 wants-fixup
166 # This is the commit message #2:
168 fixup 1
170 # This is the commit message #3:
172 fixup 2
175 (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) &&
176 test_commit_message HEAD <<-\EOF &&
177 wants-fixup
179 fixup 1
181 fixup 2
184 : Final squash failed, but there was still a squash &&
185 head -n1 .git/copy.txt >first-line &&
186 test_grep "# This is a combination of 3 commits" first-line &&
187 test_grep "# This is the commit message #3:" .git/copy.txt
190 test_expect_success 'setup rerere database' '
191 rm -fr .git/rebase-* &&
192 git reset --hard commit-new-file-F3-on-topic-branch &&
193 git checkout main &&
194 test_commit "commit-new-file-F3" F3 3 &&
195 test_config rerere.enabled true &&
196 git update-ref refs/heads/topic commit-new-file-F3-on-topic-branch &&
197 test_must_fail git rebase -m main topic &&
198 echo "Resolved" >F2 &&
199 cp F2 expected-F2 &&
200 git add F2 &&
201 test_must_fail git rebase --continue &&
202 echo "Resolved" >F3 &&
203 cp F3 expected-F3 &&
204 git add F3 &&
205 git rebase --continue &&
206 git reset --hard topic@{1}
209 prepare () {
210 rm -fr .git/rebase-* &&
211 git reset --hard commit-new-file-F3-on-topic-branch &&
212 git checkout main &&
213 test_config rerere.enabled true
216 test_rerere_autoupdate () {
217 action=$1 &&
218 test_expect_success "rebase $action --continue remembers --rerere-autoupdate" '
219 prepare &&
220 test_must_fail git rebase $action --rerere-autoupdate main topic &&
221 test_cmp expected-F2 F2 &&
222 git diff-files --quiet &&
223 test_must_fail git rebase --continue &&
224 test_cmp expected-F3 F3 &&
225 git diff-files --quiet &&
226 git rebase --continue
229 test_expect_success "rebase $action --continue honors rerere.autoUpdate" '
230 prepare &&
231 test_config rerere.autoupdate true &&
232 test_must_fail git rebase $action main topic &&
233 test_cmp expected-F2 F2 &&
234 git diff-files --quiet &&
235 test_must_fail git rebase --continue &&
236 test_cmp expected-F3 F3 &&
237 git diff-files --quiet &&
238 git rebase --continue
241 test_expect_success "rebase $action --continue remembers --no-rerere-autoupdate" '
242 prepare &&
243 test_config rerere.autoupdate true &&
244 test_must_fail git rebase $action --no-rerere-autoupdate main topic &&
245 test_cmp expected-F2 F2 &&
246 test_must_fail git diff-files --quiet &&
247 git add F2 &&
248 test_must_fail git rebase --continue &&
249 test_cmp expected-F3 F3 &&
250 test_must_fail git diff-files --quiet &&
251 git add F3 &&
252 git rebase --continue
256 test_rerere_autoupdate --apply
257 test_rerere_autoupdate -m
258 GIT_SEQUENCE_EDITOR=: && export GIT_SEQUENCE_EDITOR
259 test_rerere_autoupdate -i
260 unset GIT_SEQUENCE_EDITOR
262 test_expect_success 'the todo command "break" works' '
263 rm -f execed &&
264 FAKE_LINES="break b exec_>execed" git rebase -i HEAD &&
265 test_path_is_missing execed &&
266 git rebase --continue &&
267 test_path_is_missing execed &&
268 git rebase --continue &&
269 test_path_is_file execed
272 test_expect_success 'patch file is removed before break command' '
273 test_when_finished "git rebase --abort" &&
274 cat >todo <<-\EOF &&
275 pick commit-new-file-F2-on-topic-branch
276 break
280 set_replace_editor todo &&
281 test_must_fail git rebase -i --onto commit-new-file-F2 HEAD
282 ) &&
283 test_path_is_file .git/rebase-merge/patch &&
284 echo 22>F2 &&
285 git add F2 &&
286 git rebase --continue &&
287 test_path_is_missing .git/rebase-merge/patch
290 test_expect_success '--reschedule-failed-exec' '
291 test_when_finished "git rebase --abort" &&
292 test_must_fail git rebase -x false --reschedule-failed-exec HEAD^ &&
293 grep "^exec false" .git/rebase-merge/git-rebase-todo &&
294 git rebase --abort &&
295 test_must_fail git -c rebase.rescheduleFailedExec=true \
296 rebase -x false HEAD^ 2>err &&
297 grep "^exec false" .git/rebase-merge/git-rebase-todo &&
298 test_grep "has been rescheduled" err
301 test_expect_success 'rebase.rescheduleFailedExec only affects `rebase -i`' '
302 test_config rebase.rescheduleFailedExec true &&
303 test_must_fail git rebase -x false HEAD^ &&
304 grep "^exec false" .git/rebase-merge/git-rebase-todo &&
305 git rebase --abort &&
306 git rebase HEAD^
309 test_expect_success 'rebase.rescheduleFailedExec=true & --no-reschedule-failed-exec' '
310 test_when_finished "git rebase --abort" &&
311 test_config rebase.rescheduleFailedExec true &&
312 test_must_fail git rebase -x false --no-reschedule-failed-exec HEAD~2 &&
313 test_must_fail git rebase --continue 2>err &&
314 ! grep "has been rescheduled" err
317 test_expect_success 'new rebase.rescheduleFailedExec=true setting in an ongoing rebase is ignored' '
318 test_when_finished "git rebase --abort" &&
319 test_must_fail git rebase -x false HEAD~2 &&
320 test_config rebase.rescheduleFailedExec true &&
321 test_must_fail git rebase --continue 2>err &&
322 ! grep "has been rescheduled" err
325 test_expect_success 'there is no --no-reschedule-failed-exec in an ongoing rebase' '
326 test_when_finished "git rebase --abort" &&
327 test_must_fail git rebase -x false HEAD~2 &&
328 test_expect_code 129 git rebase --continue --no-reschedule-failed-exec &&
329 test_expect_code 129 git rebase --edit-todo --no-reschedule-failed-exec
332 test_orig_head_helper () {
333 test_when_finished 'git rebase --abort &&
334 git checkout topic &&
335 git reset --hard commit-new-file-F2-on-topic-branch' &&
336 git update-ref -d ORIG_HEAD &&
337 test_must_fail git rebase "$@" &&
338 test_cmp_rev ORIG_HEAD commit-new-file-F2-on-topic-branch
341 test_orig_head () {
342 type=$1
343 test_expect_success "rebase $type sets ORIG_HEAD correctly" '
344 git checkout topic &&
345 git reset --hard commit-new-file-F2-on-topic-branch &&
346 test_orig_head_helper $type main
349 test_expect_success "rebase $type <upstream> <branch> sets ORIG_HEAD correctly" '
350 git checkout main &&
351 test_orig_head_helper $type main topic
355 test_orig_head --apply
356 test_orig_head --merge
358 test_done