3 test_description
='git rebase --continue tests'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 .
"$TEST_DIRECTORY"/lib-rebase.sh
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 &&
24 test_expect_success
'merge based rebase --continue with works with touched file' '
25 rm -fr .git/rebase-* &&
29 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
30 test-tool chmtime =-60 F1 &&
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-* &&
49 test_must_fail git rebase --apply --onto main main topic &&
50 echo "Resolved" >F2 &&
52 test-tool chmtime =-60 F1 &&
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" &&
68 write_script test-bin/git-merge-funny <<-\EOF &&
69 printf "[%s]\n" $# "$1" "$2" "$3" "$5" >actual
71 exec git merge-recursive "$@"
74 cat >expect <<-\EOF &&
76 [--option=arg with space]
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
89 test_cmp expect actual &&
91 echo "Resolved" >F2 &&
94 PATH=./test-bin:$PATH &&
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 &&
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 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 &&
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:
131 # The commit message #2 will be skipped:
136 : skip and continue &&
137 echo "cp \"\$1\" .git/copy.txt" | write_script copy-editor.sh &&
138 (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) &&
140 : the user should not have had to edit the commit message &&
141 test_path_is_missing .git/copy.txt &&
143 : now the comments in the commit message should have been cleaned up &&
144 test_commit_message HEAD -m wants-fixup &&
146 : now, let us ensure that "squash" is handled correctly &&
147 git reset --hard wants-fixup-3 &&
148 test_must_fail env FAKE_LINES="1 squash 2 squash 1 squash 3 squash 1" \
149 git rebase -i HEAD~4 &&
151 : the second squash failed, but there are two more in the chain &&
152 (test_set_editor "$PWD/copy-editor.sh" &&
153 test_must_fail git rebase --skip) &&
155 : not the final squash, no need to edit the commit message &&
156 test_path_is_missing .git/copy.txt &&
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:
165 # This is the commit message #2:
169 # This is the commit message #3:
174 (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) &&
175 test_commit_message HEAD <<-\EOF &&
183 : Final squash failed, but there was still a squash &&
184 head -n1 .git/copy.txt >first-line &&
185 test_i18ngrep "# This is a combination of 3 commits" first-line &&
186 test_i18ngrep "# This is the commit message #3:" .git/copy.txt
189 test_expect_success
'setup rerere database' '
190 rm -fr .git/rebase-* &&
191 git reset --hard commit-new-file-F3-on-topic-branch &&
193 test_commit "commit-new-file-F3" F3 3 &&
194 test_config rerere.enabled true &&
195 git update-ref refs/heads/topic commit-new-file-F3-on-topic-branch &&
196 test_must_fail git rebase -m main topic &&
197 echo "Resolved" >F2 &&
200 test_must_fail git rebase --continue &&
201 echo "Resolved" >F3 &&
204 git rebase --continue &&
205 git reset --hard topic@{1}
209 rm -fr .git
/rebase-
* &&
210 git
reset --hard commit-new-file-F3-on-topic-branch
&&
212 test_config rerere.enabled true
215 test_rerere_autoupdate
() {
217 test_expect_success
"rebase $action --continue remembers --rerere-autoupdate" '
219 test_must_fail git rebase $action --rerere-autoupdate main topic &&
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
228 test_expect_success
"rebase $action --continue honors rerere.autoUpdate" '
230 test_config rerere.autoupdate true &&
231 test_must_fail git rebase $action main topic &&
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
240 test_expect_success
"rebase $action --continue remembers --no-rerere-autoupdate" '
242 test_config rerere.autoupdate true &&
243 test_must_fail git rebase $action --no-rerere-autoupdate main topic &&
244 test_cmp expected-F2 F2 &&
245 test_must_fail git diff-files --quiet &&
247 test_must_fail git rebase --continue &&
248 test_cmp expected-F3 F3 &&
249 test_must_fail git diff-files --quiet &&
251 git rebase --continue
255 test_rerere_autoupdate
--apply
256 test_rerere_autoupdate
-m
257 GIT_SEQUENCE_EDITOR
=: && export GIT_SEQUENCE_EDITOR
258 test_rerere_autoupdate
-i
259 unset GIT_SEQUENCE_EDITOR
261 test_expect_success
'the todo command "break" works' '
263 FAKE_LINES="break b exec_>execed" git rebase -i HEAD &&
264 test_path_is_missing execed &&
265 git rebase --continue &&
266 test_path_is_missing execed &&
267 git rebase --continue &&
268 test_path_is_file execed
271 test_expect_success
'--reschedule-failed-exec' '
272 test_when_finished "git rebase --abort" &&
273 test_must_fail git rebase -x false --reschedule-failed-exec HEAD^ &&
274 grep "^exec false" .git/rebase-merge/git-rebase-todo &&
275 git rebase --abort &&
276 test_must_fail git -c rebase.rescheduleFailedExec=true \
277 rebase -x false HEAD^ 2>err &&
278 grep "^exec false" .git/rebase-merge/git-rebase-todo &&
279 test_i18ngrep "has been rescheduled" err
282 test_expect_success
'rebase.rescheduleFailedExec only affects `rebase -i`' '
283 test_config rebase.rescheduleFailedExec true &&
284 test_must_fail git rebase -x false HEAD^ &&
285 grep "^exec false" .git/rebase-merge/git-rebase-todo &&
286 git rebase --abort &&
290 test_expect_success
'rebase.rescheduleFailedExec=true & --no-reschedule-failed-exec' '
291 test_when_finished "git rebase --abort" &&
292 test_config rebase.rescheduleFailedExec true &&
293 test_must_fail git rebase -x false --no-reschedule-failed-exec HEAD~2 &&
294 test_must_fail git rebase --continue 2>err &&
295 ! grep "has been rescheduled" err
298 test_expect_success
'new rebase.rescheduleFailedExec=true setting in an ongoing rebase is ignored' '
299 test_when_finished "git rebase --abort" &&
300 test_must_fail git rebase -x false HEAD~2 &&
301 test_config rebase.rescheduleFailedExec true &&
302 test_must_fail git rebase --continue 2>err &&
303 ! grep "has been rescheduled" err
306 test_expect_success
'there is no --no-reschedule-failed-exec in an ongoing rebase' '
307 test_when_finished "git rebase --abort" &&
308 test_must_fail git rebase -x false HEAD~2 &&
309 test_expect_code 129 git rebase --continue --no-reschedule-failed-exec &&
310 test_expect_code 129 git rebase --edit-todo --no-reschedule-failed-exec
313 test_orig_head_helper
() {
314 test_when_finished
'git rebase --abort &&
315 git checkout topic &&
316 git reset --hard commit-new-file-F2-on-topic-branch' &&
317 git update-ref
-d ORIG_HEAD
&&
318 test_must_fail git rebase
"$@" &&
319 test_cmp_rev ORIG_HEAD commit-new-file-F2-on-topic-branch
324 test_expect_success
"rebase $type sets ORIG_HEAD correctly" '
325 git checkout topic &&
326 git reset --hard commit-new-file-F2-on-topic-branch &&
327 test_orig_head_helper $type main
330 test_expect_success
"rebase $type <upstream> <branch> sets ORIG_HEAD correctly" '
332 test_orig_head_helper $type main topic
336 test_orig_head
--apply
337 test_orig_head
--merge