rebase --keep-empty -i: add test
[git.git] / t / t3404-rebase-interactive.sh
blob9848524aeea034fce797babe4dccb280b2ec2274
1 #!/bin/sh
3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description='git rebase interactive
8 This test runs git rebase "interactively", by faking an edit, and verifies
9 that the result still makes sense.
11 Initial setup:
13 one - two - three - four (conflict-branch)
15 A - B - C - D - E (master)
16 | \
17 | F - G - H (branch1)
18 | \
19 |\ I (branch2)
20 | \
21 | J - K - L - M (no-conflict-branch)
23 N - O - P (no-ff-branch)
25 where A, B, D and G all touch file1, and one, two, three, four all
26 touch file "conflict".
28 . ./test-lib.sh
30 . "$TEST_DIRECTORY"/lib-rebase.sh
32 # WARNING: Modifications to the initial repository can change the SHA ID used
33 # in the expect2 file for the 'stop on conflicting pick' test.
35 test_expect_success 'setup' '
36 test_commit A file1 &&
37 test_commit B file1 &&
38 test_commit C file2 &&
39 test_commit D file1 &&
40 test_commit E file3 &&
41 git checkout -b branch1 A &&
42 test_commit F file4 &&
43 test_commit G file1 &&
44 test_commit H file5 &&
45 git checkout -b branch2 F &&
46 test_commit I file6 &&
47 git checkout -b conflict-branch A &&
48 test_commit one conflict &&
49 test_commit two conflict &&
50 test_commit three conflict &&
51 test_commit four conflict &&
52 git checkout -b no-conflict-branch A &&
53 test_commit J fileJ &&
54 test_commit K fileK &&
55 test_commit L fileL &&
56 test_commit M fileM &&
57 git checkout -b no-ff-branch A &&
58 test_commit N fileN &&
59 test_commit O fileO &&
60 test_commit P fileP
63 # "exec" commands are ran with the user shell by default, but this may
64 # be non-POSIX. For example, if SHELL=zsh then ">file" doesn't work
65 # to create a file. Unseting SHELL avoids such non-portable behavior
66 # in tests. It must be exported for it to take effect where needed.
67 SHELL=
68 export SHELL
70 test_expect_success 'rebase --keep-empty' '
71 git checkout -b emptybranch master &&
72 git commit --allow-empty -m "empty" &&
73 git rebase --keep-empty -i HEAD~2 &&
74 git log --oneline >actual &&
75 test_line_count = 6 actual
78 test_expect_success 'rebase -i with the exec command' '
79 git checkout master &&
81 set_fake_editor &&
82 FAKE_LINES="1 exec_>touch-one
83 2 exec_>touch-two exec_false exec_>touch-three
84 3 4 exec_>\"touch-file__name_with_spaces\";_>touch-after-semicolon 5" &&
85 export FAKE_LINES &&
86 test_must_fail git rebase -i A
87 ) &&
88 test_path_is_file touch-one &&
89 test_path_is_file touch-two &&
90 test_path_is_missing touch-three " (should have stopped before)" &&
91 test_cmp_rev C HEAD &&
92 git rebase --continue &&
93 test_path_is_file touch-three &&
94 test_path_is_file "touch-file name with spaces" &&
95 test_path_is_file touch-after-semicolon &&
96 test_cmp_rev master HEAD &&
97 rm -f touch-*
100 test_expect_success 'rebase -i with the exec command runs from tree root' '
101 git checkout master &&
102 mkdir subdir && (cd subdir &&
103 set_fake_editor &&
104 FAKE_LINES="1 exec_>touch-subdir" \
105 git rebase -i HEAD^
106 ) &&
107 test_path_is_file touch-subdir &&
108 rm -fr subdir
111 test_expect_success 'rebase -i with the exec command checks tree cleanness' '
112 git checkout master &&
114 set_fake_editor &&
115 FAKE_LINES="exec_echo_foo_>file1 1" &&
116 export FAKE_LINES &&
117 test_must_fail git rebase -i HEAD^
118 ) &&
119 test_cmp_rev master^ HEAD &&
120 git reset --hard &&
121 git rebase --continue
124 test_expect_success 'rebase -i with exec of inexistent command' '
125 git checkout master &&
126 test_when_finished "git rebase --abort" &&
128 set_fake_editor &&
129 FAKE_LINES="exec_this-command-does-not-exist 1" &&
130 export FAKE_LINES &&
131 test_must_fail git rebase -i HEAD^ >actual 2>&1
132 ) &&
133 ! grep "Maybe git-rebase is broken" actual
136 test_expect_success 'no changes are a nop' '
137 git checkout branch2 &&
138 set_fake_editor &&
139 git rebase -i F &&
140 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
141 test $(git rev-parse I) = $(git rev-parse HEAD)
144 test_expect_success 'test the [branch] option' '
145 git checkout -b dead-end &&
146 git rm file6 &&
147 git commit -m "stop here" &&
148 set_fake_editor &&
149 git rebase -i F branch2 &&
150 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
151 test $(git rev-parse I) = $(git rev-parse branch2) &&
152 test $(git rev-parse I) = $(git rev-parse HEAD)
155 test_expect_success 'test --onto <branch>' '
156 git checkout -b test-onto branch2 &&
157 set_fake_editor &&
158 git rebase -i --onto branch1 F &&
159 test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" &&
160 test $(git rev-parse HEAD^) = $(git rev-parse branch1) &&
161 test $(git rev-parse I) = $(git rev-parse branch2)
164 test_expect_success 'rebase on top of a non-conflicting commit' '
165 git checkout branch1 &&
166 git tag original-branch1 &&
167 set_fake_editor &&
168 git rebase -i branch2 &&
169 test file6 = $(git diff --name-only original-branch1) &&
170 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
171 test $(git rev-parse I) = $(git rev-parse branch2) &&
172 test $(git rev-parse I) = $(git rev-parse HEAD~2)
175 test_expect_success 'reflog for the branch shows state before rebase' '
176 test $(git rev-parse branch1@{1}) = $(git rev-parse original-branch1)
179 test_expect_success 'exchange two commits' '
180 set_fake_editor &&
181 FAKE_LINES="2 1" git rebase -i HEAD~2 &&
182 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
183 test G = $(git cat-file commit HEAD | sed -ne \$p)
186 cat > expect << EOF
187 diff --git a/file1 b/file1
188 index f70f10e..fd79235 100644
189 --- a/file1
190 +++ b/file1
191 @@ -1 +1 @@
196 cat > expect2 << EOF
197 <<<<<<< HEAD
199 =======
201 >>>>>>> 5d18e54... G
204 test_expect_success 'stop on conflicting pick' '
205 git tag new-branch1 &&
206 set_fake_editor &&
207 test_must_fail git rebase -i master &&
208 test "$(git rev-parse HEAD~3)" = "$(git rev-parse master)" &&
209 test_cmp expect .git/rebase-merge/patch &&
210 test_cmp expect2 file1 &&
211 test "$(git diff --name-status |
212 sed -n -e "/^U/s/^U[^a-z]*//p")" = file1 &&
213 test 4 = $(grep -v "^#" < .git/rebase-merge/done | wc -l) &&
214 test 0 = $(grep -c "^[^#]" < .git/rebase-merge/git-rebase-todo)
217 test_expect_success 'abort' '
218 git rebase --abort &&
219 test $(git rev-parse new-branch1) = $(git rev-parse HEAD) &&
220 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
221 test_path_is_missing .git/rebase-merge
224 test_expect_success 'abort with error when new base cannot be checked out' '
225 git rm --cached file1 &&
226 git commit -m "remove file in base" &&
227 set_fake_editor &&
228 test_must_fail git rebase -i master > output 2>&1 &&
229 grep "The following untracked working tree files would be overwritten by checkout:" \
230 output &&
231 grep "file1" output &&
232 test_path_is_missing .git/rebase-merge &&
233 git reset --hard HEAD^
236 test_expect_success 'retain authorship' '
237 echo A > file7 &&
238 git add file7 &&
239 test_tick &&
240 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
241 git tag twerp &&
242 set_fake_editor &&
243 git rebase -i --onto master HEAD^ &&
244 git show HEAD | grep "^Author: Twerp Snog"
247 test_expect_success 'squash' '
248 git reset --hard twerp &&
249 echo B > file7 &&
250 test_tick &&
251 GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 &&
252 echo "******************************" &&
253 set_fake_editor &&
254 FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \
255 git rebase -i --onto master HEAD~2 &&
256 test B = $(cat file7) &&
257 test $(git rev-parse HEAD^) = $(git rev-parse master)
260 test_expect_success 'retain authorship when squashing' '
261 git show HEAD | grep "^Author: Twerp Snog"
264 test_expect_success '-p handles "no changes" gracefully' '
265 HEAD=$(git rev-parse HEAD) &&
266 set_fake_editor &&
267 git rebase -i -p HEAD^ &&
268 git update-index --refresh &&
269 git diff-files --quiet &&
270 git diff-index --quiet --cached HEAD -- &&
271 test $HEAD = $(git rev-parse HEAD)
274 test_expect_failure 'exchange two commits with -p' '
275 git checkout H &&
276 set_fake_editor &&
277 FAKE_LINES="2 1" git rebase -i -p HEAD~2 &&
278 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
279 test G = $(git cat-file commit HEAD | sed -ne \$p)
282 test_expect_success 'preserve merges with -p' '
283 git checkout -b to-be-preserved master^ &&
284 : > unrelated-file &&
285 git add unrelated-file &&
286 test_tick &&
287 git commit -m "unrelated" &&
288 git checkout -b another-branch master &&
289 echo B > file1 &&
290 test_tick &&
291 git commit -m J file1 &&
292 test_tick &&
293 git merge to-be-preserved &&
294 echo C > file1 &&
295 test_tick &&
296 git commit -m K file1 &&
297 echo D > file1 &&
298 test_tick &&
299 git commit -m L1 file1 &&
300 git checkout HEAD^ &&
301 echo 1 > unrelated-file &&
302 test_tick &&
303 git commit -m L2 unrelated-file &&
304 test_tick &&
305 git merge another-branch &&
306 echo E > file1 &&
307 test_tick &&
308 git commit -m M file1 &&
309 git checkout -b to-be-rebased &&
310 test_tick &&
311 set_fake_editor &&
312 git rebase -i -p --onto branch1 master &&
313 git update-index --refresh &&
314 git diff-files --quiet &&
315 git diff-index --quiet --cached HEAD -- &&
316 test $(git rev-parse HEAD~6) = $(git rev-parse branch1) &&
317 test $(git rev-parse HEAD~4^2) = $(git rev-parse to-be-preserved) &&
318 test $(git rev-parse HEAD^^2^) = $(git rev-parse HEAD^^^) &&
319 test $(git show HEAD~5:file1) = B &&
320 test $(git show HEAD~3:file1) = C &&
321 test $(git show HEAD:file1) = E &&
322 test $(git show HEAD:unrelated-file) = 1
325 test_expect_success 'edit ancestor with -p' '
326 set_fake_editor &&
327 FAKE_LINES="1 2 edit 3 4" git rebase -i -p HEAD~3 &&
328 echo 2 > unrelated-file &&
329 test_tick &&
330 git commit -m L2-modified --amend unrelated-file &&
331 git rebase --continue &&
332 git update-index --refresh &&
333 git diff-files --quiet &&
334 git diff-index --quiet --cached HEAD -- &&
335 test $(git show HEAD:unrelated-file) = 2
338 test_expect_success '--continue tries to commit' '
339 test_tick &&
340 set_fake_editor &&
341 test_must_fail git rebase -i --onto new-branch1 HEAD^ &&
342 echo resolved > file1 &&
343 git add file1 &&
344 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
345 test $(git rev-parse HEAD^) = $(git rev-parse new-branch1) &&
346 git show HEAD | grep chouette
349 test_expect_success 'verbose flag is heeded, even after --continue' '
350 git reset --hard master@{1} &&
351 test_tick &&
352 set_fake_editor &&
353 test_must_fail git rebase -v -i --onto new-branch1 HEAD^ &&
354 echo resolved > file1 &&
355 git add file1 &&
356 git rebase --continue > output &&
357 grep "^ file1 | 2 +-$" output
360 test_expect_success 'multi-squash only fires up editor once' '
361 base=$(git rev-parse HEAD~4) &&
362 set_fake_editor &&
363 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 squash 2 squash 3 squash 4" \
364 EXPECT_HEADER_COUNT=4 \
365 git rebase -i $base &&
366 test $base = $(git rev-parse HEAD^) &&
367 test 1 = $(git show | grep ONCE | wc -l)
370 test_expect_success 'multi-fixup does not fire up editor' '
371 git checkout -b multi-fixup E &&
372 base=$(git rev-parse HEAD~4) &&
373 set_fake_editor &&
374 FAKE_COMMIT_AMEND="NEVER" FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \
375 git rebase -i $base &&
376 test $base = $(git rev-parse HEAD^) &&
377 test 0 = $(git show | grep NEVER | wc -l) &&
378 git checkout to-be-rebased &&
379 git branch -D multi-fixup
382 test_expect_success 'commit message used after conflict' '
383 git checkout -b conflict-fixup conflict-branch &&
384 base=$(git rev-parse HEAD~4) &&
385 set_fake_editor &&
387 FAKE_LINES="1 fixup 3 fixup 4" &&
388 export FAKE_LINES &&
389 test_must_fail git rebase -i $base
390 ) &&
391 echo three > conflict &&
392 git add conflict &&
393 FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \
394 git rebase --continue &&
395 test $base = $(git rev-parse HEAD^) &&
396 test 1 = $(git show | grep ONCE | wc -l) &&
397 git checkout to-be-rebased &&
398 git branch -D conflict-fixup
401 test_expect_success 'commit message retained after conflict' '
402 git checkout -b conflict-squash conflict-branch &&
403 base=$(git rev-parse HEAD~4) &&
404 set_fake_editor &&
406 FAKE_LINES="1 fixup 3 squash 4" &&
407 export FAKE_LINES &&
408 test_must_fail git rebase -i $base
409 ) &&
410 echo three > conflict &&
411 git add conflict &&
412 FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \
413 git rebase --continue &&
414 test $base = $(git rev-parse HEAD^) &&
415 test 2 = $(git show | grep TWICE | wc -l) &&
416 git checkout to-be-rebased &&
417 git branch -D conflict-squash
420 cat > expect-squash-fixup << EOF
425 ONCE
428 test_expect_success 'squash and fixup generate correct log messages' '
429 git checkout -b squash-fixup E &&
430 base=$(git rev-parse HEAD~4) &&
431 set_fake_editor &&
432 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 fixup 2 squash 3 fixup 4" \
433 EXPECT_HEADER_COUNT=4 \
434 git rebase -i $base &&
435 git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup &&
436 test_cmp expect-squash-fixup actual-squash-fixup &&
437 git checkout to-be-rebased &&
438 git branch -D squash-fixup
441 test_expect_success 'squash ignores comments' '
442 git checkout -b skip-comments E &&
443 base=$(git rev-parse HEAD~4) &&
444 set_fake_editor &&
445 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \
446 EXPECT_HEADER_COUNT=4 \
447 git rebase -i $base &&
448 test $base = $(git rev-parse HEAD^) &&
449 test 1 = $(git show | grep ONCE | wc -l) &&
450 git checkout to-be-rebased &&
451 git branch -D skip-comments
454 test_expect_success 'squash ignores blank lines' '
455 git checkout -b skip-blank-lines E &&
456 base=$(git rev-parse HEAD~4) &&
457 set_fake_editor &&
458 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \
459 EXPECT_HEADER_COUNT=4 \
460 git rebase -i $base &&
461 test $base = $(git rev-parse HEAD^) &&
462 test 1 = $(git show | grep ONCE | wc -l) &&
463 git checkout to-be-rebased &&
464 git branch -D skip-blank-lines
467 test_expect_success 'squash works as expected' '
468 git checkout -b squash-works no-conflict-branch &&
469 one=$(git rev-parse HEAD~3) &&
470 set_fake_editor &&
471 FAKE_LINES="1 squash 3 2" EXPECT_HEADER_COUNT=2 \
472 git rebase -i HEAD~3 &&
473 test $one = $(git rev-parse HEAD~2)
476 test_expect_success 'interrupted squash works as expected' '
477 git checkout -b interrupted-squash conflict-branch &&
478 one=$(git rev-parse HEAD~3) &&
479 set_fake_editor &&
481 FAKE_LINES="1 squash 3 2" &&
482 export FAKE_LINES &&
483 test_must_fail git rebase -i HEAD~3
484 ) &&
485 (echo one; echo two; echo four) > conflict &&
486 git add conflict &&
487 test_must_fail git rebase --continue &&
488 echo resolved > conflict &&
489 git add conflict &&
490 git rebase --continue &&
491 test $one = $(git rev-parse HEAD~2)
494 test_expect_success 'interrupted squash works as expected (case 2)' '
495 git checkout -b interrupted-squash2 conflict-branch &&
496 one=$(git rev-parse HEAD~3) &&
497 set_fake_editor &&
499 FAKE_LINES="3 squash 1 2" &&
500 export FAKE_LINES &&
501 test_must_fail git rebase -i HEAD~3
502 ) &&
503 (echo one; echo four) > conflict &&
504 git add conflict &&
505 test_must_fail git rebase --continue &&
506 (echo one; echo two; echo four) > conflict &&
507 git add conflict &&
508 test_must_fail git rebase --continue &&
509 echo resolved > conflict &&
510 git add conflict &&
511 git rebase --continue &&
512 test $one = $(git rev-parse HEAD~2)
515 test_expect_success '--continue tries to commit, even for "edit"' '
516 echo unrelated > file7 &&
517 git add file7 &&
518 test_tick &&
519 git commit -m "unrelated change" &&
520 parent=$(git rev-parse HEAD^) &&
521 test_tick &&
522 set_fake_editor &&
523 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
524 echo edited > file7 &&
525 git add file7 &&
526 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
527 test edited = $(git show HEAD:file7) &&
528 git show HEAD | grep chouette &&
529 test $parent = $(git rev-parse HEAD^)
532 test_expect_success 'aborted --continue does not squash commits after "edit"' '
533 old=$(git rev-parse HEAD) &&
534 test_tick &&
535 set_fake_editor &&
536 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
537 echo "edited again" > file7 &&
538 git add file7 &&
540 FAKE_COMMIT_MESSAGE=" " &&
541 export FAKE_COMMIT_MESSAGE &&
542 test_must_fail git rebase --continue
543 ) &&
544 test $old = $(git rev-parse HEAD) &&
545 git rebase --abort
548 test_expect_success 'auto-amend only edited commits after "edit"' '
549 test_tick &&
550 set_fake_editor &&
551 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
552 echo "edited again" > file7 &&
553 git add file7 &&
554 FAKE_COMMIT_MESSAGE="edited file7 again" git commit &&
555 echo "and again" > file7 &&
556 git add file7 &&
557 test_tick &&
559 FAKE_COMMIT_MESSAGE="and again" &&
560 export FAKE_COMMIT_MESSAGE &&
561 test_must_fail git rebase --continue
562 ) &&
563 git rebase --abort
566 test_expect_success 'clean error after failed "exec"' '
567 test_tick &&
568 test_when_finished "git rebase --abort || :" &&
569 set_fake_editor &&
571 FAKE_LINES="1 exec_false" &&
572 export FAKE_LINES &&
573 test_must_fail git rebase -i HEAD^
574 ) &&
575 echo "edited again" > file7 &&
576 git add file7 &&
577 test_must_fail git rebase --continue 2>error &&
578 grep "You have staged changes in your working tree." error
581 test_expect_success 'rebase a detached HEAD' '
582 grandparent=$(git rev-parse HEAD~2) &&
583 git checkout $(git rev-parse HEAD) &&
584 test_tick &&
585 set_fake_editor &&
586 FAKE_LINES="2 1" git rebase -i HEAD~2 &&
587 test $grandparent = $(git rev-parse HEAD~2)
590 test_expect_success 'rebase a commit violating pre-commit' '
592 mkdir -p .git/hooks &&
593 PRE_COMMIT=.git/hooks/pre-commit &&
594 echo "#!/bin/sh" > $PRE_COMMIT &&
595 echo "test -z \"\$(git diff --cached --check)\"" >> $PRE_COMMIT &&
596 chmod a+x $PRE_COMMIT &&
597 echo "monde! " >> file1 &&
598 test_tick &&
599 test_must_fail git commit -m doesnt-verify file1 &&
600 git commit -m doesnt-verify --no-verify file1 &&
601 test_tick &&
602 set_fake_editor &&
603 FAKE_LINES=2 git rebase -i HEAD~2
607 test_expect_success 'rebase with a file named HEAD in worktree' '
609 rm -fr .git/hooks &&
610 git reset --hard &&
611 git checkout -b branch3 A &&
614 GIT_AUTHOR_NAME="Squashed Away" &&
615 export GIT_AUTHOR_NAME &&
616 >HEAD &&
617 git add HEAD &&
618 git commit -m "Add head" &&
619 >BODY &&
620 git add BODY &&
621 git commit -m "Add body"
622 ) &&
624 set_fake_editor &&
625 FAKE_LINES="1 squash 2" git rebase -i to-be-rebased &&
626 test "$(git show -s --pretty=format:%an)" = "Squashed Away"
630 test_expect_success 'do "noop" when there is nothing to cherry-pick' '
632 git checkout -b branch4 HEAD &&
633 GIT_EDITOR=: git commit --amend \
634 --author="Somebody else <somebody@else.com>" &&
635 test $(git rev-parse branch3) != $(git rev-parse branch4) &&
636 set_fake_editor &&
637 git rebase -i branch3 &&
638 test $(git rev-parse branch3) = $(git rev-parse branch4)
642 test_expect_success 'submodule rebase setup' '
643 git checkout A &&
644 mkdir sub &&
646 cd sub && git init && >elif &&
647 git add elif && git commit -m "submodule initial"
648 ) &&
649 echo 1 >file1 &&
650 git add file1 sub &&
651 test_tick &&
652 git commit -m "One" &&
653 echo 2 >file1 &&
654 test_tick &&
655 git commit -a -m "Two" &&
657 cd sub && echo 3 >elif &&
658 git commit -a -m "submodule second"
659 ) &&
660 test_tick &&
661 set_fake_editor &&
662 git commit -a -m "Three changes submodule"
665 test_expect_success 'submodule rebase -i' '
666 set_fake_editor &&
667 FAKE_LINES="1 squash 2 3" git rebase -i A
670 test_expect_success 'submodule conflict setup' '
671 git tag submodule-base &&
672 git checkout HEAD^ &&
674 cd sub && git checkout HEAD^ && echo 4 >elif &&
675 git add elif && git commit -m "submodule conflict"
676 ) &&
677 git add sub &&
678 test_tick &&
679 git commit -m "Conflict in submodule" &&
680 git tag submodule-topic
683 test_expect_success 'rebase -i continue with only submodule staged' '
684 set_fake_editor &&
685 test_must_fail git rebase -i submodule-base &&
686 git add sub &&
687 git rebase --continue &&
688 test $(git rev-parse submodule-base) != $(git rev-parse HEAD)
691 test_expect_success 'rebase -i continue with unstaged submodule' '
692 git checkout submodule-topic &&
693 git reset --hard &&
694 set_fake_editor &&
695 test_must_fail git rebase -i submodule-base &&
696 git reset &&
697 git rebase --continue &&
698 test $(git rev-parse submodule-base) = $(git rev-parse HEAD)
701 test_expect_success 'avoid unnecessary reset' '
702 git checkout master &&
703 git reset --hard &&
704 test-chmtime =123456789 file3 &&
705 git update-index --refresh &&
706 HEAD=$(git rev-parse HEAD) &&
707 set_fake_editor &&
708 git rebase -i HEAD~4 &&
709 test $HEAD = $(git rev-parse HEAD) &&
710 MTIME=$(test-chmtime -v +0 file3 | sed 's/[^0-9].*$//') &&
711 test 123456789 = $MTIME
714 test_expect_success 'reword' '
715 git checkout -b reword-branch master &&
716 set_fake_editor &&
717 FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" git rebase -i A &&
718 git show HEAD | grep "E changed" &&
719 test $(git rev-parse master) != $(git rev-parse HEAD) &&
720 test $(git rev-parse master^) = $(git rev-parse HEAD^) &&
721 FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" git rebase -i A &&
722 git show HEAD^ | grep "D changed" &&
723 FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" git rebase -i A &&
724 git show HEAD~3 | grep "B changed" &&
725 FAKE_LINES="1 reword 2 3 4" FAKE_COMMIT_MESSAGE="C changed" git rebase -i A &&
726 git show HEAD~2 | grep "C changed"
729 test_expect_success 'rebase -i can copy notes' '
730 git config notes.rewrite.rebase true &&
731 git config notes.rewriteRef "refs/notes/*" &&
732 test_commit n1 &&
733 test_commit n2 &&
734 test_commit n3 &&
735 git notes add -m"a note" n3 &&
736 set_fake_editor &&
737 git rebase -i --onto n1 n2 &&
738 test "a note" = "$(git notes show HEAD)"
741 cat >expect <<EOF
742 an earlier note
744 a note
747 test_expect_success 'rebase -i can copy notes over a fixup' '
748 git reset --hard n3 &&
749 git notes add -m"an earlier note" n2 &&
750 set_fake_editor &&
751 GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 fixup 2" git rebase -i n1 &&
752 git notes show > output &&
753 test_cmp expect output
756 test_expect_success 'rebase while detaching HEAD' '
757 git symbolic-ref HEAD &&
758 grandparent=$(git rev-parse HEAD~2) &&
759 test_tick &&
760 set_fake_editor &&
761 FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0 &&
762 test $grandparent = $(git rev-parse HEAD~2) &&
763 test_must_fail git symbolic-ref HEAD
766 test_tick # Ensure that the rebased commits get a different timestamp.
767 test_expect_success 'always cherry-pick with --no-ff' '
768 git checkout no-ff-branch &&
769 git tag original-no-ff-branch &&
770 set_fake_editor &&
771 git rebase -i --no-ff A &&
772 touch empty &&
773 for p in 0 1 2
775 test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) &&
776 git diff HEAD~$p original-no-ff-branch~$p > out &&
777 test_cmp empty out
778 done &&
779 test $(git rev-parse HEAD~3) = $(git rev-parse original-no-ff-branch~3) &&
780 git diff HEAD~3 original-no-ff-branch~3 > out &&
781 test_cmp empty out
784 test_expect_success 'set up commits with funny messages' '
785 git checkout -b funny A &&
786 echo >>file1 &&
787 test_tick &&
788 git commit -a -m "end with slash\\" &&
789 echo >>file1 &&
790 test_tick &&
791 git commit -a -m "something (\000) that looks like octal" &&
792 echo >>file1 &&
793 test_tick &&
794 git commit -a -m "something (\n) that looks like a newline" &&
795 echo >>file1 &&
796 test_tick &&
797 git commit -a -m "another commit"
800 test_expect_success 'rebase-i history with funny messages' '
801 git rev-list A..funny >expect &&
802 test_tick &&
803 set_fake_editor &&
804 FAKE_LINES="1 2 3 4" git rebase -i A &&
805 git rev-list A.. >actual &&
806 test_cmp expect actual
810 test_expect_success 'prepare for rebase -i --exec' '
811 git checkout master &&
812 git checkout -b execute &&
813 test_commit one_exec main.txt one_exec &&
814 test_commit two_exec main.txt two_exec &&
815 test_commit three_exec main.txt three_exec
819 test_expect_success 'running "git rebase -i --exec git show HEAD"' '
820 set_fake_editor &&
821 git rebase -i --exec "git show HEAD" HEAD~2 >actual &&
823 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
824 export FAKE_LINES &&
825 git rebase -i HEAD~2 >expect
826 ) &&
827 sed -e "1,9d" expect >expected &&
828 test_cmp expected actual
832 test_expect_success 'running "git rebase --exec git show HEAD -i"' '
833 git reset --hard execute &&
834 set_fake_editor &&
835 git rebase --exec "git show HEAD" -i HEAD~2 >actual &&
837 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
838 export FAKE_LINES &&
839 git rebase -i HEAD~2 >expect
840 ) &&
841 sed -e "1,9d" expect >expected &&
842 test_cmp expected actual
846 test_expect_success 'running "git rebase -ix git show HEAD"' '
847 git reset --hard execute &&
848 set_fake_editor &&
849 git rebase -ix "git show HEAD" HEAD~2 >actual &&
851 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
852 export FAKE_LINES &&
853 git rebase -i HEAD~2 >expect
854 ) &&
855 sed -e "1,9d" expect >expected &&
856 test_cmp expected actual
860 test_expect_success 'rebase -ix with several <CMD>' '
861 git reset --hard execute &&
862 set_fake_editor &&
863 git rebase -ix "git show HEAD; pwd" HEAD~2 >actual &&
865 FAKE_LINES="1 exec_git_show_HEAD;_pwd 2 exec_git_show_HEAD;_pwd" &&
866 export FAKE_LINES &&
867 git rebase -i HEAD~2 >expect
868 ) &&
869 sed -e "1,9d" expect >expected &&
870 test_cmp expected actual
874 test_expect_success 'rebase -ix with several instances of --exec' '
875 git reset --hard execute &&
876 set_fake_editor &&
877 git rebase -i --exec "git show HEAD" --exec "pwd" HEAD~2 >actual &&
879 FAKE_LINES="1 exec_git_show_HEAD exec_pwd 2
880 exec_git_show_HEAD exec_pwd" &&
881 export FAKE_LINES &&
882 git rebase -i HEAD~2 >expect
883 ) &&
884 sed -e "1,11d" expect >expected &&
885 test_cmp expected actual
889 test_expect_success 'rebase -ix with --autosquash' '
890 git reset --hard execute &&
891 git checkout -b autosquash &&
892 echo second >second.txt &&
893 git add second.txt &&
894 git commit -m "fixup! two_exec" &&
895 echo bis >bis.txt &&
896 git add bis.txt &&
897 git commit -m "fixup! two_exec" &&
898 set_fake_editor &&
900 git checkout -b autosquash_actual &&
901 git rebase -i --exec "git show HEAD" --autosquash HEAD~4 >actual
902 ) &&
903 git checkout autosquash &&
905 git checkout -b autosquash_expected &&
906 FAKE_LINES="1 fixup 3 fixup 4 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
907 export FAKE_LINES &&
908 git rebase -i HEAD~4 >expect
909 ) &&
910 sed -e "1,13d" expect >expected &&
911 test_cmp expected actual
915 test_expect_success 'rebase --exec without -i shows error message' '
916 git reset --hard execute &&
917 set_fake_editor &&
918 test_must_fail git rebase --exec "git show HEAD" HEAD~2 2>actual &&
919 echo "The --exec option must be used with the --interactive option" >expected &&
920 test_i18ncmp expected actual
924 test_expect_success 'rebase -i --exec without <CMD>' '
925 git reset --hard execute &&
926 set_fake_editor &&
927 test_must_fail git rebase -i --exec 2>tmp &&
928 sed -e "1d" tmp >actual &&
929 test_must_fail git rebase -h >expected &&
930 test_cmp expected actual &&
931 git checkout master
934 test_expect_success 'rebase -i --root re-order and drop commits' '
935 git checkout E &&
936 set_fake_editor &&
937 FAKE_LINES="3 1 2 5" git rebase -i --root &&
938 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
939 test B = $(git cat-file commit HEAD^ | sed -ne \$p) &&
940 test A = $(git cat-file commit HEAD^^ | sed -ne \$p) &&
941 test C = $(git cat-file commit HEAD^^^ | sed -ne \$p) &&
942 test 0 = $(git cat-file commit HEAD^^^ | grep -c ^parent\ )
945 test_expect_success 'rebase -i --root retain root commit author and message' '
946 git checkout A &&
947 echo B >file7 &&
948 git add file7 &&
949 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
950 set_fake_editor &&
951 FAKE_LINES="2" git rebase -i --root &&
952 git cat-file commit HEAD | grep -q "^author Twerp Snog" &&
953 git cat-file commit HEAD | grep -q "^different author$"
956 test_expect_success 'rebase -i --root temporary sentinel commit' '
957 git checkout B &&
959 set_fake_editor &&
960 FAKE_LINES="2" &&
961 export FAKE_LINES &&
962 test_must_fail git rebase -i --root
963 ) &&
964 git cat-file commit HEAD | grep "^tree 4b825dc642cb" &&
965 git rebase --abort
968 test_expect_success 'rebase -i --root fixup root commit' '
969 git checkout B &&
970 set_fake_editor &&
971 FAKE_LINES="1 fixup 2" git rebase -i --root &&
972 test A = $(git cat-file commit HEAD | sed -ne \$p) &&
973 test B = $(git show HEAD:file1) &&
974 test 0 = $(git cat-file commit HEAD | grep -c ^parent\ )
977 test_expect_success 'rebase --edit-todo does not works on non-interactive rebase' '
978 git reset --hard &&
979 git checkout conflict-branch &&
980 set_fake_editor &&
981 test_must_fail git rebase --onto HEAD~2 HEAD~ &&
982 test_must_fail git rebase --edit-todo &&
983 git rebase --abort
986 test_expect_success 'rebase --edit-todo can be used to modify todo' '
987 git reset --hard &&
988 git checkout no-conflict-branch^0 &&
989 set_fake_editor &&
990 FAKE_LINES="edit 1 2 3" git rebase -i HEAD~3 &&
991 FAKE_LINES="2 1" git rebase --edit-todo &&
992 git rebase --continue
993 test M = $(git cat-file commit HEAD^ | sed -ne \$p) &&
994 test L = $(git cat-file commit HEAD | sed -ne \$p)
997 test_expect_success 'rebase -i produces readable reflog' '
998 git reset --hard &&
999 git branch -f branch-reflog-test H &&
1000 set_fake_editor &&
1001 git rebase -i --onto I F branch-reflog-test &&
1002 cat >expect <<-\EOF &&
1003 rebase -i (start): checkout I
1004 rebase -i (pick): G
1005 rebase -i (pick): H
1006 rebase -i (finish): returning to refs/heads/branch-reflog-test
1008 tail -n 4 .git/logs/HEAD |
1009 sed -e "s/.* //" >actual &&
1010 test_cmp expect actual
1013 test_expect_success 'rebase -i respects core.commentchar' '
1014 git reset --hard &&
1015 git checkout E^0 &&
1016 test_config core.commentchar "\\" &&
1017 write_script remove-all-but-first.sh <<-\EOF &&
1018 sed -e "2,\$s/^/\\\\/" "$1" >"$1.tmp" &&
1019 mv "$1.tmp" "$1"
1021 test_set_editor "$(pwd)/remove-all-but-first.sh" &&
1022 git rebase -i B &&
1023 test B = $(git cat-file commit HEAD^ | sed -ne \$p)
1026 test_expect_success 'rebase -i, with <onto> and <upstream> specified as :/quuxery' '
1027 test_when_finished "git branch -D torebase" &&
1028 git checkout -b torebase branch1 &&
1029 upstream=$(git rev-parse ":/J") &&
1030 onto=$(git rev-parse ":/A") &&
1031 git rebase --onto $onto $upstream &&
1032 git reset --hard branch1 &&
1033 git rebase --onto ":/A" ":/J" &&
1034 git checkout branch1
1037 test_expect_success 'rebase -i with --strategy and -X' '
1038 git checkout -b conflict-merge-use-theirs conflict-branch &&
1039 git reset --hard HEAD^ &&
1040 echo five >conflict &&
1041 echo Z >file1 &&
1042 git commit -a -m "one file conflict" &&
1043 EDITOR=true git rebase -i --strategy=recursive -Xours conflict-branch &&
1044 test $(git show conflict-branch:conflict) = $(cat conflict) &&
1045 test $(cat file1) = Z
1048 test_expect_success 'rebase -i error on commits with \ in message' '
1049 current_head=$(git rev-parse HEAD)
1050 test_when_finished "git rebase --abort; git reset --hard $current_head; rm -f error" &&
1051 test_commit TO-REMOVE will-conflict old-content &&
1052 test_commit "\temp" will-conflict new-content dummy &&
1054 EDITOR=true &&
1055 export EDITOR &&
1056 test_must_fail git rebase -i HEAD^ --onto HEAD^^ 2>error
1057 ) &&
1058 test_expect_code 1 grep " emp" error
1061 test_expect_success 'short SHA-1 setup' '
1062 test_when_finished "git checkout master" &&
1063 git checkout --orphan collide &&
1064 git rm -rf . &&
1066 unset test_tick &&
1067 test_commit collide1 collide &&
1068 test_commit --notick collide2 collide &&
1069 test_commit --notick collide3 collide
1073 test_expect_success 'short SHA-1 collide' '
1074 test_when_finished "reset_rebase && git checkout master" &&
1075 git checkout collide &&
1077 unset test_tick &&
1078 test_tick &&
1079 set_fake_editor &&
1080 FAKE_COMMIT_MESSAGE="collide2 ac4f2ee" \
1081 FAKE_LINES="reword 1 2" git rebase -i HEAD~2
1085 test_done