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 funny.was.run" &&
67 cat >test-bin/git-merge-funny <<-EOF &&
69 case "\$1" in --opt) ;; *) exit 2 ;; esac
72 exec git merge-recursive "\$@"
74 chmod +x test-bin/git-merge-funny &&
76 PATH=./test-bin:$PATH &&
77 test_must_fail git rebase -s funny -Xopt main topic
79 test -f funny.was.run &&
81 echo "Resolved" >F2 &&
84 PATH=./test-bin:$PATH &&
90 test_expect_success
'rebase -i --continue handles merge strategy and options' '
91 rm -fr .git/rebase-* &&
92 git reset --hard commit-new-file-F2-on-topic-branch &&
93 test_commit "commit-new-file-F3-on-topic-branch-for-dash-i" F3 32 &&
94 test_when_finished "rm -fr test-bin funny.was.run funny.args" &&
96 cat >test-bin/git-merge-funny <<-EOF &&
98 echo "\$@" >>funny.args
99 case "\$1" in --opt) ;; *) exit 2 ;; esac
100 case "\$2" in --foo) ;; *) exit 2 ;; esac
101 case "\$4" in --) ;; *) exit 2 ;; esac
104 exec git merge-recursive "\$@"
106 chmod +x test-bin/git-merge-funny &&
108 PATH=./test-bin:$PATH &&
109 test_must_fail git rebase -i -s funny -Xopt -Xfoo main topic
111 test -f funny.was.run &&
113 echo "Resolved" >F2 &&
116 PATH=./test-bin:$PATH &&
117 git rebase --continue
119 test -f funny.was.run
122 test_expect_success REBASE_P
'rebase passes merge strategy options correctly' '
123 rm -fr .git/rebase-* &&
124 git reset --hard commit-new-file-F3-on-topic-branch &&
125 test_commit theirs-to-merge &&
126 git reset --hard HEAD^ &&
127 test_commit some-commit &&
129 git merge --no-ff theirs-to-merge &&
130 FAKE_LINES="1 edit 2 3" git rebase -i -f -p -m \
131 -s recursive --strategy-option=theirs HEAD~2 &&
132 test_commit force-change &&
133 git rebase --continue
136 test_expect_success
'rebase -r passes merge strategy options correctly' '
137 rm -fr .git/rebase-* &&
138 git reset --hard commit-new-file-F3-on-topic-branch &&
139 test_commit merge-theirs &&
140 git reset --hard HEAD^ &&
141 test_commit some-other-commit &&
143 git merge --no-ff merge-theirs &&
144 FAKE_LINES="1 3 edit 4 5 7 8 9" git rebase -i -f -r -m \
145 -s recursive --strategy-option=theirs HEAD~2 &&
146 test_commit force-change-ours &&
147 git rebase --continue
150 test_expect_success
'--skip after failed fixup cleans commit message' '
151 test_when_finished "test_might_fail git rebase --abort" &&
152 git checkout -b with-conflicting-fixup &&
153 test_commit wants-fixup &&
154 test_commit "fixup! wants-fixup" wants-fixup.t 1 wants-fixup-1 &&
155 test_commit "fixup! wants-fixup" wants-fixup.t 2 wants-fixup-2 &&
156 test_commit "fixup! wants-fixup" wants-fixup.t 3 wants-fixup-3 &&
157 test_must_fail env FAKE_LINES="1 fixup 2 squash 4" \
158 git rebase -i HEAD~4 &&
160 : now there is a conflict, and comments in the commit message &&
161 git show HEAD >out &&
162 grep "fixup! wants-fixup" out &&
164 : skip and continue &&
165 echo "cp \"\$1\" .git/copy.txt" | write_script copy-editor.sh &&
166 (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) &&
168 : the user should not have had to edit the commit message &&
169 test_path_is_missing .git/copy.txt &&
171 : now the comments in the commit message should have been cleaned up &&
172 git show HEAD >out &&
173 ! grep "fixup! wants-fixup" out &&
175 : now, let us ensure that "squash" is handled correctly &&
176 git reset --hard wants-fixup-3 &&
177 test_must_fail env FAKE_LINES="1 squash 4 squash 2 squash 4" \
178 git rebase -i HEAD~4 &&
180 : the first squash failed, but there are two more in the chain &&
181 (test_set_editor "$PWD/copy-editor.sh" &&
182 test_must_fail git rebase --skip) &&
184 : not the final squash, no need to edit the commit message &&
185 test_path_is_missing .git/copy.txt &&
187 : The first squash was skipped, therefore: &&
188 git show HEAD >out &&
189 test_i18ngrep "# This is a combination of 2 commits" out &&
190 test_i18ngrep "# This is the commit message #2:" out &&
192 (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) &&
193 git show HEAD >out &&
194 test_i18ngrep ! "# This is a combination" out &&
196 : Final squash failed, but there was still a squash &&
197 test_i18ngrep "# This is a combination of 2 commits" .git/copy.txt &&
198 test_i18ngrep "# This is the commit message #2:" .git/copy.txt
201 test_expect_success
'setup rerere database' '
202 rm -fr .git/rebase-* &&
203 git reset --hard commit-new-file-F3-on-topic-branch &&
205 test_commit "commit-new-file-F3" F3 3 &&
206 test_config rerere.enabled true &&
207 git update-ref refs/heads/topic commit-new-file-F3-on-topic-branch &&
208 test_must_fail git rebase -m main topic &&
209 echo "Resolved" >F2 &&
212 test_must_fail git rebase --continue &&
213 echo "Resolved" >F3 &&
216 git rebase --continue &&
217 git reset --hard topic@{1}
221 rm -fr .git
/rebase-
* &&
222 git
reset --hard commit-new-file-F3-on-topic-branch
&&
224 test_config rerere.enabled true
227 test_rerere_autoupdate
() {
229 test_expect_success
"rebase $action --continue remembers --rerere-autoupdate" '
231 test_must_fail git rebase $action --rerere-autoupdate 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 honors rerere.autoUpdate" '
242 test_config rerere.autoupdate true &&
243 test_must_fail git rebase $action main topic &&
244 test_cmp expected-F2 F2 &&
245 git diff-files --quiet &&
246 test_must_fail git rebase --continue &&
247 test_cmp expected-F3 F3 &&
248 git diff-files --quiet &&
249 git rebase --continue
252 test_expect_success
"rebase $action --continue remembers --no-rerere-autoupdate" '
254 test_config rerere.autoupdate true &&
255 test_must_fail git rebase $action --no-rerere-autoupdate main topic &&
256 test_cmp expected-F2 F2 &&
257 test_must_fail git diff-files --quiet &&
259 test_must_fail git rebase --continue &&
260 test_cmp expected-F3 F3 &&
261 test_must_fail git diff-files --quiet &&
263 git rebase --continue
267 test_rerere_autoupdate
--apply
268 test_rerere_autoupdate
-m
269 GIT_SEQUENCE_EDITOR
=: && export GIT_SEQUENCE_EDITOR
270 test_rerere_autoupdate
-i
271 test_have_prereq
!REBASE_P || test_rerere_autoupdate
--preserve-merges
272 unset GIT_SEQUENCE_EDITOR
274 test_expect_success
'the todo command "break" works' '
276 FAKE_LINES="break b exec_>execed" git rebase -i HEAD &&
277 test_path_is_missing execed &&
278 git rebase --continue &&
279 test_path_is_missing execed &&
280 git rebase --continue &&
281 test_path_is_file execed
284 test_expect_success
'--reschedule-failed-exec' '
285 test_when_finished "git rebase --abort" &&
286 test_must_fail git rebase -x false --reschedule-failed-exec HEAD^ &&
287 grep "^exec false" .git/rebase-merge/git-rebase-todo &&
288 git rebase --abort &&
289 test_must_fail git -c rebase.rescheduleFailedExec=true \
290 rebase -x false HEAD^ 2>err &&
291 grep "^exec false" .git/rebase-merge/git-rebase-todo &&
292 test_i18ngrep "has been rescheduled" err
295 test_expect_success
'rebase.rescheduleFailedExec only affects `rebase -i`' '
296 test_config rebase.rescheduleFailedExec true &&
297 test_must_fail git rebase -x false HEAD^ &&
298 grep "^exec false" .git/rebase-merge/git-rebase-todo &&
299 git rebase --abort &&
303 test_expect_success
'rebase.rescheduleFailedExec=true & --no-reschedule-failed-exec' '
304 test_when_finished "git rebase --abort" &&
305 test_config rebase.rescheduleFailedExec true &&
306 test_must_fail git rebase -x false --no-reschedule-failed-exec HEAD~2 &&
307 test_must_fail git rebase --continue 2>err &&
308 ! grep "has been rescheduled" err
311 test_expect_success
'new rebase.rescheduleFailedExec=true setting in an ongoing rebase is ignored' '
312 test_when_finished "git rebase --abort" &&
313 test_must_fail git rebase -x false HEAD~2 &&
314 test_config rebase.rescheduleFailedExec true &&
315 test_must_fail git rebase --continue 2>err &&
316 ! grep "has been rescheduled" err
319 test_expect_success
'there is no --no-reschedule-failed-exec in an ongoing rebase' '
320 test_when_finished "git rebase --abort" &&
321 test_must_fail git rebase -x false HEAD~2 &&
322 test_expect_code 129 git rebase --continue --no-reschedule-failed-exec &&
323 test_expect_code 129 git rebase --edit-todo --no-reschedule-failed-exec