]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3404-rebase-interactive.sh
Sync with Git 2.45.1
[thirdparty/git.git] / t / t3404-rebase-interactive.sh
CommitLineData
1b1dce4b
JS
1#!/bin/sh
2#
3# Copyright (c) 2007 Johannes E. Schindelin
4#
5
6test_description='git rebase interactive
7
8This test runs git rebase "interactively", by faking an edit, and verifies
9that the result still makes sense.
99b028e5
JN
10
11Initial setup:
12
13 one - two - three - four (conflict-branch)
14 /
9c8509a4 15 A - B - C - D - E (primary)
99b028e5
JN
16 | \
17 | F - G - H (branch1)
18 | \
19 |\ I (branch2)
20 | \
21 | J - K - L - M (no-conflict-branch)
22 \
23 N - O - P (no-ff-branch)
24
25 where A, B, D and G all touch file1, and one, two, three, four all
26 touch file "conflict".
1b1dce4b 27'
334afbc7 28
1b1dce4b
JS
29. ./test-lib.sh
30
eaf0551d 31. "$TEST_DIRECTORY"/lib-rebase.sh
29a03348 32
1b1dce4b 33test_expect_success 'setup' '
9c8509a4 34 git switch -C primary &&
163f3925
MH
35 test_commit A file1 &&
36 test_commit B file1 &&
37 test_commit C file2 &&
38 test_commit D file1 &&
39 test_commit E file3 &&
1b1dce4b 40 git checkout -b branch1 A &&
163f3925
MH
41 test_commit F file4 &&
42 test_commit G file1 &&
43 test_commit H file5 &&
1b1dce4b 44 git checkout -b branch2 F &&
2dec68cf 45 test_commit I file6 &&
6c4c44c4 46 git checkout -b conflict-branch A &&
391a825f
JN
47 test_commit one conflict &&
48 test_commit two conflict &&
49 test_commit three conflict &&
50 test_commit four conflict &&
6c4c44c4 51 git checkout -b no-conflict-branch A &&
391a825f
JN
52 test_commit J fileJ &&
53 test_commit K fileK &&
54 test_commit L fileL &&
55 test_commit M fileM &&
b4995494 56 git checkout -b no-ff-branch A &&
391a825f
JN
57 test_commit N fileN &&
58 test_commit O fileO &&
59 test_commit P fileP
1b1dce4b
JS
60'
61
fa90ab4a 62# "exec" commands are run with the user shell by default, but this may
cd035b1c 63# be non-POSIX. For example, if SHELL=zsh then ">file" doesn't work
386aad5a 64# to create a file. Unsetting SHELL avoids such non-portable behavior
5cd3e107 65# in tests. It must be exported for it to take effect where needed.
cd035b1c 66SHELL=
5cd3e107 67export SHELL
cd035b1c 68
bd46cfae 69test_expect_success 'rebase --keep-empty' '
9c8509a4 70 git checkout -b emptybranch primary &&
bd46cfae
MT
71 git commit --allow-empty -m "empty" &&
72 git rebase --keep-empty -i HEAD~2 &&
73 git log --oneline >actual &&
74 test_line_count = 6 actual
75'
76
a9ae8fde 77test_expect_success 'rebase -i with empty todo list' '
c9749b36
SG
78 cat >expect <<-\EOF &&
79 error: nothing to do
80 EOF
b2dbacbd
PW
81 (
82 set_fake_editor &&
a9ae8fde
EN
83 test_must_fail env FAKE_LINES="#" \
84 git rebase -i HEAD^ >output 2>&1
b2dbacbd 85 ) &&
a9ae8fde 86 tail -n 1 output >actual && # Ignore output about changing todo list
1108cea7 87 test_cmp expect actual
d078c391
AG
88'
89
cd035b1c 90test_expect_success 'rebase -i with the exec command' '
9c8509a4 91 git checkout primary &&
cd035b1c 92 (
31cd8275 93 set_fake_editor &&
cd035b1c
MM
94 FAKE_LINES="1 exec_>touch-one
95 2 exec_>touch-two exec_false exec_>touch-three
96 3 4 exec_>\"touch-file__name_with_spaces\";_>touch-after-semicolon 5" &&
97 export FAKE_LINES &&
98 test_must_fail git rebase -i A
99 ) &&
2caf20c5
MM
100 test_path_is_file touch-one &&
101 test_path_is_file touch-two &&
45a26864
ÆAB
102 # Missing because we should have stopped by now.
103 test_path_is_missing touch-three &&
5c947e2c 104 test_cmp_rev C HEAD &&
cd035b1c 105 git rebase --continue &&
2caf20c5
MM
106 test_path_is_file touch-three &&
107 test_path_is_file "touch-file name with spaces" &&
108 test_path_is_file touch-after-semicolon &&
9c8509a4 109 test_cmp_rev primary HEAD &&
cd035b1c
MM
110 rm -f touch-*
111'
112
113test_expect_success 'rebase -i with the exec command runs from tree root' '
9c8509a4 114 git checkout primary &&
c2e0940b 115 mkdir subdir && (cd subdir &&
31cd8275 116 set_fake_editor &&
cd035b1c 117 FAKE_LINES="1 exec_>touch-subdir" \
c2e0940b
JL
118 git rebase -i HEAD^
119 ) &&
2caf20c5 120 test_path_is_file touch-subdir &&
cd035b1c
MM
121 rm -fr subdir
122'
123
09d7b6c6
JK
124test_expect_success 'rebase -i with exec allows git commands in subdirs' '
125 test_when_finished "rm -rf subdir" &&
126 test_when_finished "git rebase --abort ||:" &&
9c8509a4 127 git checkout primary &&
09d7b6c6
JK
128 mkdir subdir && (cd subdir &&
129 set_fake_editor &&
8c64bc94 130 FAKE_LINES="1 x_cd_subdir_&&_git_rev-parse_--is-inside-work-tree" \
09d7b6c6
JK
131 git rebase -i HEAD^
132 )
133'
134
ab5e67d7 135test_expect_success 'rebase -i sets work tree properly' '
136 test_when_finished "rm -rf subdir" &&
137 test_when_finished "test_might_fail git rebase --abort" &&
138 mkdir subdir &&
139 git rebase -x "(cd subdir && git rev-parse --show-toplevel)" HEAD^ \
140 >actual &&
141 ! grep "/subdir$" actual
142'
143
cd035b1c 144test_expect_success 'rebase -i with the exec command checks tree cleanness' '
9c8509a4 145 git checkout primary &&
b2dbacbd
PW
146 (
147 set_fake_editor &&
148 test_must_fail env FAKE_LINES="exec_echo_foo_>file1 1" \
149 git rebase -i HEAD^
150 ) &&
9c8509a4 151 test_cmp_rev primary^ HEAD &&
cd035b1c
MM
152 git reset --hard &&
153 git rebase --continue
154'
155
e4301f73
VN
156test_expect_success 'cherry-pick works with rebase --exec' '
157 test_when_finished "git cherry-pick --abort; \
158 git rebase --abort; \
159 git checkout primary" &&
160 echo "exec git cherry-pick G" >todo &&
161 (
162 set_replace_editor todo &&
163 test_must_fail git rebase -i D D
164 ) &&
165 test_cmp_rev G CHERRY_PICK_HEAD
166'
167
c762aada
PW
168test_expect_success 'rebase -x with empty command fails' '
169 test_when_finished "git rebase --abort ||:" &&
d03ebd41 170 test_must_fail env git rebase -x "" @ 2>actual &&
c762aada 171 test_write_lines "error: empty exec command" >expected &&
1108cea7 172 test_cmp expected actual &&
d03ebd41 173 test_must_fail env git rebase -x " " @ 2>actual &&
1108cea7 174 test_cmp expected actual
c762aada
PW
175'
176
c762aada
PW
177test_expect_success 'rebase -x with newline in command fails' '
178 test_when_finished "git rebase --abort ||:" &&
d03ebd41 179 test_must_fail env git rebase -x "a${LF}b" @ 2>actual &&
c762aada
PW
180 test_write_lines "error: exec commands cannot contain newlines" \
181 >expected &&
1108cea7 182 test_cmp expected actual
c762aada
PW
183'
184
ecfe1ea9 185test_expect_success 'rebase -i with exec of inexistent command' '
9c8509a4 186 git checkout primary &&
ecfe1ea9 187 test_when_finished "git rebase --abort" &&
b2dbacbd
PW
188 (
189 set_fake_editor &&
190 test_must_fail env FAKE_LINES="exec_this-command-does-not-exist 1" \
191 git rebase -i HEAD^ >actual 2>&1
192 ) &&
ecfe1ea9
JS
193 ! grep "Maybe git-rebase is broken" actual
194'
195
891d4a03
PW
196test_expect_success 'implicit interactive rebase does not invoke sequence editor' '
197 test_when_finished "git rebase --abort ||:" &&
198 GIT_SEQUENCE_EDITOR="echo bad >" git rebase -x"echo one" @^
199'
200
1b1dce4b 201test_expect_success 'no changes are a nop' '
6c4c44c4 202 git checkout branch2 &&
1b1dce4b 203 git rebase -i F &&
ab736792 204 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
780308d0 205 test_cmp_rev I HEAD
1b1dce4b
JS
206'
207
c9e65892
JS
208test_expect_success 'test the [branch] option' '
209 git checkout -b dead-end &&
210 git rm file6 &&
211 git commit -m "stop here" &&
212 git rebase -i F branch2 &&
ab736792 213 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
780308d0
PW
214 test_cmp_rev I branch2 &&
215 test_cmp_rev I HEAD
c9e65892
JS
216'
217
ab736792
SB
218test_expect_success 'test --onto <branch>' '
219 git checkout -b test-onto branch2 &&
220 git rebase -i --onto branch1 F &&
221 test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" &&
780308d0
PW
222 test_cmp_rev HEAD^ branch1 &&
223 test_cmp_rev I branch2
ab736792
SB
224'
225
1b1dce4b
JS
226test_expect_success 'rebase on top of a non-conflicting commit' '
227 git checkout branch1 &&
228 git tag original-branch1 &&
229 git rebase -i branch2 &&
230 test file6 = $(git diff --name-only original-branch1) &&
ab736792 231 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
780308d0
PW
232 test_cmp_rev I branch2 &&
233 test_cmp_rev I HEAD~2
1b1dce4b
JS
234'
235
68a163c9 236test_expect_success 'reflog for the branch shows state before rebase' '
780308d0 237 test_cmp_rev branch1@{1} original-branch1
68a163c9
JS
238'
239
1ceb9dfa 240test_expect_success 'reflog for the branch shows correct finish message' '
c2417d3a 241 printf "rebase (finish): refs/heads/branch1 onto %s\n" \
1ceb9dfa
PW
242 "$(git rev-parse branch2)" >expected &&
243 git log -g --pretty=%gs -1 refs/heads/branch1 >actual &&
244 test_cmp expected actual
245'
246
1b1dce4b 247test_expect_success 'exchange two commits' '
b2dbacbd
PW
248 (
249 set_fake_editor &&
250 FAKE_LINES="2 1" git rebase -i HEAD~2
251 ) &&
b4ce54fc 252 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
4dd1b5f9 253 test G = $(git cat-file commit HEAD | sed -ne \$p) &&
254 blob1=$(git rev-parse --short HEAD^:file1) &&
255 blob2=$(git rev-parse --short HEAD:file1) &&
256 commit=$(git rev-parse --short HEAD)
1b1dce4b
JS
257'
258
1b1dce4b 259test_expect_success 'stop on conflicting pick' '
4dd1b5f9 260 cat >expect <<-EOF &&
c9749b36 261 diff --git a/file1 b/file1
4dd1b5f9 262 index $blob1..$blob2 100644
c9749b36
SG
263 --- a/file1
264 +++ b/file1
265 @@ -1 +1 @@
266 -A
267 +G
268 EOF
4dd1b5f9 269 cat >expect2 <<-EOF &&
c9749b36
SG
270 <<<<<<< HEAD
271 D
272 =======
273 G
7d056dea 274 >>>>>>> $commit (G)
c9749b36 275 EOF
1b1dce4b 276 git tag new-branch1 &&
9c8509a4
JS
277 test_must_fail git rebase -i primary &&
278 test "$(git rev-parse HEAD~3)" = "$(git rev-parse primary)" &&
28ed6e7b 279 test_cmp expect .git/rebase-merge/patch &&
82ebb0b6 280 test_cmp expect2 file1 &&
0cb0e143 281 test "$(git diff --name-status |
ab736792 282 sed -n -e "/^U/s/^U[^a-z]*//p")" = file1 &&
28ed6e7b
JS
283 test 4 = $(grep -v "^#" < .git/rebase-merge/done | wc -l) &&
284 test 0 = $(grep -c "^[^#]" < .git/rebase-merge/git-rebase-todo)
1b1dce4b
JS
285'
286
66335298
NTND
287test_expect_success 'show conflicted patch' '
288 GIT_TRACE=1 git rebase --show-current-patch >/dev/null 2>stderr &&
fbd7a232
NTND
289 grep "show.*REBASE_HEAD" stderr &&
290 # the original stopped-sha1 is abbreviated
291 stopped_sha1="$(git rev-parse $(cat ".git/rebase-merge/stopped-sha"))" &&
292 test "$(git rev-parse REBASE_HEAD)" = "$stopped_sha1"
66335298
NTND
293'
294
1b1dce4b
JS
295test_expect_success 'abort' '
296 git rebase --abort &&
780308d0 297 test_cmp_rev new-branch1 HEAD &&
ab736792 298 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
2caf20c5 299 test_path_is_missing .git/rebase-merge
1b1dce4b
JS
300'
301
b096374f
IWC
302test_expect_success 'abort with error when new base cannot be checked out' '
303 git rm --cached file1 &&
304 git commit -m "remove file in base" &&
9c8509a4 305 test_must_fail git rebase -i primary > output 2>&1 &&
6789275d 306 test_grep "The following untracked working tree files would be overwritten by checkout:" \
b096374f 307 output &&
6789275d 308 test_grep "file1" output &&
2caf20c5 309 test_path_is_missing .git/rebase-merge &&
f222bd34 310 rm file1 &&
b096374f
IWC
311 git reset --hard HEAD^
312'
313
1b1dce4b
JS
314test_expect_success 'retain authorship' '
315 echo A > file7 &&
316 git add file7 &&
c54b7817 317 test_tick &&
1b1dce4b
JS
318 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
319 git tag twerp &&
9c8509a4 320 git rebase -i --onto primary HEAD^ &&
1b1dce4b
JS
321 git show HEAD | grep "^Author: Twerp Snog"
322'
323
a2a20b0d 324test_expect_success 'retain authorship w/ conflicts' '
650161a2
JH
325 oGIT_AUTHOR_NAME=$GIT_AUTHOR_NAME &&
326 test_when_finished "GIT_AUTHOR_NAME=\$oGIT_AUTHOR_NAME" &&
327
a2a20b0d
JS
328 git reset --hard twerp &&
329 test_commit a conflict a conflict-a &&
330 git reset --hard twerp &&
650161a2
JH
331
332 GIT_AUTHOR_NAME=AttributeMe &&
333 export GIT_AUTHOR_NAME &&
a2a20b0d 334 test_commit b conflict b conflict-b &&
650161a2
JH
335 GIT_AUTHOR_NAME=$oGIT_AUTHOR_NAME &&
336
a2a20b0d
JS
337 test_must_fail git rebase -i conflict-a &&
338 echo resolved >conflict &&
339 git add conflict &&
340 git rebase --continue &&
780308d0 341 test_cmp_rev conflict-a^0 HEAD^ &&
a2a20b0d
JS
342 git show >out &&
343 grep AttributeMe out
344'
345
1b1dce4b
JS
346test_expect_success 'squash' '
347 git reset --hard twerp &&
348 echo B > file7 &&
c54b7817 349 test_tick &&
1b1dce4b
JS
350 GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 &&
351 echo "******************************" &&
b2dbacbd
PW
352 (
353 set_fake_editor &&
354 FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \
9c8509a4 355 git rebase -i --onto primary HEAD~2
b2dbacbd 356 ) &&
1b1dce4b 357 test B = $(cat file7) &&
9c8509a4 358 test_cmp_rev HEAD^ primary
1b1dce4b
JS
359'
360
361test_expect_success 'retain authorship when squashing' '
81ab1cb4 362 git show HEAD | grep "^Author: Twerp Snog"
1b1dce4b
JS
363'
364
18640d99 365test_expect_success '--continue tries to commit' '
6c8fbae6 366 git reset --hard D &&
18640d99 367 test_tick &&
b2dbacbd
PW
368 (
369 set_fake_editor &&
370 test_must_fail git rebase -i --onto new-branch1 HEAD^ &&
371 echo resolved > file1 &&
372 git add file1 &&
373 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue
374 ) &&
780308d0 375 test_cmp_rev HEAD^ new-branch1 &&
18640d99
JS
376 git show HEAD | grep chouette
377'
378
8e4a91bd 379test_expect_success 'verbose flag is heeded, even after --continue' '
9c8509a4 380 git reset --hard primary@{1} &&
8e4a91bd 381 test_tick &&
ab736792 382 test_must_fail git rebase -v -i --onto new-branch1 HEAD^ &&
8e4a91bd
JS
383 echo resolved > file1 &&
384 git add file1 &&
385 git rebase --continue > output &&
dc801e71 386 grep "^ file1 | 2 +-$" output
8e4a91bd
JS
387'
388
a926c4b9 389test_expect_success 'multi-squash only fires up editor once' '
6368f3f8 390 base=$(git rev-parse HEAD~4) &&
b2dbacbd
PW
391 (
392 set_fake_editor &&
393 FAKE_COMMIT_AMEND="ONCE" \
394 FAKE_LINES="1 squash 2 squash 3 squash 4" \
395 EXPECT_HEADER_COUNT=4 \
396 git rebase -i $base
397 ) &&
6368f3f8
JS
398 test $base = $(git rev-parse HEAD^) &&
399 test 1 = $(git show | grep ONCE | wc -l)
400'
401
a926c4b9 402test_expect_success 'multi-fixup does not fire up editor' '
0205e72f
MH
403 git checkout -b multi-fixup E &&
404 base=$(git rev-parse HEAD~4) &&
b2dbacbd
PW
405 (
406 set_fake_editor &&
407 FAKE_COMMIT_AMEND="NEVER" \
408 FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \
409 git rebase -i $base
410 ) &&
0205e72f 411 test $base = $(git rev-parse HEAD^) &&
a25eb139 412 test 0 = $(git show | grep NEVER | wc -l) &&
6c8fbae6 413 git checkout @{-1} &&
0205e72f
MH
414 git branch -D multi-fixup
415'
416
6bdcd0d2
MH
417test_expect_success 'commit message used after conflict' '
418 git checkout -b conflict-fixup conflict-branch &&
419 base=$(git rev-parse HEAD~4) &&
b2dbacbd
PW
420 (
421 set_fake_editor &&
422 test_must_fail env FAKE_LINES="1 fixup 3 fixup 4" \
423 git rebase -i $base &&
424 echo three > conflict &&
425 git add conflict &&
426 FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \
427 git rebase --continue
428 ) &&
6bdcd0d2
MH
429 test $base = $(git rev-parse HEAD^) &&
430 test 1 = $(git show | grep ONCE | wc -l) &&
6c8fbae6 431 git checkout @{-1} &&
6bdcd0d2
MH
432 git branch -D conflict-fixup
433'
434
435test_expect_success 'commit message retained after conflict' '
436 git checkout -b conflict-squash conflict-branch &&
437 base=$(git rev-parse HEAD~4) &&
b2dbacbd
PW
438 (
439 set_fake_editor &&
440 test_must_fail env FAKE_LINES="1 fixup 3 squash 4" \
441 git rebase -i $base &&
442 echo three > conflict &&
443 git add conflict &&
444 FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \
445 git rebase --continue
446 ) &&
6bdcd0d2
MH
447 test $base = $(git rev-parse HEAD^) &&
448 test 2 = $(git show | grep TWICE | wc -l) &&
6c8fbae6 449 git checkout @{-1} &&
6bdcd0d2
MH
450 git branch -D conflict-squash
451'
452
a926c4b9 453test_expect_success 'squash and fixup generate correct log messages' '
c9749b36
SG
454 cat >expect-squash-fixup <<-\EOF &&
455 B
0205e72f 456
c9749b36 457 D
0205e72f 458
c9749b36
SG
459 ONCE
460 EOF
0205e72f
MH
461 git checkout -b squash-fixup E &&
462 base=$(git rev-parse HEAD~4) &&
b2dbacbd
PW
463 (
464 set_fake_editor &&
465 FAKE_COMMIT_AMEND="ONCE" \
466 FAKE_LINES="1 fixup 2 squash 3 fixup 4" \
467 EXPECT_HEADER_COUNT=4 \
468 git rebase -i $base
469 ) &&
0205e72f
MH
470 git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup &&
471 test_cmp expect-squash-fixup actual-squash-fixup &&
60b61588
PW
472 git cat-file commit HEAD@{2} |
473 grep "^# This is a combination of 3 commits\." &&
474 git cat-file commit HEAD@{3} |
475 grep "^# This is a combination of 2 commits\." &&
6c8fbae6 476 git checkout @{-1} &&
0205e72f
MH
477 git branch -D squash-fixup
478'
479
a926c4b9 480test_expect_success 'squash ignores comments' '
234b3dae
MH
481 git checkout -b skip-comments E &&
482 base=$(git rev-parse HEAD~4) &&
b2dbacbd
PW
483 (
484 set_fake_editor &&
485 FAKE_COMMIT_AMEND="ONCE" \
486 FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \
487 EXPECT_HEADER_COUNT=4 \
488 git rebase -i $base
489 ) &&
234b3dae
MH
490 test $base = $(git rev-parse HEAD^) &&
491 test 1 = $(git show | grep ONCE | wc -l) &&
6c8fbae6 492 git checkout @{-1} &&
234b3dae
MH
493 git branch -D skip-comments
494'
495
a926c4b9 496test_expect_success 'squash ignores blank lines' '
234b3dae
MH
497 git checkout -b skip-blank-lines E &&
498 base=$(git rev-parse HEAD~4) &&
b2dbacbd
PW
499 (
500 set_fake_editor &&
501 FAKE_COMMIT_AMEND="ONCE" \
502 FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \
503 EXPECT_HEADER_COUNT=4 \
504 git rebase -i $base
505 ) &&
234b3dae
MH
506 test $base = $(git rev-parse HEAD^) &&
507 test 1 = $(git show | grep ONCE | wc -l) &&
6c8fbae6 508 git checkout @{-1} &&
234b3dae
MH
509 git branch -D skip-blank-lines
510'
511
fb47cfbd 512test_expect_success 'squash works as expected' '
6c4c44c4 513 git checkout -b squash-works no-conflict-branch &&
fb47cfbd 514 one=$(git rev-parse HEAD~3) &&
b2dbacbd
PW
515 (
516 set_fake_editor &&
517 FAKE_LINES="1 s 3 2" EXPECT_HEADER_COUNT=2 git rebase -i HEAD~3
518 ) &&
fb47cfbd
JS
519 test $one = $(git rev-parse HEAD~2)
520'
521
522test_expect_success 'interrupted squash works as expected' '
6c4c44c4 523 git checkout -b interrupted-squash conflict-branch &&
fb47cfbd 524 one=$(git rev-parse HEAD~3) &&
b2dbacbd
PW
525 (
526 set_fake_editor &&
527 test_must_fail env FAKE_LINES="1 squash 3 2" \
528 git rebase -i HEAD~3
529 ) &&
0590ff26 530 test_write_lines one two four > conflict &&
fb47cfbd 531 git add conflict &&
ab736792 532 test_must_fail git rebase --continue &&
fb47cfbd
JS
533 echo resolved > conflict &&
534 git add conflict &&
535 git rebase --continue &&
536 test $one = $(git rev-parse HEAD~2)
537'
538
1d25c8cf 539test_expect_success 'interrupted squash works as expected (case 2)' '
6c4c44c4 540 git checkout -b interrupted-squash2 conflict-branch &&
1d25c8cf 541 one=$(git rev-parse HEAD~3) &&
b2dbacbd
PW
542 (
543 set_fake_editor &&
544 test_must_fail env FAKE_LINES="3 squash 1 2" \
545 git rebase -i HEAD~3
546 ) &&
0590ff26 547 test_write_lines one four > conflict &&
1d25c8cf 548 git add conflict &&
ab736792 549 test_must_fail git rebase --continue &&
0590ff26 550 test_write_lines one two four > conflict &&
1d25c8cf 551 git add conflict &&
ab736792 552 test_must_fail git rebase --continue &&
1d25c8cf
JS
553 echo resolved > conflict &&
554 git add conflict &&
555 git rebase --continue &&
556 test $one = $(git rev-parse HEAD~2)
557'
558
3f213981 559test_expect_success '--continue tries to commit, even for "edit"' '
96ffe892
JS
560 echo unrelated > file7 &&
561 git add file7 &&
562 test_tick &&
563 git commit -m "unrelated change" &&
be6ff208
JS
564 parent=$(git rev-parse HEAD^) &&
565 test_tick &&
b2dbacbd
PW
566 (
567 set_fake_editor &&
568 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
569 echo edited > file7 &&
570 git add file7 &&
571 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue
572 ) &&
be6ff208
JS
573 test edited = $(git show HEAD:file7) &&
574 git show HEAD | grep chouette &&
575 test $parent = $(git rev-parse HEAD^)
576'
577
dc7f55cb
SB
578test_expect_success 'aborted --continue does not squash commits after "edit"' '
579 old=$(git rev-parse HEAD) &&
580 test_tick &&
b2dbacbd
PW
581 (
582 set_fake_editor &&
583 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
584 echo "edited again" > file7 &&
585 git add file7 &&
586 test_must_fail env FAKE_COMMIT_MESSAGE=" " git rebase --continue
587 ) &&
a3ec9eaf
EN
588 test $old = $(git rev-parse HEAD) &&
589 git rebase --abort
dc7f55cb
SB
590'
591
f8aa1b69
SB
592test_expect_success 'auto-amend only edited commits after "edit"' '
593 test_tick &&
b2dbacbd
PW
594 (
595 set_fake_editor &&
596 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
597 echo "edited again" > file7 &&
598 git add file7 &&
599 FAKE_COMMIT_MESSAGE="edited file7 again" git commit &&
600 echo "and again" > file7 &&
601 git add file7 &&
602 test_tick &&
603 test_must_fail env FAKE_COMMIT_MESSAGE="and again" \
604 git rebase --continue
605 ) &&
f8aa1b69
SB
606 git rebase --abort
607'
608
ffaaed88
MM
609test_expect_success 'clean error after failed "exec"' '
610 test_tick &&
611 test_when_finished "git rebase --abort || :" &&
b2dbacbd
PW
612 (
613 set_fake_editor &&
614 test_must_fail env FAKE_LINES="1 exec_false" git rebase -i HEAD^
615 ) &&
ffaaed88
MM
616 echo "edited again" > file7 &&
617 git add file7 &&
618 test_must_fail git rebase --continue 2>error &&
a8e23947
JH
619 test_grep "you have staged changes in your working tree" error &&
620 test_grep ! "could not open.*for reading" error
ffaaed88
MM
621'
622
73697a0b
JS
623test_expect_success 'rebase a detached HEAD' '
624 grandparent=$(git rev-parse HEAD~2) &&
625 git checkout $(git rev-parse HEAD) &&
626 test_tick &&
b2dbacbd
PW
627 (
628 set_fake_editor &&
629 FAKE_LINES="2 1" git rebase -i HEAD~2
630 ) &&
73697a0b
JS
631 test $grandparent = $(git rev-parse HEAD~2)
632'
633
752527f5 634test_expect_success 'rebase a commit violating pre-commit' '
bef805b7 635 test_hook pre-commit <<-\EOF &&
7bec7f50
JH
636 test -z "$(git diff --cached --check)"
637 EOF
752527f5
JS
638 echo "monde! " >> file1 &&
639 test_tick &&
ab736792 640 test_must_fail git commit -m doesnt-verify file1 &&
752527f5
JS
641 git commit -m doesnt-verify --no-verify file1 &&
642 test_tick &&
b2dbacbd
PW
643 (
644 set_fake_editor &&
645 FAKE_LINES=2 git rebase -i HEAD~2
646 )
752527f5
JS
647'
648
077b725f 649test_expect_success 'rebase with a file named HEAD in worktree' '
077b725f
JH
650 git reset --hard &&
651 git checkout -b branch3 A &&
652
653 (
654 GIT_AUTHOR_NAME="Squashed Away" &&
655 export GIT_AUTHOR_NAME &&
656 >HEAD &&
657 git add HEAD &&
658 git commit -m "Add head" &&
659 >BODY &&
660 git add BODY &&
661 git commit -m "Add body"
662 ) &&
663
b2dbacbd
PW
664 (
665 set_fake_editor &&
666 FAKE_LINES="1 squash 2" git rebase -i @{-1}
667 ) &&
077b725f
JH
668 test "$(git show -s --pretty=format:%an)" = "Squashed Away"
669
670'
671
ff74126c
JS
672test_expect_success 'do "noop" when there is nothing to cherry-pick' '
673
674 git checkout -b branch4 HEAD &&
675 GIT_EDITOR=: git commit --amend \
2dec68cf 676 --author="Somebody else <somebody@else.com>" &&
ff74126c
JS
677 test $(git rev-parse branch3) != $(git rev-parse branch4) &&
678 git rebase -i branch3 &&
780308d0 679 test_cmp_rev branch3 branch4
ff74126c
JS
680
681'
682
96747696
JH
683test_expect_success 'submodule rebase setup' '
684 git checkout A &&
685 mkdir sub &&
686 (
687 cd sub && git init && >elif &&
688 git add elif && git commit -m "submodule initial"
689 ) &&
690 echo 1 >file1 &&
2dec68cf 691 git add file1 sub &&
96747696
JH
692 test_tick &&
693 git commit -m "One" &&
694 echo 2 >file1 &&
695 test_tick &&
696 git commit -a -m "Two" &&
697 (
698 cd sub && echo 3 >elif &&
699 git commit -a -m "submodule second"
700 ) &&
701 test_tick &&
702 git commit -a -m "Three changes submodule"
703'
704
94c88ede 705test_expect_success 'submodule rebase -i' '
b2dbacbd
PW
706 (
707 set_fake_editor &&
708 FAKE_LINES="1 squash 2 3" git rebase -i A
709 )
96747696
JH
710'
711
a6754cda
JK
712test_expect_success 'submodule conflict setup' '
713 git tag submodule-base &&
714 git checkout HEAD^ &&
715 (
716 cd sub && git checkout HEAD^ && echo 4 >elif &&
717 git add elif && git commit -m "submodule conflict"
718 ) &&
719 git add sub &&
720 test_tick &&
721 git commit -m "Conflict in submodule" &&
722 git tag submodule-topic
723'
724
725test_expect_success 'rebase -i continue with only submodule staged' '
726 test_must_fail git rebase -i submodule-base &&
727 git add sub &&
728 git rebase --continue &&
729 test $(git rev-parse submodule-base) != $(git rev-parse HEAD)
730'
731
732test_expect_success 'rebase -i continue with unstaged submodule' '
733 git checkout submodule-topic &&
734 git reset --hard &&
735 test_must_fail git rebase -i submodule-base &&
736 git reset &&
737 git rebase --continue &&
780308d0 738 test_cmp_rev submodule-base HEAD
a6754cda
JK
739'
740
0e757e30 741test_expect_success 'avoid unnecessary reset' '
9c8509a4 742 git checkout primary &&
a6754cda 743 git reset --hard &&
0e496492 744 test-tool chmtime =123456789 file3 &&
0e757e30
JS
745 git update-index --refresh &&
746 HEAD=$(git rev-parse HEAD) &&
747 git rebase -i HEAD~4 &&
748 test $HEAD = $(git rev-parse HEAD) &&
deb9845a 749 MTIME=$(test-tool chmtime --get file3) &&
0e757e30
JS
750 test 123456789 = $MTIME
751'
752
6741aa6c 753test_expect_success 'reword' '
9c8509a4 754 git checkout -b reword-branch primary &&
b2dbacbd
PW
755 (
756 set_fake_editor &&
757 FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" \
758 git rebase -i A &&
759 git show HEAD | grep "E changed" &&
9c8509a4
JS
760 test $(git rev-parse primary) != $(git rev-parse HEAD) &&
761 test_cmp_rev primary^ HEAD^ &&
b2dbacbd
PW
762 FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" \
763 git rebase -i A &&
764 git show HEAD^ | grep "D changed" &&
765 FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" \
766 git rebase -i A &&
767 git show HEAD~3 | grep "B changed" &&
768 FAKE_LINES="1 r 2 pick 3 p 4" FAKE_COMMIT_MESSAGE="C changed" \
769 git rebase -i A
770 ) &&
6741aa6c
BG
771 git show HEAD~2 | grep "C changed"
772'
773
8aae4897 774test_expect_success 'no uncommitted changes when rewording and the todo list is reloaded' '
0c164ae7
PW
775 git checkout E &&
776 test_when_finished "git checkout @{-1}" &&
777 (
778 set_fake_editor &&
779 GIT_SEQUENCE_EDITOR="\"$PWD/fake-editor.sh\"" &&
780 export GIT_SEQUENCE_EDITOR &&
781 set_reword_editor &&
782 FAKE_LINES="reword 1 reword 2" git rebase -i C
783 ) &&
784 check_reworded_commits D E
785'
786
eb2151bb
TR
787test_expect_success 'rebase -i can copy notes' '
788 git config notes.rewrite.rebase true &&
789 git config notes.rewriteRef "refs/notes/*" &&
790 test_commit n1 &&
791 test_commit n2 &&
792 test_commit n3 &&
793 git notes add -m"a note" n3 &&
6f87f038 794 git rebase -i --onto n1 n2 &&
eb2151bb
TR
795 test "a note" = "$(git notes show HEAD)"
796'
797
eb2151bb 798test_expect_success 'rebase -i can copy notes over a fixup' '
c9749b36
SG
799 cat >expect <<-\EOF &&
800 an earlier note
801
802 a note
803 EOF
eb2151bb
TR
804 git reset --hard n3 &&
805 git notes add -m"an earlier note" n2 &&
b2dbacbd
PW
806 (
807 set_fake_editor &&
808 GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 f 2" \
809 git rebase -i n1
810 ) &&
eb2151bb
TR
811 git notes show > output &&
812 test_cmp expect output
813'
814
2ec33cdd
DO
815test_expect_success 'rebase while detaching HEAD' '
816 git symbolic-ref HEAD &&
817 grandparent=$(git rev-parse HEAD~2) &&
818 test_tick &&
b2dbacbd
PW
819 (
820 set_fake_editor &&
821 FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0
822 ) &&
2ec33cdd
DO
823 test $grandparent = $(git rev-parse HEAD~2) &&
824 test_must_fail git symbolic-ref HEAD
825'
826
b4995494
MB
827test_tick # Ensure that the rebased commits get a different timestamp.
828test_expect_success 'always cherry-pick with --no-ff' '
829 git checkout no-ff-branch &&
830 git tag original-no-ff-branch &&
831 git rebase -i --no-ff A &&
b4995494
MB
832 for p in 0 1 2
833 do
834 test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) &&
835 git diff HEAD~$p original-no-ff-branch~$p > out &&
db5875aa 836 test_must_be_empty out || return 1
b4995494 837 done &&
780308d0 838 test_cmp_rev HEAD~3 original-no-ff-branch~3 &&
b4995494 839 git diff HEAD~3 original-no-ff-branch~3 > out &&
1c5e94f4 840 test_must_be_empty out
b4995494
MB
841'
842
57f2b6b2
JH
843test_expect_success 'set up commits with funny messages' '
844 git checkout -b funny A &&
845 echo >>file1 &&
846 test_tick &&
847 git commit -a -m "end with slash\\" &&
848 echo >>file1 &&
849 test_tick &&
938791cd
BC
850 git commit -a -m "something (\000) that looks like octal" &&
851 echo >>file1 &&
852 test_tick &&
853 git commit -a -m "something (\n) that looks like a newline" &&
854 echo >>file1 &&
855 test_tick &&
57f2b6b2
JH
856 git commit -a -m "another commit"
857'
858
859test_expect_success 'rebase-i history with funny messages' '
860 git rev-list A..funny >expect &&
861 test_tick &&
b2dbacbd
PW
862 (
863 set_fake_editor &&
864 FAKE_LINES="1 2 3 4" git rebase -i A
865 ) &&
57f2b6b2
JH
866 git rev-list A.. >actual &&
867 test_cmp expect actual
868'
869
c2145384 870test_expect_success 'prepare for rebase -i --exec' '
9c8509a4 871 git checkout primary &&
c2145384
LK
872 git checkout -b execute &&
873 test_commit one_exec main.txt one_exec &&
874 test_commit two_exec main.txt two_exec &&
875 test_commit three_exec main.txt three_exec
876'
877
c2145384 878test_expect_success 'running "git rebase -i --exec git show HEAD"' '
c2145384 879 (
b2dbacbd
PW
880 set_fake_editor &&
881 git rebase -i --exec "git show HEAD" HEAD~2 >actual &&
c2145384
LK
882 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
883 export FAKE_LINES &&
884 git rebase -i HEAD~2 >expect
885 ) &&
886 sed -e "1,9d" expect >expected &&
887 test_cmp expected actual
888'
889
c2145384
LK
890test_expect_success 'running "git rebase --exec git show HEAD -i"' '
891 git reset --hard execute &&
c2145384 892 (
b2dbacbd
PW
893 set_fake_editor &&
894 git rebase --exec "git show HEAD" -i HEAD~2 >actual &&
c2145384
LK
895 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
896 export FAKE_LINES &&
897 git rebase -i HEAD~2 >expect
898 ) &&
899 sed -e "1,9d" expect >expected &&
900 test_cmp expected actual
901'
902
c2145384
LK
903test_expect_success 'running "git rebase -ix git show HEAD"' '
904 git reset --hard execute &&
c2145384 905 (
b2dbacbd
PW
906 set_fake_editor &&
907 git rebase -ix "git show HEAD" HEAD~2 >actual &&
c2145384
LK
908 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
909 export FAKE_LINES &&
910 git rebase -i HEAD~2 >expect
911 ) &&
912 sed -e "1,9d" expect >expected &&
913 test_cmp expected actual
914'
915
916
917test_expect_success 'rebase -ix with several <CMD>' '
918 git reset --hard execute &&
c2145384 919 (
b2dbacbd
PW
920 set_fake_editor &&
921 git rebase -ix "git show HEAD; pwd" HEAD~2 >actual &&
c2145384
LK
922 FAKE_LINES="1 exec_git_show_HEAD;_pwd 2 exec_git_show_HEAD;_pwd" &&
923 export FAKE_LINES &&
924 git rebase -i HEAD~2 >expect
925 ) &&
926 sed -e "1,9d" expect >expected &&
927 test_cmp expected actual
928'
929
c2145384
LK
930test_expect_success 'rebase -ix with several instances of --exec' '
931 git reset --hard execute &&
c2145384 932 (
b2dbacbd
PW
933 set_fake_editor &&
934 git rebase -i --exec "git show HEAD" --exec "pwd" HEAD~2 >actual &&
c2145384
LK
935 FAKE_LINES="1 exec_git_show_HEAD exec_pwd 2
936 exec_git_show_HEAD exec_pwd" &&
937 export FAKE_LINES &&
938 git rebase -i HEAD~2 >expect
939 ) &&
940 sed -e "1,11d" expect >expected &&
941 test_cmp expected actual
942'
943
a926c4b9 944test_expect_success 'rebase -ix with --autosquash' '
c2145384
LK
945 git reset --hard execute &&
946 git checkout -b autosquash &&
947 echo second >second.txt &&
948 git add second.txt &&
949 git commit -m "fixup! two_exec" &&
950 echo bis >bis.txt &&
951 git add bis.txt &&
952 git commit -m "fixup! two_exec" &&
88a92b6c
PW
953 git checkout -b autosquash_actual &&
954 git rebase -i --exec "git show HEAD" --autosquash HEAD~4 >actual &&
c2145384
LK
955 git checkout autosquash &&
956 (
b2dbacbd 957 set_fake_editor &&
c2145384
LK
958 git checkout -b autosquash_expected &&
959 FAKE_LINES="1 fixup 3 fixup 4 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
960 export FAKE_LINES &&
961 git rebase -i HEAD~4 >expect
962 ) &&
963 sed -e "1,13d" expect >expected &&
964 test_cmp expected actual
965'
966
78ec2400 967test_expect_success 'rebase --exec works without -i ' '
c2145384 968 git reset --hard execute &&
78ec2400
SB
969 rm -rf exec_output &&
970 EDITOR="echo >invoked_editor" git rebase --exec "echo a line >>exec_output" HEAD~2 2>actual &&
6789275d 971 test_grep "Successfully rebased and updated" actual &&
78ec2400
SB
972 test_line_count = 2 exec_output &&
973 test_path_is_missing invoked_editor
c2145384
LK
974'
975
c2145384
LK
976test_expect_success 'rebase -i --exec without <CMD>' '
977 git reset --hard execute &&
3bb0923f 978 test_must_fail git rebase -i --exec 2>actual &&
6789275d 979 test_grep "requires a value" actual &&
9c8509a4 980 git checkout primary
c2145384
LK
981'
982
b64b7feb
CW
983test_expect_success 'rebase -i --root re-order and drop commits' '
984 git checkout E &&
b2dbacbd
PW
985 (
986 set_fake_editor &&
987 FAKE_LINES="3 1 2 5" git rebase -i --root
988 ) &&
b64b7feb
CW
989 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
990 test B = $(git cat-file commit HEAD^ | sed -ne \$p) &&
991 test A = $(git cat-file commit HEAD^^ | sed -ne \$p) &&
992 test C = $(git cat-file commit HEAD^^^ | sed -ne \$p) &&
993 test 0 = $(git cat-file commit HEAD^^^ | grep -c ^parent\ )
994'
995
996test_expect_success 'rebase -i --root retain root commit author and message' '
997 git checkout A &&
998 echo B >file7 &&
999 git add file7 &&
1000 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
b2dbacbd
PW
1001 (
1002 set_fake_editor &&
1003 FAKE_LINES="2" git rebase -i --root
1004 ) &&
b64b7feb
CW
1005 git cat-file commit HEAD | grep -q "^author Twerp Snog" &&
1006 git cat-file commit HEAD | grep -q "^different author$"
1007'
1008
1009test_expect_success 'rebase -i --root temporary sentinel commit' '
1010 git checkout B &&
b2dbacbd
PW
1011 (
1012 set_fake_editor &&
1013 test_must_fail env FAKE_LINES="2" git rebase -i --root
1014 ) &&
4dd1b5f9 1015 git cat-file commit HEAD | grep "^tree $EMPTY_TREE" &&
b64b7feb
CW
1016 git rebase --abort
1017'
1018
2147f844
CW
1019test_expect_success 'rebase -i --root fixup root commit' '
1020 git checkout B &&
b2dbacbd
PW
1021 (
1022 set_fake_editor &&
1023 FAKE_LINES="1 fixup 2" git rebase -i --root
1024 ) &&
2147f844
CW
1025 test A = $(git cat-file commit HEAD | sed -ne \$p) &&
1026 test B = $(git show HEAD:file1) &&
1027 test 0 = $(git cat-file commit HEAD | grep -c ^parent\ )
1028'
1029
450efe2d 1030test_expect_success 'rebase -i --root reword original root commit' '
3a36ca08 1031 test_when_finished "test_might_fail git rebase --abort" &&
9c8509a4 1032 git checkout -b reword-original-root-branch primary &&
b2dbacbd
PW
1033 (
1034 set_fake_editor &&
1035 FAKE_LINES="reword 1 2" FAKE_COMMIT_MESSAGE="A changed" \
1036 git rebase -i --root
1037 ) &&
87881055
TZ
1038 git show HEAD^ | grep "A changed" &&
1039 test -z "$(git show -s --format=%p HEAD^)"
3a36ca08
TZ
1040'
1041
450efe2d
PW
1042test_expect_success 'rebase -i --root reword new root commit' '
1043 test_when_finished "test_might_fail git rebase --abort" &&
9c8509a4 1044 git checkout -b reword-now-root-branch primary &&
b2dbacbd
PW
1045 (
1046 set_fake_editor &&
1047 FAKE_LINES="reword 3 1" FAKE_COMMIT_MESSAGE="C changed" \
1048 git rebase -i --root
1049 ) &&
450efe2d
PW
1050 git show HEAD^ | grep "C changed" &&
1051 test -z "$(git show -s --format=%p HEAD^)"
1052'
1053
cc8d872e 1054test_expect_success 'rebase -i --root when root has untracked file conflict' '
a9279c67
PW
1055 test_when_finished "reset_rebase" &&
1056 git checkout -b failing-root-pick A &&
1057 echo x >file2 &&
1058 git rm file1 &&
1059 git commit -m "remove file 1 add file 2" &&
1060 echo z >file1 &&
b2dbacbd
PW
1061 (
1062 set_fake_editor &&
1063 test_must_fail env FAKE_LINES="1 2" git rebase -i --root
1064 ) &&
a9279c67
PW
1065 rm file1 &&
1066 git rebase --continue &&
1067 test "$(git log -1 --format=%B)" = "remove file 1 add file 2" &&
1068 test "$(git rev-list --count HEAD)" = 2
1069'
1070
1071test_expect_success 'rebase -i --root reword root when root has untracked file conflict' '
1072 test_when_finished "reset_rebase" &&
1073 echo z>file1 &&
b2dbacbd
PW
1074 (
1075 set_fake_editor &&
1076 test_must_fail env FAKE_LINES="reword 1 2" \
1077 FAKE_COMMIT_MESSAGE="Modified A" git rebase -i --root &&
1078 rm file1 &&
1079 FAKE_COMMIT_MESSAGE="Reworded A" git rebase --continue
1080 ) &&
a9279c67
PW
1081 test "$(git log -1 --format=%B HEAD^)" = "Reworded A" &&
1082 test "$(git rev-list --count HEAD)" = 2
1083'
1084
a926c4b9 1085test_expect_success 'rebase --edit-todo does not work on non-interactive rebase' '
450efe2d 1086 git checkout reword-original-root-branch &&
9f4981ba
AW
1087 git reset --hard &&
1088 git checkout conflict-branch &&
b2dbacbd
PW
1089 (
1090 set_fake_editor &&
10cdb9f3 1091 test_must_fail git rebase -f --apply --onto HEAD~2 HEAD~ &&
b2dbacbd
PW
1092 test_must_fail git rebase --edit-todo
1093 ) &&
9f4981ba
AW
1094 git rebase --abort
1095'
1096
1097test_expect_success 'rebase --edit-todo can be used to modify todo' '
1098 git reset --hard &&
1099 git checkout no-conflict-branch^0 &&
b2dbacbd
PW
1100 (
1101 set_fake_editor &&
1102 FAKE_LINES="edit 1 2 3" git rebase -i HEAD~3 &&
1103 FAKE_LINES="2 1" git rebase --edit-todo &&
1104 git rebase --continue
1105 ) &&
9f4981ba
AW
1106 test M = $(git cat-file commit HEAD^ | sed -ne \$p) &&
1107 test L = $(git cat-file commit HEAD | sed -ne \$p)
1108'
1109
26cd160c
RR
1110test_expect_success 'rebase -i produces readable reflog' '
1111 git reset --hard &&
1112 git branch -f branch-reflog-test H &&
1113 git rebase -i --onto I F branch-reflog-test &&
1114 cat >expect <<-\EOF &&
c2417d3a
EN
1115 rebase (finish): returning to refs/heads/branch-reflog-test
1116 rebase (pick): H
1117 rebase (pick): G
1118 rebase (start): checkout I
26cd160c 1119 EOF
d0ab0584
DT
1120 git reflog -n4 HEAD |
1121 sed "s/[^:]*: //" >actual &&
26cd160c
RR
1122 test_cmp expect actual
1123'
1124
180bad3d
JK
1125test_expect_success 'rebase -i respects core.commentchar' '
1126 git reset --hard &&
1127 git checkout E^0 &&
aac6c2f4 1128 test_config core.commentchar "\\" &&
180bad3d
JK
1129 write_script remove-all-but-first.sh <<-\EOF &&
1130 sed -e "2,\$s/^/\\\\/" "$1" >"$1.tmp" &&
1131 mv "$1.tmp" "$1"
1132 EOF
b2dbacbd
PW
1133 (
1134 test_set_editor "$(pwd)/remove-all-but-first.sh" &&
1135 git rebase -i B
1136 ) &&
180bad3d
JK
1137 test B = $(git cat-file commit HEAD^ | sed -ne \$p)
1138'
1139
882cd237 1140test_expect_success 'rebase -i respects core.commentchar=auto' '
66458388
JS
1141 test_config core.commentchar auto &&
1142 write_script copy-edit-script.sh <<-\EOF &&
1143 cp "$1" edit-script
1144 EOF
66458388 1145 test_when_finished "git rebase --abort || :" &&
b2dbacbd
PW
1146 (
1147 test_set_editor "$(pwd)/copy-edit-script.sh" &&
1148 git rebase -i HEAD^
1149 ) &&
66458388
JS
1150 test -z "$(grep -ve "^#" -e "^\$" -e "^pick" edit-script)"
1151'
1152
2e6e276d 1153test_expect_success 'rebase -i, with <onto> and <upstream> specified as :/quuxery' '
6567dc05
RR
1154 test_when_finished "git branch -D torebase" &&
1155 git checkout -b torebase branch1 &&
1156 upstream=$(git rev-parse ":/J") &&
1157 onto=$(git rev-parse ":/A") &&
1158 git rebase --onto $onto $upstream &&
1159 git reset --hard branch1 &&
1160 git rebase --onto ":/A" ":/J" &&
1161 git checkout branch1
1162'
1163
db2b3b82
AF
1164test_expect_success 'rebase -i with --strategy and -X' '
1165 git checkout -b conflict-merge-use-theirs conflict-branch &&
1166 git reset --hard HEAD^ &&
1167 echo five >conflict &&
1168 echo Z >file1 &&
1169 git commit -a -m "one file conflict" &&
1170 EDITOR=true git rebase -i --strategy=recursive -Xours conflict-branch &&
1171 test $(git show conflict-branch:conflict) = $(cat conflict) &&
1172 test $(cat file1) = Z
1173'
1174
040fd39e
FR
1175test_expect_success 'interrupted rebase -i with --strategy and -X' '
1176 git checkout -b conflict-merge-use-theirs-interrupted conflict-branch &&
1177 git reset --hard HEAD^ &&
1178 >breakpoint &&
1179 git add breakpoint &&
1180 git commit -m "breakpoint for interactive mode" &&
1181 echo five >conflict &&
1182 echo Z >file1 &&
1183 git commit -a -m "one file conflict" &&
b2dbacbd
PW
1184 (
1185 set_fake_editor &&
1186 FAKE_LINES="edit 1 2" git rebase -i --strategy=recursive \
1187 -Xours conflict-branch
1188 ) &&
040fd39e
FR
1189 git rebase --continue &&
1190 test $(git show conflict-branch:conflict) = $(cat conflict) &&
1191 test $(cat file1) = Z
1192'
1193
89b0230a 1194test_expect_success 'rebase -i error on commits with \ in message' '
99094a7a 1195 current_head=$(git rev-parse HEAD) &&
89b0230a
MM
1196 test_when_finished "git rebase --abort; git reset --hard $current_head; rm -f error" &&
1197 test_commit TO-REMOVE will-conflict old-content &&
1198 test_commit "\temp" will-conflict new-content dummy &&
512477b1 1199 test_must_fail env EDITOR=true git rebase -i HEAD^ --onto HEAD^^ 2>error &&
89b0230a
MM
1200 test_expect_code 1 grep " emp" error
1201'
1202
800e6a70 1203test_expect_success 'short commit ID setup' '
9c8509a4 1204 test_when_finished "git checkout primary" &&
66ae9a57
ES
1205 git checkout --orphan collide &&
1206 git rm -rf . &&
1207 (
1208 unset test_tick &&
1209 test_commit collide1 collide &&
1210 test_commit --notick collide2 collide &&
1211 test_commit --notick collide3 collide
1212 )
1213'
1214
800e6a70
JS
1215if test -n "$GIT_TEST_FIND_COLLIDER"
1216then
1217 author="$(unset test_tick; test_tick; git var GIT_AUTHOR_IDENT)"
1218 committer="$(unset test_tick; test_tick; git var GIT_COMMITTER_IDENT)"
1219 blob="$(git rev-parse collide2:collide)"
1220 from="$(git rev-parse collide1^0)"
1221 repl="commit refs/heads/collider-&\\n"
1222 repl="${repl}author $author\\ncommitter $committer\\n"
1223 repl="${repl}data <<EOF\\ncollide2 &\\nEOF\\n"
1224 repl="${repl}from $from\\nM 100644 $blob collide\\n"
1225 test_seq 1 32768 | sed "s|.*|$repl|" >script &&
1226 git fast-import <script &&
1227 git pack-refs &&
1228 git for-each-ref >refs &&
1229 grep "^$(test_oid t3404_collision)" <refs >matches &&
1230 cat matches &&
1231 test_line_count -gt 2 matches || {
1232 echo "Could not find a collider" >&2
1233 exit 1
1234 }
1235fi
1236
1237test_expect_success 'short commit ID collide' '
1238 test_oid_cache <<-EOF &&
1239 # collision-related constants
1240 t3404_collision sha1:6bcd
1241 t3404_collision sha256:0161
1242 t3404_collider sha1:ac4f2ee
1243 t3404_collider sha256:16697
1244 EOF
9c8509a4 1245 test_when_finished "reset_rebase && git checkout primary" &&
66ae9a57 1246 git checkout collide &&
800e6a70
JS
1247 colliding_id=$(test_oid t3404_collision) &&
1248 hexsz=$(test_oid hexsz) &&
1249 test $colliding_id = "$(git rev-parse HEAD | cut -c 1-4)" &&
1250 test_config core.abbrev 4 &&
66ae9a57 1251 (
8cf8f9b4
JS
1252 unset test_tick &&
1253 test_tick &&
1254 set_fake_editor &&
800e6a70 1255 FAKE_COMMIT_MESSAGE="collide2 $(test_oid t3404_collider)" \
b6992261 1256 FAKE_LINES="reword 1 break 2" git rebase -i HEAD~2 &&
800e6a70
JS
1257 test $colliding_id = "$(git rev-parse HEAD | cut -c 1-4)" &&
1258 grep "^pick $colliding_id " \
b6992261 1259 .git/rebase-merge/git-rebase-todo.tmp &&
a764c37b 1260 grep -E "^pick [0-9a-f]{$hexsz}" \
b6992261 1261 .git/rebase-merge/git-rebase-todo &&
a764c37b 1262 grep -E "^pick [0-9a-f]{$hexsz}" \
26027625 1263 .git/rebase-merge/git-rebase-todo.backup &&
b6992261
JS
1264 git rebase --continue
1265 ) &&
1266 collide2="$(git rev-parse HEAD~1 | cut -c 1-4)" &&
1267 collide3="$(git rev-parse collide3 | cut -c 1-4)" &&
1268 test "$collide2" = "$collide3"
66ae9a57
ES
1269'
1270
edb72d55
KS
1271test_expect_success 'respect core.abbrev' '
1272 git config core.abbrev 12 &&
b2dbacbd
PW
1273 (
1274 set_cat_todo_editor &&
1275 test_must_fail git rebase -i HEAD~4 >todo-list
1276 ) &&
a764c37b 1277 test 4 = $(grep -c -E "pick [0-9a-f]{12,}" todo-list)
edb72d55
KS
1278'
1279
28c8cfc3
ES
1280test_expect_success 'todo count' '
1281 write_script dump-raw.sh <<-\EOF &&
1282 cat "$1"
1283 EOF
b2dbacbd
PW
1284 (
1285 test_set_editor "$(pwd)/dump-raw.sh" &&
1286 git rebase -i HEAD~4 >actual
1287 ) &&
6789275d 1288 test_grep "^# Rebase ..* onto ..* ([0-9]" actual
28c8cfc3
ES
1289'
1290
8cbc57ca 1291test_expect_success 'rebase -i commits that overwrite untracked files (pick)' '
203573b0 1292 git checkout --force A &&
8cbc57ca 1293 git clean -f &&
203573b0
PW
1294 cat >todo <<-EOF &&
1295 exec >file2
1296 pick $(git rev-parse B) B
1297 pick $(git rev-parse C) C
1298 pick $(git rev-parse D) D
1299 exec cat .git/rebase-merge/done >actual
1300 EOF
b2dbacbd 1301 (
203573b0
PW
1302 set_replace_editor todo &&
1303 test_must_fail git rebase -i A
b2dbacbd 1304 ) &&
203573b0
PW
1305 test_cmp_rev HEAD B &&
1306 test_cmp_rev REBASE_HEAD C &&
1307 head -n3 todo >expect &&
1308 test_cmp expect .git/rebase-merge/done &&
1309 rm file2 &&
e032abd5 1310 test_path_is_missing .git/rebase-merge/patch &&
405509cb
PW
1311 echo changed >file1 &&
1312 git add file1 &&
1313 test_must_fail git rebase --continue 2>err &&
1314 grep "error: you have staged changes in your working tree" err &&
1315 git reset --hard HEAD &&
8cbc57ca 1316 git rebase --continue &&
203573b0
PW
1317 test_cmp_rev HEAD D &&
1318 tail -n3 todo >>expect &&
1319 test_cmp expect actual
8cbc57ca
PH
1320'
1321
1322test_expect_success 'rebase -i commits that overwrite untracked files (squash)' '
1323 git checkout --force branch2 &&
1324 git clean -f &&
1325 git tag original-branch2 &&
b2dbacbd
PW
1326 (
1327 set_fake_editor &&
1328 FAKE_LINES="edit 1 squash 2" git rebase -i A
1329 ) &&
8cbc57ca
PH
1330 test_cmp_rev HEAD F &&
1331 test_path_is_missing file6 &&
1332 >file6 &&
1333 test_must_fail git rebase --continue &&
1334 test_cmp_rev HEAD F &&
e032abd5 1335 test_cmp_rev REBASE_HEAD I &&
8cbc57ca 1336 rm file6 &&
e032abd5 1337 test_path_is_missing .git/rebase-merge/patch &&
405509cb
PW
1338 echo changed >file1 &&
1339 git add file1 &&
1340 test_must_fail git rebase --continue 2>err &&
1341 grep "error: you have staged changes in your working tree" err &&
1342 git reset --hard HEAD &&
8cbc57ca
PH
1343 git rebase --continue &&
1344 test $(git cat-file commit HEAD | sed -ne \$p) = I &&
1345 git reset --hard original-branch2
1346'
1347
1348test_expect_success 'rebase -i commits that overwrite untracked files (no ff)' '
1349 git checkout --force branch2 &&
1350 git clean -f &&
b2dbacbd
PW
1351 (
1352 set_fake_editor &&
1353 FAKE_LINES="edit 1 2" git rebase -i --no-ff A
1354 ) &&
8cbc57ca
PH
1355 test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1356 test_path_is_missing file6 &&
1357 >file6 &&
1358 test_must_fail git rebase --continue &&
1359 test $(git cat-file commit HEAD | sed -ne \$p) = F &&
e032abd5 1360 test_cmp_rev REBASE_HEAD I &&
8cbc57ca 1361 rm file6 &&
e032abd5 1362 test_path_is_missing .git/rebase-merge/patch &&
405509cb
PW
1363 echo changed >file1 &&
1364 git add file1 &&
1365 test_must_fail git rebase --continue 2>err &&
1366 grep "error: you have staged changes in your working tree" err &&
1367 git reset --hard HEAD &&
8cbc57ca
PH
1368 git rebase --continue &&
1369 test $(git cat-file commit HEAD | sed -ne \$p) = I
1370'
1371
0e0aff4b 1372test_expect_success 'rebase --continue removes CHERRY_PICK_HEAD' '
d17ec3a9
JS
1373 git checkout -b commit-to-skip &&
1374 for double in X 3 1
1375 do
1376 test_seq 5 | sed "s/$double/&&/" >seq &&
1377 git add seq &&
1378 test_tick &&
db5875aa 1379 git commit -m seq-$double || return 1
d17ec3a9
JS
1380 done &&
1381 git tag seq-onto &&
1382 git reset --hard HEAD~2 &&
1383 git cherry-pick seq-onto &&
b2dbacbd
PW
1384 (
1385 set_fake_editor &&
1386 test_must_fail env FAKE_LINES= git rebase -i seq-onto
1387 ) &&
d17ec3a9
JS
1388 test -d .git/rebase-merge &&
1389 git rebase --continue &&
1390 git diff --exit-code seq-onto &&
1391 test ! -d .git/rebase-merge &&
1392 test ! -f .git/CHERRY_PICK_HEAD
1393'
1394
c9266d58
GR
1395rebase_setup_and_clean () {
1396 test_when_finished "
9c8509a4 1397 git checkout primary &&
c9266d58
GR
1398 test_might_fail git branch -D $1 &&
1399 test_might_fail git rebase --abort
1400 " &&
9c8509a4 1401 git checkout -b $1 ${2:-primary}
c9266d58
GR
1402}
1403
1404test_expect_success 'drop' '
1405 rebase_setup_and_clean drop-test &&
b2dbacbd
PW
1406 (
1407 set_fake_editor &&
1408 FAKE_LINES="1 drop 2 3 d 4 5" git rebase -i --root
1409 ) &&
c9266d58
GR
1410 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1411 test C = $(git cat-file commit HEAD^ | sed -ne \$p) &&
1412 test A = $(git cat-file commit HEAD^^ | sed -ne \$p)
1413'
1414
37079959
GR
1415test_expect_success 'rebase -i respects rebase.missingCommitsCheck = ignore' '
1416 test_config rebase.missingCommitsCheck ignore &&
1417 rebase_setup_and_clean missing-commit &&
b2dbacbd
PW
1418 (
1419 set_fake_editor &&
1420 FAKE_LINES="1 2 3 4" git rebase -i --root 2>actual
1421 ) &&
37079959 1422 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
6789275d 1423 test_grep \
21d0764c
JS
1424 "Successfully rebased and updated refs/heads/missing-commit" \
1425 actual
37079959
GR
1426'
1427
37079959 1428test_expect_success 'rebase -i respects rebase.missingCommitsCheck = warn' '
c9749b36
SG
1429 cat >expect <<-EOF &&
1430 Warning: some commits may have been dropped accidentally.
1431 Dropped commits (newer to older):
9c8509a4 1432 - $(git rev-list --pretty=oneline --abbrev-commit -1 primary)
c9749b36 1433 To avoid this message, use "drop" to explicitly remove a commit.
c9749b36 1434 EOF
37079959
GR
1435 test_config rebase.missingCommitsCheck warn &&
1436 rebase_setup_and_clean missing-commit &&
b2dbacbd
PW
1437 (
1438 set_fake_editor &&
1439 FAKE_LINES="1 2 3 4" git rebase -i --root 2>actual.2
1440 ) &&
077b9798 1441 head -n4 actual.2 >actual &&
1108cea7 1442 test_cmp expect actual &&
37079959
GR
1443 test D = $(git cat-file commit HEAD | sed -ne \$p)
1444'
1445
37079959 1446test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' '
c9749b36
SG
1447 cat >expect <<-EOF &&
1448 Warning: some commits may have been dropped accidentally.
1449 Dropped commits (newer to older):
9c8509a4
JS
1450 - $(git rev-list --pretty=oneline --abbrev-commit -1 primary)
1451 - $(git rev-list --pretty=oneline --abbrev-commit -1 primary~2)
c9749b36
SG
1452 To avoid this message, use "drop" to explicitly remove a commit.
1453
1454 Use '\''git config rebase.missingCommitsCheck'\'' to change the level of warnings.
1455 The possible behaviours are: ignore, warn, error.
1456
1457 You can fix this with '\''git rebase --edit-todo'\'' and then run '\''git rebase --continue'\''.
1458 Or you can abort the rebase with '\''git rebase --abort'\''.
1459 EOF
37079959
GR
1460 test_config rebase.missingCommitsCheck error &&
1461 rebase_setup_and_clean missing-commit &&
b2dbacbd
PW
1462 (
1463 set_fake_editor &&
1464 test_must_fail env FAKE_LINES="1 2 4" \
1465 git rebase -i --root 2>actual &&
1108cea7 1466 test_cmp expect actual &&
b2dbacbd
PW
1467 cp .git/rebase-merge/git-rebase-todo.backup \
1468 .git/rebase-merge/git-rebase-todo &&
1469 FAKE_LINES="1 2 drop 3 4 drop 5" git rebase --edit-todo
1470 ) &&
37079959
GR
1471 git rebase --continue &&
1472 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1473 test B = $(git cat-file commit HEAD^ | sed -ne \$p)
1474'
1475
5a5445d8
AG
1476test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = ignore' '
1477 test_config rebase.missingCommitsCheck ignore &&
1478 rebase_setup_and_clean missing-commit &&
1479 (
1480 set_fake_editor &&
1481 FAKE_LINES="break 1 2 3 4 5" git rebase -i --root &&
1482 FAKE_LINES="1 2 3 4" git rebase --edit-todo &&
1483 git rebase --continue 2>actual
1484 ) &&
1485 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
6789275d 1486 test_grep \
5a5445d8
AG
1487 "Successfully rebased and updated refs/heads/missing-commit" \
1488 actual
1489'
1490
1491test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = warn' '
1492 cat >expect <<-EOF &&
7aed2c05
PW
1493 error: invalid command '\''pickled'\''
1494 error: invalid line 1: pickled $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4)
5a5445d8
AG
1495 Warning: some commits may have been dropped accidentally.
1496 Dropped commits (newer to older):
9c8509a4
JS
1497 - $(git rev-list --pretty=oneline --abbrev-commit -1 primary)
1498 - $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4)
5a5445d8
AG
1499 To avoid this message, use "drop" to explicitly remove a commit.
1500 EOF
7aed2c05 1501 head -n5 expect >expect.2 &&
5a5445d8
AG
1502 tail -n1 expect >>expect.2 &&
1503 tail -n4 expect.2 >expect.3 &&
1504 test_config rebase.missingCommitsCheck warn &&
1505 rebase_setup_and_clean missing-commit &&
1506 (
1507 set_fake_editor &&
1508 test_must_fail env FAKE_LINES="bad 1 2 3 4 5" \
1509 git rebase -i --root &&
1510 cp .git/rebase-merge/git-rebase-todo.backup orig &&
1511 FAKE_LINES="2 3 4" git rebase --edit-todo 2>actual.2 &&
7aed2c05 1512 head -n7 actual.2 >actual &&
1108cea7 1513 test_cmp expect actual &&
5a5445d8
AG
1514 cp orig .git/rebase-merge/git-rebase-todo &&
1515 FAKE_LINES="1 2 3 4" git rebase --edit-todo 2>actual.2 &&
1516 head -n4 actual.2 >actual &&
1108cea7 1517 test_cmp expect.3 actual &&
5a5445d8
AG
1518 git rebase --continue 2>actual
1519 ) &&
1520 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
6789275d 1521 test_grep \
5a5445d8
AG
1522 "Successfully rebased and updated refs/heads/missing-commit" \
1523 actual
1524'
1525
1526test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = error' '
1527 cat >expect <<-EOF &&
7aed2c05
PW
1528 error: invalid command '\''pickled'\''
1529 error: invalid line 1: pickled $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4)
5a5445d8
AG
1530 Warning: some commits may have been dropped accidentally.
1531 Dropped commits (newer to older):
9c8509a4
JS
1532 - $(git rev-list --pretty=oneline --abbrev-commit -1 primary)
1533 - $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4)
5a5445d8
AG
1534 To avoid this message, use "drop" to explicitly remove a commit.
1535
1536 Use '\''git config rebase.missingCommitsCheck'\'' to change the level of warnings.
1537 The possible behaviours are: ignore, warn, error.
1538
1539 You can fix this with '\''git rebase --edit-todo'\'' and then run '\''git rebase --continue'\''.
1540 Or you can abort the rebase with '\''git rebase --abort'\''.
1541 EOF
1542 tail -n11 expect >expect.2 &&
1543 head -n3 expect.2 >expect.3 &&
1544 tail -n7 expect.2 >>expect.3 &&
1545 test_config rebase.missingCommitsCheck error &&
1546 rebase_setup_and_clean missing-commit &&
1547 (
1548 set_fake_editor &&
1549 test_must_fail env FAKE_LINES="bad 1 2 3 4 5" \
1550 git rebase -i --root &&
1551 cp .git/rebase-merge/git-rebase-todo.backup orig &&
1552 test_must_fail env FAKE_LINES="2 3 4" \
1553 git rebase --edit-todo 2>actual &&
1108cea7 1554 test_cmp expect actual &&
5a5445d8 1555 test_must_fail git rebase --continue 2>actual &&
1108cea7 1556 test_cmp expect.2 actual &&
5a5445d8
AG
1557 test_must_fail git rebase --edit-todo &&
1558 cp orig .git/rebase-merge/git-rebase-todo &&
1559 test_must_fail env FAKE_LINES="1 2 3 4" \
1560 git rebase --edit-todo 2>actual &&
1108cea7 1561 test_cmp expect.3 actual &&
5a5445d8 1562 test_must_fail git rebase --continue 2>actual &&
1108cea7 1563 test_cmp expect.3 actual &&
5a5445d8
AG
1564 cp orig .git/rebase-merge/git-rebase-todo &&
1565 FAKE_LINES="1 2 3 4 drop 5" git rebase --edit-todo &&
1566 git rebase --continue 2>actual
1567 ) &&
1568 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
6789275d 1569 test_grep \
5a5445d8
AG
1570 "Successfully rebased and updated refs/heads/missing-commit" \
1571 actual
1572'
1573
1574test_expect_success 'rebase.missingCommitsCheck = error after resolving conflicts' '
1575 test_config rebase.missingCommitsCheck error &&
1576 (
1577 set_fake_editor &&
1578 FAKE_LINES="drop 1 break 2 3 4" git rebase -i A E
1579 ) &&
1580 git rebase --edit-todo &&
1581 test_must_fail git rebase --continue &&
1582 echo x >file1 &&
1583 git add file1 &&
1584 git rebase --continue
1585'
1586
1587test_expect_success 'rebase.missingCommitsCheck = error when editing for a second time' '
1588 test_config rebase.missingCommitsCheck error &&
1589 (
1590 set_fake_editor &&
1591 FAKE_LINES="1 break 2 3" git rebase -i A D &&
1592 cp .git/rebase-merge/git-rebase-todo todo &&
1593 test_must_fail env FAKE_LINES=2 git rebase --edit-todo &&
1594 GIT_SEQUENCE_EDITOR="cp todo" git rebase --edit-todo &&
1595 git rebase --continue
1596 )
1597'
1598
17959934
LB
1599test_expect_success 'respects rebase.abbreviateCommands with fixup, squash and exec' '
1600 rebase_setup_and_clean abbrevcmd &&
1601 test_commit "first" file1.txt "first line" first &&
1602 test_commit "second" file1.txt "another line" second &&
1603 test_commit "fixup! first" file2.txt "first line again" first_fixup &&
1604 test_commit "squash! second" file1.txt "another line here" second_squash &&
1605 cat >expected <<-EOF &&
1606 p $(git rev-list --abbrev-commit -1 first) first
1607 f $(git rev-list --abbrev-commit -1 first_fixup) fixup! first
1608 x git show HEAD
1609 p $(git rev-list --abbrev-commit -1 second) second
1610 s $(git rev-list --abbrev-commit -1 second_squash) squash! second
1611 x git show HEAD
1612 EOF
1613 git checkout abbrevcmd &&
17959934 1614 test_config rebase.abbreviateCommands true &&
b2dbacbd
PW
1615 (
1616 set_cat_todo_editor &&
1617 test_must_fail git rebase -i --exec "git show HEAD" \
9c8509a4 1618 --autosquash primary >actual
b2dbacbd 1619 ) &&
17959934
LB
1620 test_cmp expected actual
1621'
1622
804098bb
GR
1623test_expect_success 'static check of bad command' '
1624 rebase_setup_and_clean bad-cmd &&
b2dbacbd
PW
1625 (
1626 set_fake_editor &&
1627 test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \
804098bb 1628 git rebase -i --root 2>actual &&
6789275d 1629 test_grep "pickled $(git rev-list --oneline -1 primary~1)" \
b2dbacbd 1630 actual &&
6789275d 1631 test_grep "You can fix this with .git rebase --edit-todo.." \
b2dbacbd
PW
1632 actual &&
1633 FAKE_LINES="1 2 3 drop 4 5" git rebase --edit-todo
1634 ) &&
804098bb
GR
1635 git rebase --continue &&
1636 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1637 test C = $(git cat-file commit HEAD^ | sed -ne \$p)
1638'
1639
9645a087
AH
1640test_expect_success 'the first command cannot be a fixup' '
1641 rebase_setup_and_clean fixup-first &&
1642
1643 cat >orig <<-EOF &&
1644 fixup $(git log -1 --format="%h %s" B)
1645 pick $(git log -1 --format="%h %s" C)
1646 EOF
1647
1648 (
1649 set_replace_editor orig &&
1650 test_must_fail git rebase -i A 2>actual
1651 ) &&
1652 grep "cannot .fixup. without a previous commit" actual &&
1653 grep "You can fix this with .git rebase --edit-todo.." actual &&
1654 # verify that the todo list has not been truncated
1655 grep -v "^#" .git/rebase-merge/git-rebase-todo >actual &&
1656 test_cmp orig actual &&
1657
1658 test_must_fail git rebase --edit-todo 2>actual &&
1659 grep "cannot .fixup. without a previous commit" actual &&
1660 grep "You can fix this with .git rebase --edit-todo.." actual &&
1661 # verify that the todo list has not been truncated
1662 grep -v "^#" .git/rebase-merge/git-rebase-todo >actual &&
1663 test_cmp orig actual
1664'
1665
1db168ee
MM
1666test_expect_success 'tabs and spaces are accepted in the todolist' '
1667 rebase_setup_and_clean indented-comment &&
1668 write_script add-indent.sh <<-\EOF &&
1669 (
1670 # Turn single spaces into space/tab mix
1671 sed "1s/ / /g; 2s/ / /g; 3s/ / /g" "$1"
1672 printf "\n\t# comment\n #more\n\t # comment\n"
7966230b 1673 ) >"$1.new"
1db168ee
MM
1674 mv "$1.new" "$1"
1675 EOF
b2dbacbd
PW
1676 (
1677 test_set_editor "$(pwd)/add-indent.sh" &&
1678 git rebase -i HEAD^^^
1679 ) &&
1db168ee
MM
1680 test E = $(git cat-file commit HEAD | sed -ne \$p)
1681'
1682
804098bb
GR
1683test_expect_success 'static check of bad SHA-1' '
1684 rebase_setup_and_clean bad-sha &&
b2dbacbd
PW
1685 (
1686 set_fake_editor &&
1687 test_must_fail env FAKE_LINES="1 2 edit fakesha 3 4 5 #" \
1688 git rebase -i --root 2>actual &&
6789275d
JH
1689 test_grep "edit XXXXXXX False commit" actual &&
1690 test_grep "You can fix this with .git rebase --edit-todo.." \
b2dbacbd
PW
1691 actual &&
1692 FAKE_LINES="1 2 4 5 6" git rebase --edit-todo
1693 ) &&
804098bb
GR
1694 git rebase --continue &&
1695 test E = $(git cat-file commit HEAD | sed -ne \$p)
1696'
1697
39743cf5 1698test_expect_success 'editor saves as CR/LF' '
1db25aae
JS
1699 git checkout -b with-crlf &&
1700 write_script add-crs.sh <<-\EOF &&
1701 sed -e "s/\$/Q/" <"$1" | tr Q "\\015" >"$1".new &&
1702 mv -f "$1".new "$1"
1703 EOF
1704 (
1705 test_set_editor "$(pwd)/add-crs.sh" &&
1706 git rebase -i HEAD^
1707 )
1708'
1709
6672b9f9 1710test_expect_success 'rebase -i --gpg-sign=<key-id>' '
ed1e5282 1711 test_when_finished "test_might_fail git rebase --abort" &&
b2dbacbd
PW
1712 (
1713 set_fake_editor &&
1714 FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" \
1715 HEAD^ >out 2>err
1716 ) &&
6789275d 1717 test_grep "$SQ-S\"S I Gner\"$SQ" err
ed1e5282
JS
1718'
1719
1720test_expect_success 'rebase -i --gpg-sign=<key-id> overrides commit.gpgSign' '
1721 test_when_finished "test_might_fail git rebase --abort" &&
1722 test_config commit.gpgsign true &&
b2dbacbd
PW
1723 (
1724 set_fake_editor &&
1725 FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" \
1726 HEAD^ >out 2>err
1727 ) &&
6789275d 1728 test_grep "$SQ-S\"S I Gner\"$SQ" err
6672b9f9
JS
1729'
1730
ca3e1826
ES
1731test_expect_success 'valid author header after --root swap' '
1732 rebase_setup_and_clean author-header no-conflict-branch &&
4aa5ff94
PW
1733 git commit --amend --author="Au ${SQ}thor <author@example.com>" --no-edit &&
1734 git cat-file commit HEAD | grep ^author >expected &&
b2dbacbd
PW
1735 (
1736 set_fake_editor &&
1737 FAKE_LINES="5 1" git rebase -i --root
1738 ) &&
4aa5ff94
PW
1739 git cat-file commit HEAD^ | grep ^author >actual &&
1740 test_cmp expected actual
1741'
1742
1743test_expect_success 'valid author header when author contains single quote' '
1744 rebase_setup_and_clean author-header no-conflict-branch &&
4aa5ff94
PW
1745 git commit --amend --author="Au ${SQ}thor <author@example.com>" --no-edit &&
1746 git cat-file commit HEAD | grep ^author >expected &&
b2dbacbd
PW
1747 (
1748 set_fake_editor &&
1749 FAKE_LINES="2" git rebase -i HEAD~2
1750 ) &&
4aa5ff94
PW
1751 git cat-file commit HEAD | grep ^author >actual &&
1752 test_cmp expected actual
ca3e1826
ES
1753'
1754
4627bc77 1755test_expect_success 'post-commit hook is called' '
4627bc77 1756 >actual &&
bef805b7 1757 test_hook post-commit <<-\EOS &&
4627bc77
PW
1758 git rev-parse HEAD >>actual
1759 EOS
1760 (
1761 set_fake_editor &&
1762 FAKE_LINES="edit 4 1 reword 2 fixup 3" git rebase -i A E &&
1763 echo x>file3 &&
1764 git add file3 &&
1765 FAKE_COMMIT_MESSAGE=edited git rebase --continue
1766 ) &&
1767 git rev-parse HEAD@{5} HEAD@{4} HEAD@{3} HEAD@{2} HEAD@{1} HEAD \
1768 >expect &&
1769 test_cmp expect actual
1770'
1771
430b75f7
PW
1772test_expect_success 'correct error message for partial commit after empty pick' '
1773 test_when_finished "git rebase --abort" &&
1774 (
1775 set_fake_editor &&
1776 FAKE_LINES="2 1 1" &&
1777 export FAKE_LINES &&
1778 test_must_fail git rebase -i A D
1779 ) &&
1780 echo x >file1 &&
1781 test_must_fail git commit file1 2>err &&
6789275d 1782 test_grep "cannot do a partial commit during a rebase." err
430b75f7
PW
1783'
1784
1785test_expect_success 'correct error message for commit --amend after empty pick' '
1786 test_when_finished "git rebase --abort" &&
1787 (
1788 set_fake_editor &&
1789 FAKE_LINES="1 1" &&
1790 export FAKE_LINES &&
1791 test_must_fail git rebase -i A D
1792 ) &&
1793 echo x>file1 &&
1794 test_must_fail git commit -a --amend 2>err &&
6789275d 1795 test_grep "middle of a rebase -- cannot amend." err
430b75f7
PW
1796'
1797
5da69c0d
AK
1798test_expect_success 'todo has correct onto hash' '
1799 GIT_SEQUENCE_EDITOR=cat git rebase -i no-conflict-branch~4 no-conflict-branch >actual &&
1800 onto=$(git rev-parse --short HEAD~4) &&
6789275d 1801 test_grep "^# Rebase ..* onto $onto" actual
5da69c0d
AK
1802'
1803
e100bea4 1804test_expect_success 'ORIG_HEAD is updated correctly' '
9c8509a4 1805 test_when_finished "git checkout primary && git branch -D test-orig-head" &&
e100bea4
PW
1806 git checkout -b test-orig-head A &&
1807 git commit --allow-empty -m A1 &&
1808 git commit --allow-empty -m A2 &&
1809 git commit --allow-empty -m A3 &&
1810 git commit --allow-empty -m A4 &&
9c8509a4 1811 git rebase primary &&
e100bea4
PW
1812 test_cmp_rev ORIG_HEAD test-orig-head@{1}
1813'
1814
900b50c2
DS
1815test_expect_success '--update-refs adds label and update-ref commands' '
1816 git checkout -b update-refs no-conflict-branch &&
1817 git branch -f base HEAD~4 &&
1818 git branch -f first HEAD~3 &&
1819 git branch -f second HEAD~3 &&
1820 git branch -f third HEAD~1 &&
1821 git commit --allow-empty --fixup=third &&
1822 git branch -f is-not-reordered &&
1823 git commit --allow-empty --fixup=HEAD~4 &&
1824 git branch -f shared-tip &&
1825 (
1826 set_cat_todo_editor &&
1827
1828 cat >expect <<-EOF &&
1829 pick $(git log -1 --format=%h J) J
1830 fixup $(git log -1 --format=%h update-refs) fixup! J # empty
1831 update-ref refs/heads/second
1832 update-ref refs/heads/first
1833 pick $(git log -1 --format=%h K) K
1834 pick $(git log -1 --format=%h L) L
1835 fixup $(git log -1 --format=%h is-not-reordered) fixup! L # empty
1836 update-ref refs/heads/third
1837 pick $(git log -1 --format=%h M) M
1838 update-ref refs/heads/no-conflict-branch
1839 update-ref refs/heads/is-not-reordered
1840 update-ref refs/heads/shared-tip
1841 EOF
1842
1843 test_must_fail git rebase -i --autosquash --update-refs primary >todo &&
3113feda
DS
1844 test_cmp expect todo &&
1845
1846 test_must_fail git -c rebase.autosquash=true \
1847 -c rebase.updaterefs=true \
1848 rebase -i primary >todo &&
1849
900b50c2
DS
1850 test_cmp expect todo
1851 )
1852'
1853
1854test_expect_success '--update-refs adds commands with --rebase-merges' '
1855 git checkout -b update-refs-with-merge no-conflict-branch &&
1856 git branch -f base HEAD~4 &&
1857 git branch -f first HEAD~3 &&
1858 git branch -f second HEAD~3 &&
1859 git branch -f third HEAD~1 &&
1860 git merge -m merge branch2 &&
1861 git branch -f merge-branch &&
1862 git commit --fixup=third --allow-empty &&
1863 (
1864 set_cat_todo_editor &&
1865
1866 cat >expect <<-EOF &&
1867 label onto
1868 reset onto
1869 pick $(git log -1 --format=%h branch2~1) F
1870 pick $(git log -1 --format=%h branch2) I
1871 update-ref refs/heads/branch2
1872 label merge
1873 reset onto
1874 pick $(git log -1 --format=%h refs/heads/second) J
1875 update-ref refs/heads/second
1876 update-ref refs/heads/first
1877 pick $(git log -1 --format=%h refs/heads/third~1) K
1878 pick $(git log -1 --format=%h refs/heads/third) L
1879 fixup $(git log -1 --format=%h update-refs-with-merge) fixup! L # empty
1880 update-ref refs/heads/third
1881 pick $(git log -1 --format=%h HEAD~2) M
1882 update-ref refs/heads/no-conflict-branch
1883 merge -C $(git log -1 --format=%h HEAD~1) merge # merge
1884 update-ref refs/heads/merge-branch
1885 EOF
1886
1887 test_must_fail git rebase -i --autosquash \
1888 --rebase-merges=rebase-cousins \
1889 --update-refs primary >todo &&
1890
3113feda
DS
1891 test_cmp expect todo &&
1892
1893 test_must_fail git -c rebase.autosquash=true \
1894 -c rebase.updaterefs=true \
1895 rebase -i \
1896 --rebase-merges=rebase-cousins \
1897 primary >todo &&
1898
900b50c2
DS
1899 test_cmp expect todo
1900 )
1901'
1902
89fc0b53
DS
1903test_expect_success '--update-refs updates refs correctly' '
1904 git checkout -B update-refs no-conflict-branch &&
1905 git branch -f base HEAD~4 &&
1906 git branch -f first HEAD~3 &&
1907 git branch -f second HEAD~3 &&
1908 git branch -f third HEAD~1 &&
1909 test_commit extra2 fileX &&
1910 git commit --amend --fixup=L &&
1911
4611884e 1912 git rebase -i --autosquash --update-refs primary 2>err &&
89fc0b53
DS
1913
1914 test_cmp_rev HEAD~3 refs/heads/first &&
1915 test_cmp_rev HEAD~3 refs/heads/second &&
1916 test_cmp_rev HEAD~1 refs/heads/third &&
4611884e
DS
1917 test_cmp_rev HEAD refs/heads/no-conflict-branch &&
1918
1919 cat >expect <<-\EOF &&
1920 Successfully rebased and updated refs/heads/update-refs.
1921 Updated the following refs with --update-refs:
1922 refs/heads/first
1923 refs/heads/no-conflict-branch
1924 refs/heads/second
1925 refs/heads/third
1926 EOF
1927
1928 # Clear "Rebasing (X/Y)" progress lines and drop leading tabs.
1929 sed -e "s/Rebasing.*Successfully/Successfully/g" -e "s/^\t//g" \
1930 <err >err.trimmed &&
1931 test_cmp expect err.trimmed
89fc0b53
DS
1932'
1933
b3b1a21d
DS
1934test_expect_success 'respect user edits to update-ref steps' '
1935 git checkout -B update-refs-break no-conflict-branch &&
1936 git branch -f base HEAD~4 &&
1937 git branch -f first HEAD~3 &&
1938 git branch -f second HEAD~3 &&
1939 git branch -f third HEAD~1 &&
1940 git branch -f unseen base &&
1941
1942 # First, we will add breaks to the expected todo file
1943 cat >fake-todo-1 <<-EOF &&
1944 pick $(git rev-parse HEAD~3)
1945 break
1946 update-ref refs/heads/second
1947 update-ref refs/heads/first
1948
1949 pick $(git rev-parse HEAD~2)
1950 pick $(git rev-parse HEAD~1)
1951 update-ref refs/heads/third
1952
1953 pick $(git rev-parse HEAD)
1954 update-ref refs/heads/no-conflict-branch
1955 EOF
1956
1957 # Second, we will drop some update-refs commands (and move one)
1958 cat >fake-todo-2 <<-EOF &&
1959 update-ref refs/heads/second
1960
1961 pick $(git rev-parse HEAD~2)
1962 update-ref refs/heads/third
1963 pick $(git rev-parse HEAD~1)
1964 break
1965
1966 pick $(git rev-parse HEAD)
1967 EOF
1968
1969 # Third, we will:
1970 # * insert a new one (new-branch),
1971 # * re-add an old one (first), and
1972 # * add a second instance of a previously-stored one (second)
1973 cat >fake-todo-3 <<-EOF &&
1974 update-ref refs/heads/unseen
1975 update-ref refs/heads/new-branch
1976 pick $(git rev-parse HEAD)
1977 update-ref refs/heads/first
1978 update-ref refs/heads/second
1979 EOF
1980
1981 (
1982 set_replace_editor fake-todo-1 &&
1983 git rebase -i --update-refs primary &&
1984
1985 # These branches are currently locked.
1986 for b in first second third no-conflict-branch
1987 do
1988 test_must_fail git branch -f $b base || return 1
1989 done &&
1990
1991 set_replace_editor fake-todo-2 &&
1992 git rebase --edit-todo &&
1993
1994 # These branches are currently locked.
1995 for b in second third
1996 do
1997 test_must_fail git branch -f $b base || return 1
1998 done &&
1999
2000 # These branches are currently unlocked for checkout.
2001 for b in first no-conflict-branch
2002 do
2003 git worktree add wt-$b $b &&
2004 git worktree remove wt-$b || return 1
2005 done &&
2006
2007 git rebase --continue &&
2008
2009 set_replace_editor fake-todo-3 &&
2010 git rebase --edit-todo &&
2011
2012 # These branches are currently locked.
2013 for b in second third first unseen
2014 do
2015 test_must_fail git branch -f $b base || return 1
2016 done &&
2017
2018 # These branches are currently unlocked for checkout.
2019 for b in no-conflict-branch
2020 do
2021 git worktree add wt-$b $b &&
2022 git worktree remove wt-$b || return 1
2023 done &&
2024
2025 git rebase --continue
2026 ) &&
2027
2028 test_cmp_rev HEAD~2 refs/heads/third &&
2029 test_cmp_rev HEAD~1 refs/heads/unseen &&
2030 test_cmp_rev HEAD~1 refs/heads/new-branch &&
2031 test_cmp_rev HEAD refs/heads/first &&
2032 test_cmp_rev HEAD refs/heads/second &&
2033 test_cmp_rev HEAD refs/heads/no-conflict-branch
2034'
2035
44da9e08
VD
2036test_expect_success '--update-refs: all update-ref lines removed' '
2037 git checkout -b test-refs-not-removed no-conflict-branch &&
2038 git branch -f base HEAD~4 &&
2039 git branch -f first HEAD~3 &&
2040 git branch -f second HEAD~3 &&
2041 git branch -f third HEAD~1 &&
2042 git branch -f tip &&
2043
2044 test_commit test-refs-not-removed &&
2045 git commit --amend --fixup first &&
2046
2047 git rev-parse first second third tip no-conflict-branch >expect-oids &&
2048
2049 (
2050 set_cat_todo_editor &&
2051 test_must_fail git rebase -i --update-refs base >todo.raw &&
2052 sed -e "/^update-ref/d" <todo.raw >todo
2053 ) &&
2054 (
2055 set_replace_editor todo &&
2056 git rebase -i --update-refs base
2057 ) &&
2058
2059 # Ensure refs are not deleted and their OIDs have not changed
2060 git rev-parse first second third tip no-conflict-branch >actual-oids &&
2061 test_cmp expect-oids actual-oids
2062'
2063
2064test_expect_success '--update-refs: all update-ref lines removed, then some re-added' '
2065 git checkout -b test-refs-not-removed2 no-conflict-branch &&
2066 git branch -f base HEAD~4 &&
2067 git branch -f first HEAD~3 &&
2068 git branch -f second HEAD~3 &&
2069 git branch -f third HEAD~1 &&
2070 git branch -f tip &&
2071
2072 test_commit test-refs-not-removed2 &&
2073 git commit --amend --fixup first &&
2074
2075 git rev-parse first second third >expect-oids &&
2076
2077 (
2078 set_cat_todo_editor &&
2079 test_must_fail git rebase -i \
2080 --autosquash --update-refs \
2081 base >todo.raw &&
2082 sed -e "/^update-ref/d" <todo.raw >todo
2083 ) &&
2084
2085 # Add a break to the end of the todo so we can edit later
2086 echo "break" >>todo &&
2087
2088 (
2089 set_replace_editor todo &&
2090 git rebase -i --autosquash --update-refs base &&
2091 echo "update-ref refs/heads/tip" >todo &&
2092 git rebase --edit-todo &&
2093 git rebase --continue
2094 ) &&
2095
2096 # Ensure first/second/third are unchanged, but tip is updated
2097 git rev-parse first second third >actual-oids &&
2098 test_cmp expect-oids actual-oids &&
2099 test_cmp_rev HEAD tip
2100'
2101
2102test_expect_success '--update-refs: --edit-todo with no update-ref lines' '
2103 git checkout -b test-refs-not-removed3 no-conflict-branch &&
2104 git branch -f base HEAD~4 &&
2105 git branch -f first HEAD~3 &&
2106 git branch -f second HEAD~3 &&
2107 git branch -f third HEAD~1 &&
2108 git branch -f tip &&
2109
2110 test_commit test-refs-not-removed3 &&
2111 git commit --amend --fixup first &&
2112
2113 git rev-parse first second third tip no-conflict-branch >expect-oids &&
2114
2115 (
2116 set_cat_todo_editor &&
2117 test_must_fail git rebase -i \
2118 --autosquash --update-refs \
2119 base >todo.raw &&
2120 sed -e "/^update-ref/d" <todo.raw >todo
2121 ) &&
2122
2123 # Add a break to the beginning of the todo so we can resume with no
2124 # update-ref lines
2125 echo "break" >todo.new &&
2126 cat todo >>todo.new &&
2127
2128 (
2129 set_replace_editor todo.new &&
2130 git rebase -i --autosquash --update-refs base &&
2131
2132 # Make no changes when editing so update-refs is still empty
2133 cat todo >todo.new &&
2134 git rebase --edit-todo &&
2135 git rebase --continue
2136 ) &&
2137
2138 # Ensure refs are not deleted and their OIDs have not changed
2139 git rev-parse first second third tip no-conflict-branch >actual-oids &&
2140 test_cmp expect-oids actual-oids
2141'
2142
b3b1a21d 2143test_expect_success '--update-refs: check failed ref update' '
16b3880d 2144 test_when_finished "test_might_fail git rebase --abort" &&
b3b1a21d
DS
2145 git checkout -B update-refs-error no-conflict-branch &&
2146 git branch -f base HEAD~4 &&
2147 git branch -f first HEAD~3 &&
2148 git branch -f second HEAD~2 &&
2149 git branch -f third HEAD~1 &&
2150
2151 cat >fake-todo <<-EOF &&
2152 pick $(git rev-parse HEAD~3)
2153 break
2154 update-ref refs/heads/first
2155
2156 pick $(git rev-parse HEAD~2)
2157 update-ref refs/heads/second
2158
2159 pick $(git rev-parse HEAD~1)
2160 update-ref refs/heads/third
2161
2162 pick $(git rev-parse HEAD)
2163 update-ref refs/heads/no-conflict-branch
2164 EOF
2165
2166 (
2167 set_replace_editor fake-todo &&
2168 git rebase -i --update-refs base
2169 ) &&
2170
2171 # At this point, the values of first, second, and third are
2172 # recorded in the update-refs file. We will force-update the
2173 # "second" ref, but "git branch -f" will not work because of
2174 # the lock in the update-refs file.
1c6667cb 2175 git update-ref refs/heads/second third &&
b3b1a21d 2176
4611884e
DS
2177 test_must_fail git rebase --continue 2>err &&
2178 grep "update_ref failed for ref '\''refs/heads/second'\''" err &&
2179
2180 cat >expect <<-\EOF &&
2181 Updated the following refs with --update-refs:
2182 refs/heads/first
2183 refs/heads/no-conflict-branch
2184 refs/heads/third
2185 Failed to update the following refs with --update-refs:
2186 refs/heads/second
2187 EOF
2188
2189 # Clear "Rebasing (X/Y)" progress lines and drop leading tabs.
2190 tail -n 6 err >err.last &&
2191 sed -e "s/Rebasing.*Successfully/Successfully/g" -e "s/^\t//g" \
2192 <err.last >err.trimmed &&
2193 test_cmp expect err.trimmed
b3b1a21d
DS
2194'
2195
16b3880d
PW
2196test_expect_success 'bad labels and refs rejected when parsing todo list' '
2197 test_when_finished "test_might_fail git rebase --abort" &&
2198 cat >todo <<-\EOF &&
2199 exec >execed
2200 label #
2201 label :invalid
2202 update-ref :bad
2203 update-ref topic
2204 EOF
2205 rm -f execed &&
2206 (
2207 set_replace_editor todo &&
2208 test_must_fail git rebase -i HEAD 2>err
2209 ) &&
2210 grep "'\''#'\'' is not a valid label" err &&
2211 grep "'\'':invalid'\'' is not a valid label" err &&
2212 grep "'\'':bad'\'' is not a valid refname" err &&
2213 grep "update-ref requires a fully qualified refname e.g. refs/heads/topic" \
2214 err &&
2215 test_path_is_missing execed
2216'
2217
6a619ca0
PW
2218# This must be the last test in this file
2219test_expect_success '$EDITOR and friends are unchanged' '
2220 test_editor_unchanged
2221'
2222
1b1dce4b 2223test_done