Sync with 2.38.5
[git.git] / t / t3418-rebase-continue.sh
blob130e2f9b553003b9972ebe1010f17abff2d5ee05
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-lib.sh
10 . "$TEST_DIRECTORY"/lib-rebase.sh
12 set_fake_editor
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 &&
21 git checkout main
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 &&
29 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
30 test-tool chmtime =-60 F1 &&
31 git rebase --continue
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-* &&
46 git reset --hard &&
47 git checkout main &&
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
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" &&
66 mkdir test-bin &&
67 cat >test-bin/git-merge-funny <<-EOF &&
68 #!$SHELL_PATH
69 case "\$1" in --opt) ;; *) exit 2 ;; esac
70 shift &&
71 >funny.was.run &&
72 exec git merge-recursive "\$@"
73 EOF
74 chmod +x test-bin/git-merge-funny &&
76 PATH=./test-bin:$PATH &&
77 test_must_fail git rebase -s funny -Xopt main topic
78 ) &&
79 test -f funny.was.run &&
80 rm funny.was.run &&
81 echo "Resolved" >F2 &&
82 git add F2 &&
84 PATH=./test-bin:$PATH &&
85 git rebase --continue
86 ) &&
87 test -f funny.was.run
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" &&
95 mkdir test-bin &&
96 cat >test-bin/git-merge-funny <<-EOF &&
97 #!$SHELL_PATH
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
102 shift 2 &&
103 >funny.was.run &&
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
110 ) &&
111 test -f funny.was.run &&
112 rm funny.was.run &&
113 echo "Resolved" >F2 &&
114 git add F2 &&
116 PATH=./test-bin:$PATH &&
117 git rebase --continue
118 ) &&
119 test -f funny.was.run
122 test_expect_success 'rebase -r passes merge strategy options correctly' '
123 rm -fr .git/rebase-* &&
124 git reset --hard commit-new-file-F3-on-topic-branch &&
125 test_commit merge-theirs &&
126 git reset --hard HEAD^ &&
127 test_commit some-other-commit &&
128 test_tick &&
129 git merge --no-ff merge-theirs &&
130 FAKE_LINES="1 3 edit 4 5 7 8 9" git rebase -i -f -r -m \
131 -s recursive --strategy-option=theirs HEAD~2 &&
132 test_commit force-change-ours &&
133 git rebase --continue
136 test_expect_success '--skip after failed fixup cleans commit message' '
137 test_when_finished "test_might_fail git rebase --abort" &&
138 git checkout -b with-conflicting-fixup &&
139 test_commit wants-fixup &&
140 test_commit "fixup! wants-fixup" wants-fixup.t 1 wants-fixup-1 &&
141 test_commit "fixup! wants-fixup" wants-fixup.t 2 wants-fixup-2 &&
142 test_commit "fixup! wants-fixup" wants-fixup.t 3 wants-fixup-3 &&
143 test_must_fail env FAKE_LINES="1 fixup 2 squash 4" \
144 git rebase -i HEAD~4 &&
146 : now there is a conflict, and comments in the commit message &&
147 git show HEAD >out &&
148 grep "fixup! wants-fixup" out &&
150 : skip and continue &&
151 echo "cp \"\$1\" .git/copy.txt" | write_script copy-editor.sh &&
152 (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) &&
154 : the user should not have had to edit the commit message &&
155 test_path_is_missing .git/copy.txt &&
157 : now the comments in the commit message should have been cleaned up &&
158 git show HEAD >out &&
159 ! grep "fixup! wants-fixup" out &&
161 : now, let us ensure that "squash" is handled correctly &&
162 git reset --hard wants-fixup-3 &&
163 test_must_fail env FAKE_LINES="1 squash 4 squash 2 squash 4" \
164 git rebase -i HEAD~4 &&
166 : the first squash failed, but there are two more in the chain &&
167 (test_set_editor "$PWD/copy-editor.sh" &&
168 test_must_fail git rebase --skip) &&
170 : not the final squash, no need to edit the commit message &&
171 test_path_is_missing .git/copy.txt &&
173 : The first squash was skipped, therefore: &&
174 git show HEAD >out &&
175 test_i18ngrep "# This is a combination of 2 commits" out &&
176 test_i18ngrep "# This is the commit message #2:" out &&
178 (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) &&
179 git show HEAD >out &&
180 test_i18ngrep ! "# This is a combination" out &&
182 : Final squash failed, but there was still a squash &&
183 test_i18ngrep "# This is a combination of 2 commits" .git/copy.txt &&
184 test_i18ngrep "# This is the commit message #2:" .git/copy.txt
187 test_expect_success 'setup rerere database' '
188 rm -fr .git/rebase-* &&
189 git reset --hard commit-new-file-F3-on-topic-branch &&
190 git checkout main &&
191 test_commit "commit-new-file-F3" F3 3 &&
192 test_config rerere.enabled true &&
193 git update-ref refs/heads/topic commit-new-file-F3-on-topic-branch &&
194 test_must_fail git rebase -m main topic &&
195 echo "Resolved" >F2 &&
196 cp F2 expected-F2 &&
197 git add F2 &&
198 test_must_fail git rebase --continue &&
199 echo "Resolved" >F3 &&
200 cp F3 expected-F3 &&
201 git add F3 &&
202 git rebase --continue &&
203 git reset --hard topic@{1}
206 prepare () {
207 rm -fr .git/rebase-* &&
208 git reset --hard commit-new-file-F3-on-topic-branch &&
209 git checkout main &&
210 test_config rerere.enabled true
213 test_rerere_autoupdate () {
214 action=$1 &&
215 test_expect_success "rebase $action --continue remembers --rerere-autoupdate" '
216 prepare &&
217 test_must_fail git rebase $action --rerere-autoupdate main topic &&
218 test_cmp expected-F2 F2 &&
219 git diff-files --quiet &&
220 test_must_fail git rebase --continue &&
221 test_cmp expected-F3 F3 &&
222 git diff-files --quiet &&
223 git rebase --continue
226 test_expect_success "rebase $action --continue honors rerere.autoUpdate" '
227 prepare &&
228 test_config rerere.autoupdate true &&
229 test_must_fail git rebase $action main topic &&
230 test_cmp expected-F2 F2 &&
231 git diff-files --quiet &&
232 test_must_fail git rebase --continue &&
233 test_cmp expected-F3 F3 &&
234 git diff-files --quiet &&
235 git rebase --continue
238 test_expect_success "rebase $action --continue remembers --no-rerere-autoupdate" '
239 prepare &&
240 test_config rerere.autoupdate true &&
241 test_must_fail git rebase $action --no-rerere-autoupdate main topic &&
242 test_cmp expected-F2 F2 &&
243 test_must_fail git diff-files --quiet &&
244 git add F2 &&
245 test_must_fail git rebase --continue &&
246 test_cmp expected-F3 F3 &&
247 test_must_fail git diff-files --quiet &&
248 git add F3 &&
249 git rebase --continue
253 test_rerere_autoupdate --apply
254 test_rerere_autoupdate -m
255 GIT_SEQUENCE_EDITOR=: && export GIT_SEQUENCE_EDITOR
256 test_rerere_autoupdate -i
257 unset GIT_SEQUENCE_EDITOR
259 test_expect_success 'the todo command "break" works' '
260 rm -f execed &&
261 FAKE_LINES="break b exec_>execed" git rebase -i HEAD &&
262 test_path_is_missing execed &&
263 git rebase --continue &&
264 test_path_is_missing execed &&
265 git rebase --continue &&
266 test_path_is_file execed
269 test_expect_success '--reschedule-failed-exec' '
270 test_when_finished "git rebase --abort" &&
271 test_must_fail git rebase -x false --reschedule-failed-exec HEAD^ &&
272 grep "^exec false" .git/rebase-merge/git-rebase-todo &&
273 git rebase --abort &&
274 test_must_fail git -c rebase.rescheduleFailedExec=true \
275 rebase -x false HEAD^ 2>err &&
276 grep "^exec false" .git/rebase-merge/git-rebase-todo &&
277 test_i18ngrep "has been rescheduled" err
280 test_expect_success 'rebase.rescheduleFailedExec only affects `rebase -i`' '
281 test_config rebase.rescheduleFailedExec true &&
282 test_must_fail git rebase -x false HEAD^ &&
283 grep "^exec false" .git/rebase-merge/git-rebase-todo &&
284 git rebase --abort &&
285 git rebase HEAD^
288 test_expect_success 'rebase.rescheduleFailedExec=true & --no-reschedule-failed-exec' '
289 test_when_finished "git rebase --abort" &&
290 test_config rebase.rescheduleFailedExec true &&
291 test_must_fail git rebase -x false --no-reschedule-failed-exec HEAD~2 &&
292 test_must_fail git rebase --continue 2>err &&
293 ! grep "has been rescheduled" err
296 test_expect_success 'new rebase.rescheduleFailedExec=true setting in an ongoing rebase is ignored' '
297 test_when_finished "git rebase --abort" &&
298 test_must_fail git rebase -x false HEAD~2 &&
299 test_config rebase.rescheduleFailedExec true &&
300 test_must_fail git rebase --continue 2>err &&
301 ! grep "has been rescheduled" err
304 test_expect_success 'there is no --no-reschedule-failed-exec in an ongoing rebase' '
305 test_when_finished "git rebase --abort" &&
306 test_must_fail git rebase -x false HEAD~2 &&
307 test_expect_code 129 git rebase --continue --no-reschedule-failed-exec &&
308 test_expect_code 129 git rebase --edit-todo --no-reschedule-failed-exec
311 test_orig_head_helper () {
312 test_when_finished 'git rebase --abort &&
313 git checkout topic &&
314 git reset --hard commit-new-file-F2-on-topic-branch' &&
315 git update-ref -d ORIG_HEAD &&
316 test_must_fail git rebase "$@" &&
317 test_cmp_rev ORIG_HEAD commit-new-file-F2-on-topic-branch
320 test_orig_head () {
321 type=$1
322 test_expect_success "rebase $type sets ORIG_HEAD correctly" '
323 git checkout topic &&
324 git reset --hard commit-new-file-F2-on-topic-branch &&
325 test_orig_head_helper $type main
328 test_expect_success "rebase $type <upstream> <branch> sets ORIG_HEAD correctly" '
329 git checkout main &&
330 test_orig_head_helper $type main topic
334 test_orig_head --apply
335 test_orig_head --merge
337 test_done