]>
Commit | Line | Data |
---|---|---|
25e93250 DK |
1 | #!/bin/sh |
2 | ||
3 | test_description='git rebase --continue tests' | |
4 | ||
d1c02d93 | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
7 | ||
25e93250 DK |
8 | . ./test-lib.sh |
9 | ||
10 | . "$TEST_DIRECTORY"/lib-rebase.sh | |
11 | ||
12 | set_fake_editor | |
13 | ||
14 | test_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 | 24 | test_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 |
34 | test_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 | 44 | test_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 |
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 | |
59 | ' | |
60 | ||
80ff4795 MZ |
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 && | |
02380389 | 67 | cat >test-bin/git-merge-funny <<-EOF && |
80ff4795 MZ |
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 && | |
75 | ( | |
3ea67379 | 76 | PATH=./test-bin:$PATH && |
d1c02d93 | 77 | test_must_fail git rebase -s funny -Xopt main topic |
80ff4795 MZ |
78 | ) && |
79 | test -f funny.was.run && | |
80 | rm funny.was.run && | |
81 | echo "Resolved" >F2 && | |
82 | git add F2 && | |
83 | ( | |
3ea67379 | 84 | PATH=./test-bin:$PATH && |
80ff4795 MZ |
85 | git rebase --continue |
86 | ) && | |
87 | test -f funny.was.run | |
88 | ' | |
dd6fb005 | 89 | |
0060041d | 90 | test_expect_success 'rebase -i --continue handles merge strategy and options' ' |
a5a959d9 EN |
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 "\$@" | |
105 | EOF | |
106 | chmod +x test-bin/git-merge-funny && | |
107 | ( | |
108 | PATH=./test-bin:$PATH && | |
d1c02d93 | 109 | test_must_fail git rebase -i -s funny -Xopt -Xfoo main topic |
a5a959d9 EN |
110 | ) && |
111 | test -f funny.was.run && | |
112 | rm funny.was.run && | |
113 | echo "Resolved" >F2 && | |
114 | git add F2 && | |
115 | ( | |
116 | PATH=./test-bin:$PATH && | |
117 | git rebase --continue | |
118 | ) && | |
119 | test -f funny.was.run | |
120 | ' | |
121 | ||
a63f990d JS |
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 | |
dd6fb005 | 134 | ' |
d5bc6f29 | 135 | |
15ef6931 | 136 | test_expect_success '--skip after failed fixup cleans commit message' ' |
d5bc6f29 JS |
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 && | |
15ef6931 | 143 | test_must_fail env FAKE_LINES="1 fixup 2 squash 4" \ |
d5bc6f29 JS |
144 | git rebase -i HEAD~4 && |
145 | ||
146 | : now there is a conflict, and comments in the commit message && | |
147 | git show HEAD >out && | |
148 | grep "fixup! wants-fixup" out && | |
149 | ||
150 | : skip and continue && | |
15ef6931 JS |
151 | echo "cp \"\$1\" .git/copy.txt" | write_script copy-editor.sh && |
152 | (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) && | |
153 | ||
154 | : the user should not have had to edit the commit message && | |
155 | test_path_is_missing .git/copy.txt && | |
d5bc6f29 JS |
156 | |
157 | : now the comments in the commit message should have been cleaned up && | |
158 | git show HEAD >out && | |
15ef6931 JS |
159 | ! grep "fixup! wants-fixup" out && |
160 | ||
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 && | |
165 | ||
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) && | |
169 | ||
170 | : not the final squash, no need to edit the commit message && | |
171 | test_path_is_missing .git/copy.txt && | |
172 | ||
173 | : The first squash was skipped, therefore: && | |
174 | git show HEAD >out && | |
175 | test_i18ngrep "# This is a combination of 2 commits" out && | |
dd2e36eb | 176 | test_i18ngrep "# This is the commit message #2:" out && |
15ef6931 JS |
177 | |
178 | (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) && | |
179 | git show HEAD >out && | |
180 | test_i18ngrep ! "# This is a combination" out && | |
181 | ||
182 | : Final squash failed, but there was still a squash && | |
dd2e36eb PW |
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 | |
d5bc6f29 | 185 | ' |
80ff4795 | 186 | |
5fb415b5 | 187 | test_expect_success 'setup rerere database' ' |
b3e4847e MZ |
188 | rm -fr .git/rebase-* && |
189 | git reset --hard commit-new-file-F3-on-topic-branch && | |
d1c02d93 | 190 | git checkout main && |
b3e4847e | 191 | test_commit "commit-new-file-F3" F3 3 && |
5fb415b5 | 192 | test_config rerere.enabled true && |
5ee4ef8b | 193 | git update-ref refs/heads/topic commit-new-file-F3-on-topic-branch && |
d1c02d93 | 194 | test_must_fail git rebase -m main topic && |
b3e4847e | 195 | echo "Resolved" >F2 && |
5fb415b5 | 196 | cp F2 expected-F2 && |
b3e4847e MZ |
197 | git add F2 && |
198 | test_must_fail git rebase --continue && | |
199 | echo "Resolved" >F3 && | |
5fb415b5 | 200 | cp F3 expected-F3 && |
b3e4847e MZ |
201 | git add F3 && |
202 | git rebase --continue && | |
5fb415b5 | 203 | git reset --hard topic@{1} |
b3e4847e MZ |
204 | ' |
205 | ||
5fb415b5 PW |
206 | prepare () { |
207 | rm -fr .git/rebase-* && | |
208 | git reset --hard commit-new-file-F3-on-topic-branch && | |
d1c02d93 | 209 | git checkout main && |
5fb415b5 PW |
210 | test_config rerere.enabled true |
211 | } | |
212 | ||
213 | test_rerere_autoupdate () { | |
214 | action=$1 && | |
215 | test_expect_success "rebase $action --continue remembers --rerere-autoupdate" ' | |
216 | prepare && | |
d1c02d93 | 217 | test_must_fail git rebase $action --rerere-autoupdate main topic && |
5fb415b5 PW |
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 | |
224 | ' | |
225 | ||
226 | test_expect_success "rebase $action --continue honors rerere.autoUpdate" ' | |
227 | prepare && | |
228 | test_config rerere.autoupdate true && | |
d1c02d93 | 229 | test_must_fail git rebase $action main topic && |
5fb415b5 PW |
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 | |
236 | ' | |
237 | ||
238 | test_expect_success "rebase $action --continue remembers --no-rerere-autoupdate" ' | |
239 | prepare && | |
240 | test_config rerere.autoupdate true && | |
d1c02d93 | 241 | test_must_fail git rebase $action --no-rerere-autoupdate main topic && |
5fb415b5 PW |
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 | |
250 | ' | |
251 | } | |
252 | ||
bed9b4e3 | 253 | test_rerere_autoupdate --apply |
5fb415b5 | 254 | test_rerere_autoupdate -m |
9b6d7a62 PW |
255 | GIT_SEQUENCE_EDITOR=: && export GIT_SEQUENCE_EDITOR |
256 | test_rerere_autoupdate -i | |
71f82465 JS |
257 | unset GIT_SEQUENCE_EDITOR |
258 | ||
259 | test_expect_success 'the todo command "break" works' ' | |
260 | rm -f execed && | |
3a4a4cab JS |
261 | FAKE_LINES="break b exec_>execed" git rebase -i HEAD && |
262 | test_path_is_missing execed && | |
263 | git rebase --continue && | |
71f82465 JS |
264 | test_path_is_missing execed && |
265 | git rebase --continue && | |
266 | test_path_is_file execed | |
267 | ' | |
5fb415b5 | 268 | |
d421afa0 JS |
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^ && | |
969de3ff JS |
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 | |
d421afa0 JS |
278 | ' |
279 | ||
cd663df7 ÆAB |
280 | test_expect_success 'rebase.rescheduleFailedExec only affects `rebase -i`' ' |
281 | test_config rebase.rescheduleFailedExec true && | |
906b6394 JS |
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^ | |
286 | ' | |
287 | ||
e5b32bff ÆAB |
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 | |
294 | ' | |
295 | ||
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 | |
302 | ' | |
303 | ||
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 | |
309 | ' | |
310 | ||
cd1528ef PW |
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 | |
318 | } | |
319 | ||
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 | |
326 | ' | |
327 | ||
328 | test_expect_success "rebase $type <upstream> <branch> sets ORIG_HEAD correctly" ' | |
329 | git checkout main && | |
330 | test_orig_head_helper $type main topic | |
331 | ' | |
332 | } | |
333 | ||
334 | test_orig_head --apply | |
335 | test_orig_head --merge | |
336 | ||
25e93250 | 337 | test_done |