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