]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3418-rebase-continue.sh
Sync with 2.31.5
[thirdparty/git.git] / t / t3418-rebase-continue.sh
CommitLineData
25e93250
DK
1#!/bin/sh
2
3test_description='git rebase --continue tests'
4
d1c02d93 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
25e93250
DK
8. ./test-lib.sh
9
10. "$TEST_DIRECTORY"/lib-rebase.sh
11
12set_fake_editor
13
14test_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
24test_expect_success 'interactive rebase --continue works with touched file' '
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
34test_expect_success 'non-interactive rebase --continue works with touched file' '
35 rm -fr .git/rebase-* &&
36 git reset --hard &&
d1c02d93 37 git checkout main &&
25e93250 38
d1c02d93 39 test_must_fail git rebase --onto main main topic &&
25e93250
DK
40 echo "Resolved" >F2 &&
41 git add F2 &&
0e496492 42 test-tool chmtime =-60 F1 &&
25e93250
DK
43 git rebase --continue
44'
45
95135b06
MZ
46test_expect_success 'rebase --continue can not be used with other options' '
47 test_must_fail git rebase -v --continue &&
48 test_must_fail git rebase --continue -v
49'
50
80ff4795
MZ
51test_expect_success 'rebase --continue remembers merge strategy and options' '
52 rm -fr .git/rebase-* &&
53 git reset --hard commit-new-file-F2-on-topic-branch &&
54 test_commit "commit-new-file-F3-on-topic-branch" F3 32 &&
55 test_when_finished "rm -fr test-bin funny.was.run" &&
56 mkdir test-bin &&
02380389 57 cat >test-bin/git-merge-funny <<-EOF &&
80ff4795
MZ
58 #!$SHELL_PATH
59 case "\$1" in --opt) ;; *) exit 2 ;; esac
60 shift &&
61 >funny.was.run &&
62 exec git merge-recursive "\$@"
63 EOF
64 chmod +x test-bin/git-merge-funny &&
65 (
3ea67379 66 PATH=./test-bin:$PATH &&
d1c02d93 67 test_must_fail git rebase -s funny -Xopt main topic
80ff4795
MZ
68 ) &&
69 test -f funny.was.run &&
70 rm funny.was.run &&
71 echo "Resolved" >F2 &&
72 git add F2 &&
73 (
3ea67379 74 PATH=./test-bin:$PATH &&
80ff4795
MZ
75 git rebase --continue
76 ) &&
77 test -f funny.was.run
78'
dd6fb005 79
0060041d 80test_expect_success 'rebase -i --continue handles merge strategy and options' '
a5a959d9
EN
81 rm -fr .git/rebase-* &&
82 git reset --hard commit-new-file-F2-on-topic-branch &&
83 test_commit "commit-new-file-F3-on-topic-branch-for-dash-i" F3 32 &&
84 test_when_finished "rm -fr test-bin funny.was.run funny.args" &&
85 mkdir test-bin &&
86 cat >test-bin/git-merge-funny <<-EOF &&
87 #!$SHELL_PATH
88 echo "\$@" >>funny.args
89 case "\$1" in --opt) ;; *) exit 2 ;; esac
90 case "\$2" in --foo) ;; *) exit 2 ;; esac
91 case "\$4" in --) ;; *) exit 2 ;; esac
92 shift 2 &&
93 >funny.was.run &&
94 exec git merge-recursive "\$@"
95 EOF
96 chmod +x test-bin/git-merge-funny &&
97 (
98 PATH=./test-bin:$PATH &&
d1c02d93 99 test_must_fail git rebase -i -s funny -Xopt -Xfoo main topic
a5a959d9
EN
100 ) &&
101 test -f funny.was.run &&
102 rm funny.was.run &&
103 echo "Resolved" >F2 &&
104 git add F2 &&
105 (
106 PATH=./test-bin:$PATH &&
107 git rebase --continue
108 ) &&
109 test -f funny.was.run
110'
111
11aad464 112test_expect_success REBASE_P 'rebase passes merge strategy options correctly' '
dd6fb005
JS
113 rm -fr .git/rebase-* &&
114 git reset --hard commit-new-file-F3-on-topic-branch &&
115 test_commit theirs-to-merge &&
116 git reset --hard HEAD^ &&
117 test_commit some-commit &&
118 test_tick &&
119 git merge --no-ff theirs-to-merge &&
120 FAKE_LINES="1 edit 2 3" git rebase -i -f -p -m \
121 -s recursive --strategy-option=theirs HEAD~2 &&
122 test_commit force-change &&
123 git rebase --continue
124'
d5bc6f29 125
a63f990d
JS
126test_expect_success 'rebase -r passes merge strategy options correctly' '
127 rm -fr .git/rebase-* &&
128 git reset --hard commit-new-file-F3-on-topic-branch &&
129 test_commit merge-theirs &&
130 git reset --hard HEAD^ &&
131 test_commit some-other-commit &&
132 test_tick &&
133 git merge --no-ff merge-theirs &&
134 FAKE_LINES="1 3 edit 4 5 7 8 9" git rebase -i -f -r -m \
135 -s recursive --strategy-option=theirs HEAD~2 &&
136 test_commit force-change-ours &&
137 git rebase --continue
dd6fb005 138'
d5bc6f29 139
15ef6931 140test_expect_success '--skip after failed fixup cleans commit message' '
d5bc6f29
JS
141 test_when_finished "test_might_fail git rebase --abort" &&
142 git checkout -b with-conflicting-fixup &&
143 test_commit wants-fixup &&
144 test_commit "fixup! wants-fixup" wants-fixup.t 1 wants-fixup-1 &&
145 test_commit "fixup! wants-fixup" wants-fixup.t 2 wants-fixup-2 &&
146 test_commit "fixup! wants-fixup" wants-fixup.t 3 wants-fixup-3 &&
15ef6931 147 test_must_fail env FAKE_LINES="1 fixup 2 squash 4" \
d5bc6f29
JS
148 git rebase -i HEAD~4 &&
149
150 : now there is a conflict, and comments in the commit message &&
151 git show HEAD >out &&
152 grep "fixup! wants-fixup" out &&
153
154 : skip and continue &&
15ef6931
JS
155 echo "cp \"\$1\" .git/copy.txt" | write_script copy-editor.sh &&
156 (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) &&
157
158 : the user should not have had to edit the commit message &&
159 test_path_is_missing .git/copy.txt &&
d5bc6f29
JS
160
161 : now the comments in the commit message should have been cleaned up &&
162 git show HEAD >out &&
15ef6931
JS
163 ! grep "fixup! wants-fixup" out &&
164
165 : now, let us ensure that "squash" is handled correctly &&
166 git reset --hard wants-fixup-3 &&
167 test_must_fail env FAKE_LINES="1 squash 4 squash 2 squash 4" \
168 git rebase -i HEAD~4 &&
169
170 : the first squash failed, but there are two more in the chain &&
171 (test_set_editor "$PWD/copy-editor.sh" &&
172 test_must_fail git rebase --skip) &&
173
174 : not the final squash, no need to edit the commit message &&
175 test_path_is_missing .git/copy.txt &&
176
177 : The first squash was skipped, therefore: &&
178 git show HEAD >out &&
179 test_i18ngrep "# This is a combination of 2 commits" out &&
dd2e36eb 180 test_i18ngrep "# This is the commit message #2:" out &&
15ef6931
JS
181
182 (test_set_editor "$PWD/copy-editor.sh" && git rebase --skip) &&
183 git show HEAD >out &&
184 test_i18ngrep ! "# This is a combination" out &&
185
186 : Final squash failed, but there was still a squash &&
dd2e36eb
PW
187 test_i18ngrep "# This is a combination of 2 commits" .git/copy.txt &&
188 test_i18ngrep "# This is the commit message #2:" .git/copy.txt
d5bc6f29 189'
80ff4795 190
5fb415b5 191test_expect_success 'setup rerere database' '
b3e4847e
MZ
192 rm -fr .git/rebase-* &&
193 git reset --hard commit-new-file-F3-on-topic-branch &&
d1c02d93 194 git checkout main &&
b3e4847e 195 test_commit "commit-new-file-F3" F3 3 &&
5fb415b5 196 test_config rerere.enabled true &&
5ee4ef8b 197 git update-ref refs/heads/topic commit-new-file-F3-on-topic-branch &&
d1c02d93 198 test_must_fail git rebase -m main topic &&
b3e4847e 199 echo "Resolved" >F2 &&
5fb415b5 200 cp F2 expected-F2 &&
b3e4847e
MZ
201 git add F2 &&
202 test_must_fail git rebase --continue &&
203 echo "Resolved" >F3 &&
5fb415b5 204 cp F3 expected-F3 &&
b3e4847e
MZ
205 git add F3 &&
206 git rebase --continue &&
5fb415b5 207 git reset --hard topic@{1}
b3e4847e
MZ
208'
209
5fb415b5
PW
210prepare () {
211 rm -fr .git/rebase-* &&
212 git reset --hard commit-new-file-F3-on-topic-branch &&
d1c02d93 213 git checkout main &&
5fb415b5
PW
214 test_config rerere.enabled true
215}
216
217test_rerere_autoupdate () {
218 action=$1 &&
219 test_expect_success "rebase $action --continue remembers --rerere-autoupdate" '
220 prepare &&
d1c02d93 221 test_must_fail git rebase $action --rerere-autoupdate main topic &&
5fb415b5
PW
222 test_cmp expected-F2 F2 &&
223 git diff-files --quiet &&
224 test_must_fail git rebase --continue &&
225 test_cmp expected-F3 F3 &&
226 git diff-files --quiet &&
227 git rebase --continue
228 '
229
230 test_expect_success "rebase $action --continue honors rerere.autoUpdate" '
231 prepare &&
232 test_config rerere.autoupdate true &&
d1c02d93 233 test_must_fail git rebase $action main topic &&
5fb415b5
PW
234 test_cmp expected-F2 F2 &&
235 git diff-files --quiet &&
236 test_must_fail git rebase --continue &&
237 test_cmp expected-F3 F3 &&
238 git diff-files --quiet &&
239 git rebase --continue
240 '
241
242 test_expect_success "rebase $action --continue remembers --no-rerere-autoupdate" '
243 prepare &&
244 test_config rerere.autoupdate true &&
d1c02d93 245 test_must_fail git rebase $action --no-rerere-autoupdate main topic &&
5fb415b5
PW
246 test_cmp expected-F2 F2 &&
247 test_must_fail git diff-files --quiet &&
248 git add F2 &&
249 test_must_fail git rebase --continue &&
250 test_cmp expected-F3 F3 &&
251 test_must_fail git diff-files --quiet &&
252 git add F3 &&
253 git rebase --continue
254 '
255}
256
257test_rerere_autoupdate
258test_rerere_autoupdate -m
9b6d7a62
PW
259GIT_SEQUENCE_EDITOR=: && export GIT_SEQUENCE_EDITOR
260test_rerere_autoupdate -i
11aad464 261test_have_prereq !REBASE_P || test_rerere_autoupdate --preserve-merges
71f82465
JS
262unset GIT_SEQUENCE_EDITOR
263
264test_expect_success 'the todo command "break" works' '
265 rm -f execed &&
3a4a4cab
JS
266 FAKE_LINES="break b exec_>execed" git rebase -i HEAD &&
267 test_path_is_missing execed &&
268 git rebase --continue &&
71f82465
JS
269 test_path_is_missing execed &&
270 git rebase --continue &&
271 test_path_is_file execed
272'
5fb415b5 273
d421afa0
JS
274test_expect_success '--reschedule-failed-exec' '
275 test_when_finished "git rebase --abort" &&
276 test_must_fail git rebase -x false --reschedule-failed-exec HEAD^ &&
969de3ff
JS
277 grep "^exec false" .git/rebase-merge/git-rebase-todo &&
278 git rebase --abort &&
279 test_must_fail git -c rebase.rescheduleFailedExec=true \
280 rebase -x false HEAD^ 2>err &&
281 grep "^exec false" .git/rebase-merge/git-rebase-todo &&
282 test_i18ngrep "has been rescheduled" err
d421afa0
JS
283'
284
cd663df7
ÆAB
285test_expect_success 'rebase.rescheduleFailedExec only affects `rebase -i`' '
286 test_config rebase.rescheduleFailedExec true &&
906b6394
JS
287 test_must_fail git rebase -x false HEAD^ &&
288 grep "^exec false" .git/rebase-merge/git-rebase-todo &&
289 git rebase --abort &&
290 git rebase HEAD^
291'
292
e5b32bff
ÆAB
293test_expect_success 'rebase.rescheduleFailedExec=true & --no-reschedule-failed-exec' '
294 test_when_finished "git rebase --abort" &&
295 test_config rebase.rescheduleFailedExec true &&
296 test_must_fail git rebase -x false --no-reschedule-failed-exec HEAD~2 &&
297 test_must_fail git rebase --continue 2>err &&
298 ! grep "has been rescheduled" err
299'
300
301test_expect_success 'new rebase.rescheduleFailedExec=true setting in an ongoing rebase is ignored' '
302 test_when_finished "git rebase --abort" &&
303 test_must_fail git rebase -x false HEAD~2 &&
304 test_config rebase.rescheduleFailedExec true &&
305 test_must_fail git rebase --continue 2>err &&
306 ! grep "has been rescheduled" err
307'
308
309test_expect_success 'there is no --no-reschedule-failed-exec in an ongoing rebase' '
310 test_when_finished "git rebase --abort" &&
311 test_must_fail git rebase -x false HEAD~2 &&
312 test_expect_code 129 git rebase --continue --no-reschedule-failed-exec &&
313 test_expect_code 129 git rebase --edit-todo --no-reschedule-failed-exec
314'
315
25e93250 316test_done