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.
13 one - two - three - four (conflict-branch)
15 A - B - C - D - E (master)
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".
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 &&
63 # "exec" commands are run 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. Unsetting SHELL avoids such non-portable behavior
66 # in tests. It must be exported for it to take effect where needed.
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 &&
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" &&
86 test_must_fail git rebase -i A
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 &&
100 test_expect_success
'rebase -i with the exec command runs from tree root' '
101 git checkout master &&
102 mkdir subdir && (cd subdir &&
104 FAKE_LINES="1 exec_>touch-subdir" \
107 test_path_is_file touch-subdir &&
111 test_expect_success
'rebase -i with the exec command checks tree cleanness' '
112 git checkout master &&
114 test_must_fail env FAKE_LINES="exec_echo_foo_>file1 1" git rebase -i HEAD^ &&
115 test_cmp_rev master^ HEAD &&
117 git rebase --continue
120 test_expect_success
'rebase -i with exec of inexistent command' '
121 git checkout master &&
122 test_when_finished "git rebase --abort" &&
124 test_must_fail env FAKE_LINES="exec_this-command-does-not-exist 1" \
125 git rebase -i HEAD^ >actual 2>&1 &&
126 ! grep "Maybe git-rebase is broken" actual
129 test_expect_success
'no changes are a nop' '
130 git checkout branch2 &&
133 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
134 test $(git rev-parse I) = $(git rev-parse HEAD)
137 test_expect_success
'test the [branch] option' '
138 git checkout -b dead-end &&
140 git commit -m "stop here" &&
142 git rebase -i F branch2 &&
143 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
144 test $(git rev-parse I) = $(git rev-parse branch2) &&
145 test $(git rev-parse I) = $(git rev-parse HEAD)
148 test_expect_success
'test --onto <branch>' '
149 git checkout -b test-onto branch2 &&
151 git rebase -i --onto branch1 F &&
152 test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" &&
153 test $(git rev-parse HEAD^) = $(git rev-parse branch1) &&
154 test $(git rev-parse I) = $(git rev-parse branch2)
157 test_expect_success
'rebase on top of a non-conflicting commit' '
158 git checkout branch1 &&
159 git tag original-branch1 &&
161 git rebase -i branch2 &&
162 test file6 = $(git diff --name-only original-branch1) &&
163 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
164 test $(git rev-parse I) = $(git rev-parse branch2) &&
165 test $(git rev-parse I) = $(git rev-parse HEAD~2)
168 test_expect_success
'reflog for the branch shows state before rebase' '
169 test $(git rev-parse branch1@{1}) = $(git rev-parse original-branch1)
172 test_expect_success
'exchange two commits' '
174 FAKE_LINES="2 1" git rebase -i HEAD~2 &&
175 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
176 test G = $(git cat-file commit HEAD | sed -ne \$p)
180 diff --git a/file1 b/file1
181 index f70f10e..fd79235 100644
197 test_expect_success
'stop on conflicting pick' '
198 git tag new-branch1 &&
200 test_must_fail git rebase -i master &&
201 test "$(git rev-parse HEAD~3)" = "$(git rev-parse master)" &&
202 test_cmp expect .git/rebase-merge/patch &&
203 test_cmp expect2 file1 &&
204 test "$(git diff --name-status |
205 sed -n -e "/^U/s/^U[^a-z]*//p")" = file1 &&
206 test 4 = $(grep -v "^#" < .git/rebase-merge/done | wc -l) &&
207 test 0 = $(grep -c "^[^#]" < .git/rebase-merge/git-rebase-todo)
210 test_expect_success
'abort' '
211 git rebase --abort &&
212 test $(git rev-parse new-branch1) = $(git rev-parse HEAD) &&
213 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
214 test_path_is_missing .git/rebase-merge
217 test_expect_success
'abort with error when new base cannot be checked out' '
218 git rm --cached file1 &&
219 git commit -m "remove file in base" &&
221 test_must_fail git rebase -i master > output 2>&1 &&
222 test_i18ngrep "The following untracked working tree files would be overwritten by checkout:" \
224 test_i18ngrep "file1" output &&
225 test_path_is_missing .git/rebase-merge &&
226 git reset --hard HEAD^
229 test_expect_success
'retain authorship' '
233 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
236 git rebase -i --onto master HEAD^ &&
237 git show HEAD | grep "^Author: Twerp Snog"
240 test_expect_success
'retain authorship w/ conflicts' '
241 git reset --hard twerp &&
242 test_commit a conflict a conflict-a &&
243 git reset --hard twerp &&
244 GIT_AUTHOR_NAME=AttributeMe \
245 test_commit b conflict b conflict-b &&
247 test_must_fail git rebase -i conflict-a &&
248 echo resolved >conflict &&
250 git rebase --continue &&
251 test $(git rev-parse conflict-a^0) = $(git rev-parse HEAD^) &&
256 test_expect_success
'squash' '
257 git reset --hard twerp &&
260 GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 &&
261 echo "******************************" &&
263 FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \
264 git rebase -i --onto master HEAD~2 &&
265 test B = $(cat file7) &&
266 test $(git rev-parse HEAD^) = $(git rev-parse master)
269 test_expect_success
'retain authorship when squashing' '
270 git show HEAD | grep "^Author: Twerp Snog"
273 test_expect_success
'-p handles "no changes" gracefully' '
274 HEAD=$(git rev-parse HEAD) &&
276 git rebase -i -p HEAD^ &&
277 git update-index --refresh &&
278 git diff-files --quiet &&
279 git diff-index --quiet --cached HEAD -- &&
280 test $HEAD = $(git rev-parse HEAD)
283 test_expect_failure
'exchange two commits with -p' '
286 FAKE_LINES="2 1" git rebase -i -p HEAD~2 &&
287 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
288 test G = $(git cat-file commit HEAD | sed -ne \$p)
291 test_expect_success
'preserve merges with -p' '
292 git checkout -b to-be-preserved master^ &&
293 : > unrelated-file &&
294 git add unrelated-file &&
296 git commit -m "unrelated" &&
297 git checkout -b another-branch master &&
300 git commit -m J file1 &&
302 git merge to-be-preserved &&
305 git commit -m K file1 &&
308 git commit -m L1 file1 &&
309 git checkout HEAD^ &&
310 echo 1 > unrelated-file &&
312 git commit -m L2 unrelated-file &&
314 git merge another-branch &&
317 git commit -m M file1 &&
318 git checkout -b to-be-rebased &&
321 git rebase -i -p --onto branch1 master &&
322 git update-index --refresh &&
323 git diff-files --quiet &&
324 git diff-index --quiet --cached HEAD -- &&
325 test $(git rev-parse HEAD~6) = $(git rev-parse branch1) &&
326 test $(git rev-parse HEAD~4^2) = $(git rev-parse to-be-preserved) &&
327 test $(git rev-parse HEAD^^2^) = $(git rev-parse HEAD^^^) &&
328 test $(git show HEAD~5:file1) = B &&
329 test $(git show HEAD~3:file1) = C &&
330 test $(git show HEAD:file1) = E &&
331 test $(git show HEAD:unrelated-file) = 1
334 test_expect_success
'edit ancestor with -p' '
336 FAKE_LINES="1 2 edit 3 4" git rebase -i -p HEAD~3 &&
337 echo 2 > unrelated-file &&
339 git commit -m L2-modified --amend unrelated-file &&
340 git rebase --continue &&
341 git update-index --refresh &&
342 git diff-files --quiet &&
343 git diff-index --quiet --cached HEAD -- &&
344 test $(git show HEAD:unrelated-file) = 2
347 test_expect_success
'--continue tries to commit' '
350 test_must_fail git rebase -i --onto new-branch1 HEAD^ &&
351 echo resolved > file1 &&
353 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
354 test $(git rev-parse HEAD^) = $(git rev-parse new-branch1) &&
355 git show HEAD | grep chouette
358 test_expect_success
'verbose flag is heeded, even after --continue' '
359 git reset --hard master@{1} &&
362 test_must_fail git rebase -v -i --onto new-branch1 HEAD^ &&
363 echo resolved > file1 &&
365 git rebase --continue > output &&
366 grep "^ file1 | 2 +-$" output
369 test_expect_success
'multi-squash only fires up editor once' '
370 base=$(git rev-parse HEAD~4) &&
372 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 squash 2 squash 3 squash 4" \
373 EXPECT_HEADER_COUNT=4 \
374 git rebase -i $base &&
375 test $base = $(git rev-parse HEAD^) &&
376 test 1 = $(git show | grep ONCE | wc -l)
379 test_expect_success
'multi-fixup does not fire up editor' '
380 git checkout -b multi-fixup E &&
381 base=$(git rev-parse HEAD~4) &&
383 FAKE_COMMIT_AMEND="NEVER" FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \
384 git rebase -i $base &&
385 test $base = $(git rev-parse HEAD^) &&
386 test 0 = $(git show | grep NEVER | wc -l) &&
387 git checkout to-be-rebased &&
388 git branch -D multi-fixup
391 test_expect_success
'commit message used after conflict' '
392 git checkout -b conflict-fixup conflict-branch &&
393 base=$(git rev-parse HEAD~4) &&
395 test_must_fail env FAKE_LINES="1 fixup 3 fixup 4" git rebase -i $base &&
396 echo three > conflict &&
398 FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \
399 git rebase --continue &&
400 test $base = $(git rev-parse HEAD^) &&
401 test 1 = $(git show | grep ONCE | wc -l) &&
402 git checkout to-be-rebased &&
403 git branch -D conflict-fixup
406 test_expect_success
'commit message retained after conflict' '
407 git checkout -b conflict-squash conflict-branch &&
408 base=$(git rev-parse HEAD~4) &&
410 test_must_fail env FAKE_LINES="1 fixup 3 squash 4" git rebase -i $base &&
411 echo three > conflict &&
413 FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \
414 git rebase --continue &&
415 test $base = $(git rev-parse HEAD^) &&
416 test 2 = $(git show | grep TWICE | wc -l) &&
417 git checkout to-be-rebased &&
418 git branch -D conflict-squash
421 cat > expect-squash-fixup
<< EOF
429 test_expect_success
'squash and fixup generate correct log messages' '
430 git checkout -b squash-fixup E &&
431 base=$(git rev-parse HEAD~4) &&
433 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 fixup 2 squash 3 fixup 4" \
434 EXPECT_HEADER_COUNT=4 \
435 git rebase -i $base &&
436 git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup &&
437 test_cmp expect-squash-fixup actual-squash-fixup &&
438 git checkout to-be-rebased &&
439 git branch -D squash-fixup
442 test_expect_success
'squash ignores comments' '
443 git checkout -b skip-comments E &&
444 base=$(git rev-parse HEAD~4) &&
446 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \
447 EXPECT_HEADER_COUNT=4 \
448 git rebase -i $base &&
449 test $base = $(git rev-parse HEAD^) &&
450 test 1 = $(git show | grep ONCE | wc -l) &&
451 git checkout to-be-rebased &&
452 git branch -D skip-comments
455 test_expect_success
'squash ignores blank lines' '
456 git checkout -b skip-blank-lines E &&
457 base=$(git rev-parse HEAD~4) &&
459 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \
460 EXPECT_HEADER_COUNT=4 \
461 git rebase -i $base &&
462 test $base = $(git rev-parse HEAD^) &&
463 test 1 = $(git show | grep ONCE | wc -l) &&
464 git checkout to-be-rebased &&
465 git branch -D skip-blank-lines
468 test_expect_success
'squash works as expected' '
469 git checkout -b squash-works no-conflict-branch &&
470 one=$(git rev-parse HEAD~3) &&
472 FAKE_LINES="1 squash 3 2" EXPECT_HEADER_COUNT=2 \
473 git rebase -i HEAD~3 &&
474 test $one = $(git rev-parse HEAD~2)
477 test_expect_success
'interrupted squash works as expected' '
478 git checkout -b interrupted-squash conflict-branch &&
479 one=$(git rev-parse HEAD~3) &&
481 test_must_fail env FAKE_LINES="1 squash 3 2" git rebase -i HEAD~3 &&
482 (echo one; echo two; echo four) > conflict &&
484 test_must_fail git rebase --continue &&
485 echo resolved > conflict &&
487 git rebase --continue &&
488 test $one = $(git rev-parse HEAD~2)
491 test_expect_success
'interrupted squash works as expected (case 2)' '
492 git checkout -b interrupted-squash2 conflict-branch &&
493 one=$(git rev-parse HEAD~3) &&
495 test_must_fail env FAKE_LINES="3 squash 1 2" git rebase -i HEAD~3 &&
496 (echo one; echo four) > conflict &&
498 test_must_fail git rebase --continue &&
499 (echo one; echo two; echo four) > conflict &&
501 test_must_fail git rebase --continue &&
502 echo resolved > conflict &&
504 git rebase --continue &&
505 test $one = $(git rev-parse HEAD~2)
508 test_expect_success
'--continue tries to commit, even for "edit"' '
509 echo unrelated > file7 &&
512 git commit -m "unrelated change" &&
513 parent=$(git rev-parse HEAD^) &&
516 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
517 echo edited > file7 &&
519 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
520 test edited = $(git show HEAD:file7) &&
521 git show HEAD | grep chouette &&
522 test $parent = $(git rev-parse HEAD^)
525 test_expect_success
'aborted --continue does not squash commits after "edit"' '
526 old=$(git rev-parse HEAD) &&
529 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
530 echo "edited again" > file7 &&
532 test_must_fail env FAKE_COMMIT_MESSAGE=" " git rebase --continue &&
533 test $old = $(git rev-parse HEAD) &&
537 test_expect_success
'auto-amend only edited commits after "edit"' '
540 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
541 echo "edited again" > file7 &&
543 FAKE_COMMIT_MESSAGE="edited file7 again" git commit &&
544 echo "and again" > file7 &&
547 test_must_fail env FAKE_COMMIT_MESSAGE="and again" git rebase --continue &&
551 test_expect_success
'clean error after failed "exec"' '
553 test_when_finished "git rebase --abort || :" &&
555 test_must_fail env FAKE_LINES="1 exec_false" git rebase -i HEAD^ &&
556 echo "edited again" > file7 &&
558 test_must_fail git rebase --continue 2>error &&
559 test_i18ngrep "You have staged changes in your working tree." error
562 test_expect_success
'rebase a detached HEAD' '
563 grandparent=$(git rev-parse HEAD~2) &&
564 git checkout $(git rev-parse HEAD) &&
567 FAKE_LINES="2 1" git rebase -i HEAD~2 &&
568 test $grandparent = $(git rev-parse HEAD~2)
571 test_expect_success
'rebase a commit violating pre-commit' '
573 mkdir -p .git/hooks &&
574 write_script .git/hooks/pre-commit <<-\EOF &&
575 test -z "$(git diff --cached --check)"
577 echo "monde! " >> file1 &&
579 test_must_fail git commit -m doesnt-verify file1 &&
580 git commit -m doesnt-verify --no-verify file1 &&
583 FAKE_LINES=2 git rebase -i HEAD~2
587 test_expect_success
'rebase with a file named HEAD in worktree' '
591 git checkout -b branch3 A &&
594 GIT_AUTHOR_NAME="Squashed Away" &&
595 export GIT_AUTHOR_NAME &&
598 git commit -m "Add head" &&
601 git commit -m "Add body"
605 FAKE_LINES="1 squash 2" git rebase -i to-be-rebased &&
606 test "$(git show -s --pretty=format:%an)" = "Squashed Away"
610 test_expect_success
'do "noop" when there is nothing to cherry-pick' '
612 git checkout -b branch4 HEAD &&
613 GIT_EDITOR=: git commit --amend \
614 --author="Somebody else <somebody@else.com>" &&
615 test $(git rev-parse branch3) != $(git rev-parse branch4) &&
617 git rebase -i branch3 &&
618 test $(git rev-parse branch3) = $(git rev-parse branch4)
622 test_expect_success
'submodule rebase setup' '
626 cd sub && git init && >elif &&
627 git add elif && git commit -m "submodule initial"
632 git commit -m "One" &&
635 git commit -a -m "Two" &&
637 cd sub && echo 3 >elif &&
638 git commit -a -m "submodule second"
642 git commit -a -m "Three changes submodule"
645 test_expect_success
'submodule rebase -i' '
647 FAKE_LINES="1 squash 2 3" git rebase -i A
650 test_expect_success
'submodule conflict setup' '
651 git tag submodule-base &&
652 git checkout HEAD^ &&
654 cd sub && git checkout HEAD^ && echo 4 >elif &&
655 git add elif && git commit -m "submodule conflict"
659 git commit -m "Conflict in submodule" &&
660 git tag submodule-topic
663 test_expect_success
'rebase -i continue with only submodule staged' '
665 test_must_fail git rebase -i submodule-base &&
667 git rebase --continue &&
668 test $(git rev-parse submodule-base) != $(git rev-parse HEAD)
671 test_expect_success
'rebase -i continue with unstaged submodule' '
672 git checkout submodule-topic &&
675 test_must_fail git rebase -i submodule-base &&
677 git rebase --continue &&
678 test $(git rev-parse submodule-base) = $(git rev-parse HEAD)
681 test_expect_success
'avoid unnecessary reset' '
682 git checkout master &&
684 test-chmtime =123456789 file3 &&
685 git update-index --refresh &&
686 HEAD=$(git rev-parse HEAD) &&
688 git rebase -i HEAD~4 &&
689 test $HEAD = $(git rev-parse HEAD) &&
690 MTIME=$(test-chmtime -v +0 file3 | sed 's
/[^
0-9].
*$
//') &&
691 test 123456789 = $MTIME
694 test_expect_success
'reword' '
695 git checkout -b reword-branch master &&
697 FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" git rebase -i A &&
698 git show HEAD | grep "E changed" &&
699 test $(git rev-parse master) != $(git rev-parse HEAD) &&
700 test $(git rev-parse master^) = $(git rev-parse HEAD^) &&
701 FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" git rebase -i A &&
702 git show HEAD^ | grep "D changed" &&
703 FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" git rebase -i A &&
704 git show HEAD~3 | grep "B changed" &&
705 FAKE_LINES="1 reword 2 3 4" FAKE_COMMIT_MESSAGE="C changed" git rebase -i A &&
706 git show HEAD~2 | grep "C changed"
709 test_expect_success
'rebase -i can copy notes' '
710 git config notes.rewrite.rebase true &&
711 git config notes.rewriteRef "refs/notes/*" &&
715 git notes add -m"a note" n3 &&
717 git rebase -i --onto n1 n2 &&
718 test "a note" = "$(git notes show HEAD)"
727 test_expect_success
'rebase -i can copy notes over a fixup' '
728 git reset --hard n3 &&
729 git notes add -m"an earlier note" n2 &&
731 GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 fixup 2" git rebase -i n1 &&
732 git notes show > output &&
733 test_cmp expect output
736 test_expect_success
'rebase while detaching HEAD' '
737 git symbolic-ref HEAD &&
738 grandparent=$(git rev-parse HEAD~2) &&
741 FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0 &&
742 test $grandparent = $(git rev-parse HEAD~2) &&
743 test_must_fail git symbolic-ref HEAD
746 test_tick
# Ensure that the rebased commits get a different timestamp.
747 test_expect_success
'always cherry-pick with --no-ff' '
748 git checkout no-ff-branch &&
749 git tag original-no-ff-branch &&
751 git rebase -i --no-ff A &&
755 test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) &&
756 git diff HEAD~$p original-no-ff-branch~$p > out &&
759 test $(git rev-parse HEAD~3) = $(git rev-parse original-no-ff-branch~3) &&
760 git diff HEAD~3 original-no-ff-branch~3 > out &&
764 test_expect_success
'set up commits with funny messages' '
765 git checkout -b funny A &&
768 git commit -a -m "end with slash\\" &&
771 git commit -a -m "something (\000) that looks like octal" &&
774 git commit -a -m "something (\n) that looks like a newline" &&
777 git commit -a -m "another commit"
780 test_expect_success
'rebase-i history with funny messages' '
781 git rev-list A..funny >expect &&
784 FAKE_LINES="1 2 3 4" git rebase -i A &&
785 git rev-list A.. >actual &&
786 test_cmp expect actual
789 test_expect_success
'prepare for rebase -i --exec' '
790 git checkout master &&
791 git checkout -b execute &&
792 test_commit one_exec main.txt one_exec &&
793 test_commit two_exec main.txt two_exec &&
794 test_commit three_exec main.txt three_exec
797 test_expect_success
'running "git rebase -i --exec git show HEAD"' '
799 git rebase -i --exec "git show HEAD" HEAD~2 >actual &&
801 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
803 git rebase -i HEAD~2 >expect
805 sed -e "1,9d" expect >expected &&
806 test_cmp expected actual
809 test_expect_success
'running "git rebase --exec git show HEAD -i"' '
810 git reset --hard execute &&
812 git rebase --exec "git show HEAD" -i HEAD~2 >actual &&
814 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
816 git rebase -i HEAD~2 >expect
818 sed -e "1,9d" expect >expected &&
819 test_cmp expected actual
822 test_expect_success
'running "git rebase -ix git show HEAD"' '
823 git reset --hard execute &&
825 git rebase -ix "git show HEAD" HEAD~2 >actual &&
827 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
829 git rebase -i HEAD~2 >expect
831 sed -e "1,9d" expect >expected &&
832 test_cmp expected actual
836 test_expect_success
'rebase -ix with several <CMD>' '
837 git reset --hard execute &&
839 git rebase -ix "git show HEAD; pwd" HEAD~2 >actual &&
841 FAKE_LINES="1 exec_git_show_HEAD;_pwd 2 exec_git_show_HEAD;_pwd" &&
843 git rebase -i HEAD~2 >expect
845 sed -e "1,9d" expect >expected &&
846 test_cmp expected actual
849 test_expect_success
'rebase -ix with several instances of --exec' '
850 git reset --hard execute &&
852 git rebase -i --exec "git show HEAD" --exec "pwd" HEAD~2 >actual &&
854 FAKE_LINES="1 exec_git_show_HEAD exec_pwd 2
855 exec_git_show_HEAD exec_pwd" &&
857 git rebase -i HEAD~2 >expect
859 sed -e "1,11d" expect >expected &&
860 test_cmp expected actual
863 test_expect_success
'rebase -ix with --autosquash' '
864 git reset --hard execute &&
865 git checkout -b autosquash &&
866 echo second >second.txt &&
867 git add second.txt &&
868 git commit -m "fixup! two_exec" &&
871 git commit -m "fixup! two_exec" &&
874 git checkout -b autosquash_actual &&
875 git rebase -i --exec "git show HEAD" --autosquash HEAD~4 >actual
877 git checkout autosquash &&
879 git checkout -b autosquash_expected &&
880 FAKE_LINES="1 fixup 3 fixup 4 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
882 git rebase -i HEAD~4 >expect
884 sed -e "1,13d" expect >expected &&
885 test_cmp expected actual
888 test_expect_success
'rebase --exec works without -i ' '
889 git reset --hard execute &&
890 rm -rf exec_output &&
891 EDITOR="echo >invoked_editor" git rebase --exec "echo a line >>exec_output" HEAD~2 2>actual &&
892 test_i18ngrep "Successfully rebased and updated" actual &&
893 test_line_count = 2 exec_output &&
894 test_path_is_missing invoked_editor
897 test_expect_success
'rebase -i --exec without <CMD>' '
898 git reset --hard execute &&
900 test_must_fail git rebase -i --exec 2>tmp &&
901 sed -e "1d" tmp >actual &&
902 test_must_fail git rebase -h >expected &&
903 test_cmp expected actual &&
907 test_expect_success
'rebase -i --root re-order and drop commits' '
910 FAKE_LINES="3 1 2 5" git rebase -i --root &&
911 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
912 test B = $(git cat-file commit HEAD^ | sed -ne \$p) &&
913 test A = $(git cat-file commit HEAD^^ | sed -ne \$p) &&
914 test C = $(git cat-file commit HEAD^^^ | sed -ne \$p) &&
915 test 0 = $(git cat-file commit HEAD^^^ | grep -c ^parent\ )
918 test_expect_success
'rebase -i --root retain root commit author and message' '
922 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
924 FAKE_LINES="2" git rebase -i --root &&
925 git cat-file commit HEAD | grep -q "^author Twerp Snog" &&
926 git cat-file commit HEAD | grep -q "^different author$"
929 test_expect_success
'rebase -i --root temporary sentinel commit' '
932 test_must_fail env FAKE_LINES="2" git rebase -i --root &&
933 git cat-file commit HEAD | grep "^tree 4b825dc642cb" &&
937 test_expect_success
'rebase -i --root fixup root commit' '
940 FAKE_LINES="1 fixup 2" git rebase -i --root &&
941 test A = $(git cat-file commit HEAD | sed -ne \$p) &&
942 test B = $(git show HEAD:file1) &&
943 test 0 = $(git cat-file commit HEAD | grep -c ^parent\ )
946 test_expect_success
'rebase --edit-todo does not works on non-interactive rebase' '
948 git checkout conflict-branch &&
950 test_must_fail git rebase --onto HEAD~2 HEAD~ &&
951 test_must_fail git rebase --edit-todo &&
955 test_expect_success
'rebase --edit-todo can be used to modify todo' '
957 git checkout no-conflict-branch^0 &&
959 FAKE_LINES="edit 1 2 3" git rebase -i HEAD~3 &&
960 FAKE_LINES="2 1" git rebase --edit-todo &&
961 git rebase --continue &&
962 test M = $(git cat-file commit HEAD^ | sed -ne \$p) &&
963 test L = $(git cat-file commit HEAD | sed -ne \$p)
966 test_expect_success
'rebase -i produces readable reflog' '
968 git branch -f branch-reflog-test H &&
970 git rebase -i --onto I F branch-reflog-test &&
971 cat >expect <<-\EOF &&
972 rebase -i (finish): returning to refs/heads/branch-reflog-test
975 rebase -i (start): checkout I
977 git reflog -n4 HEAD |
978 sed "s/[^:]*: //" >actual &&
979 test_cmp expect actual
982 test_expect_success
'rebase -i respects core.commentchar' '
985 test_config core.commentchar "\\" &&
986 write_script remove-all-but-first.sh <<-\EOF &&
987 sed -e "2,\$s/^/\\\\/" "$1" >"$1.tmp" &&
990 test_set_editor "$(pwd)/remove-all-but-first.sh" &&
992 test B = $(git cat-file commit HEAD^ | sed -ne \$p)
995 test_expect_success
'rebase -i respects core.commentchar=auto' '
996 test_config core.commentchar auto &&
997 write_script copy-edit-script.sh <<-\EOF &&
1000 test_set_editor "$(pwd)/copy-edit-script.sh" &&
1001 test_when_finished "git rebase --abort || :" &&
1002 git rebase -i HEAD^ &&
1003 test -z "$(grep -ve "^#" -e "^\$" -e "^pick" edit-script)"
1006 test_expect_success
'rebase -i, with <onto> and <upstream> specified as :/quuxery' '
1007 test_when_finished "git branch -D torebase" &&
1008 git checkout -b torebase branch1 &&
1009 upstream=$(git rev-parse ":/J") &&
1010 onto=$(git rev-parse ":/A") &&
1011 git rebase --onto $onto $upstream &&
1012 git reset --hard branch1 &&
1013 git rebase --onto ":/A" ":/J" &&
1014 git checkout branch1
1017 test_expect_success
'rebase -i with --strategy and -X' '
1018 git checkout -b conflict-merge-use-theirs conflict-branch &&
1019 git reset --hard HEAD^ &&
1020 echo five >conflict &&
1022 git commit -a -m "one file conflict" &&
1023 EDITOR=true git rebase -i --strategy=recursive -Xours conflict-branch &&
1024 test $(git show conflict-branch:conflict) = $(cat conflict) &&
1025 test $(cat file1) = Z
1028 test_expect_success
'interrupted rebase -i with --strategy and -X' '
1029 git checkout -b conflict-merge-use-theirs-interrupted conflict-branch &&
1030 git reset --hard HEAD^ &&
1032 git add breakpoint &&
1033 git commit -m "breakpoint for interactive mode" &&
1034 echo five >conflict &&
1036 git commit -a -m "one file conflict" &&
1038 FAKE_LINES="edit 1 2" git rebase -i --strategy=recursive -Xours conflict-branch &&
1039 git rebase --continue &&
1040 test $(git show conflict-branch:conflict) = $(cat conflict) &&
1041 test $(cat file1) = Z
1044 test_expect_success
'rebase -i error on commits with \ in message' '
1045 current_head=$(git rev-parse HEAD) &&
1046 test_when_finished "git rebase --abort; git reset --hard $current_head; rm -f error" &&
1047 test_commit TO-REMOVE will-conflict old-content &&
1048 test_commit "\temp" will-conflict new-content dummy &&
1049 test_must_fail env EDITOR=true git rebase -i HEAD^ --onto HEAD^^ 2>error &&
1050 test_expect_code 1 grep " emp" error
1053 test_expect_success
'short SHA-1 setup' '
1054 test_when_finished "git checkout master" &&
1055 git checkout --orphan collide &&
1059 test_commit collide1 collide &&
1060 test_commit --notick collide2 collide &&
1061 test_commit --notick collide3 collide
1065 test_expect_success
'short SHA-1 collide' '
1066 test_when_finished "reset_rebase && git checkout master" &&
1067 git checkout collide &&
1072 FAKE_COMMIT_MESSAGE="collide2 ac4f2ee" \
1073 FAKE_LINES="reword 1 2" git rebase -i HEAD~2
1077 test_expect_success
'respect core.abbrev' '
1078 git config core.abbrev 12 &&
1079 set_cat_todo_editor &&
1080 test_must_fail git rebase -i HEAD~4 >todo-list &&
1081 test 4 = $(grep -c "pick [0-9a-f]\{12,\}" todo-list)
1084 test_expect_success
'todo count' '
1085 write_script dump-raw.sh <<-\EOF &&
1088 test_set_editor "$(pwd)/dump-raw.sh" &&
1089 git rebase -i HEAD~4 >actual &&
1090 test_i18ngrep "^# Rebase ..* onto ..* ([0-9]" actual
1093 test_expect_success
'rebase -i commits that overwrite untracked files (pick)' '
1094 git checkout --force branch2 &&
1097 FAKE_LINES="edit 1 2" git rebase -i A &&
1098 test_cmp_rev HEAD F &&
1099 test_path_is_missing file6 &&
1101 test_must_fail git rebase --continue &&
1102 test_cmp_rev HEAD F &&
1104 git rebase --continue &&
1108 test_expect_success
'rebase -i commits that overwrite untracked files (squash)' '
1109 git checkout --force branch2 &&
1111 git tag original-branch2 &&
1113 FAKE_LINES="edit 1 squash 2" git rebase -i A &&
1114 test_cmp_rev HEAD F &&
1115 test_path_is_missing file6 &&
1117 test_must_fail git rebase --continue &&
1118 test_cmp_rev HEAD F &&
1120 git rebase --continue &&
1121 test $(git cat-file commit HEAD | sed -ne \$p) = I &&
1122 git reset --hard original-branch2
1125 test_expect_success
'rebase -i commits that overwrite untracked files (no ff)' '
1126 git checkout --force branch2 &&
1129 FAKE_LINES="edit 1 2" git rebase -i --no-ff A &&
1130 test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1131 test_path_is_missing file6 &&
1133 test_must_fail git rebase --continue &&
1134 test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1136 git rebase --continue &&
1137 test $(git cat-file commit HEAD | sed -ne \$p) = I
1140 test_expect_success
'rebase --continue removes CHERRY_PICK_HEAD' '
1141 git checkout -b commit-to-skip &&
1144 test_seq 5 | sed "s/$double/&&/" >seq &&
1147 git commit -m seq-$double
1150 git reset --hard HEAD~2 &&
1151 git cherry-pick seq-onto &&
1153 test_must_fail env FAKE_LINES= git rebase -i seq-onto &&
1154 test -d .git/rebase-merge &&
1155 git rebase --continue &&
1156 git diff --exit-code seq-onto &&
1157 test ! -d .git/rebase-merge &&
1158 test ! -f .git/CHERRY_PICK_HEAD
1161 rebase_setup_and_clean
() {
1162 test_when_finished
"
1163 git checkout master &&
1164 test_might_fail git branch -D $1 &&
1165 test_might_fail git rebase --abort
1167 git checkout
-b $1 master
1170 test_expect_success
'drop' '
1171 rebase_setup_and_clean drop-test &&
1173 FAKE_LINES="1 drop 2 3 drop 4 5" git rebase -i --root &&
1174 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1175 test C = $(git cat-file commit HEAD^ | sed -ne \$p) &&
1176 test A = $(git cat-file commit HEAD^^ | sed -ne \$p)
1180 Successfully rebased and updated refs/heads/missing-commit.
1183 test_expect_success
'rebase -i respects rebase.missingCommitsCheck = ignore' '
1184 test_config rebase.missingCommitsCheck ignore &&
1185 rebase_setup_and_clean missing-commit &&
1187 FAKE_LINES="1 2 3 4" \
1188 git rebase -i --root 2>actual &&
1189 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1190 test_i18ncmp expect actual
1194 Warning: some commits may have been dropped accidentally.
1195 Dropped commits (newer to older):
1196 - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
1197 To avoid this message, use "drop" to explicitly remove a commit.
1199 Use 'git config rebase.missingCommitsCheck' to change the level of warnings.
1200 The possible behaviours are: ignore, warn, error.
1202 Successfully rebased and updated refs/heads/missing-commit.
1205 test_expect_success
'rebase -i respects rebase.missingCommitsCheck = warn' '
1206 test_config rebase.missingCommitsCheck warn &&
1207 rebase_setup_and_clean missing-commit &&
1209 FAKE_LINES="1 2 3 4" \
1210 git rebase -i --root 2>actual &&
1211 test_i18ncmp expect actual &&
1212 test D = $(git cat-file commit HEAD | sed -ne \$p)
1216 Warning: some commits may have been dropped accidentally.
1217 Dropped commits (newer to older):
1218 - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
1219 - $(git rev-list --pretty=oneline --abbrev-commit -1 master~2)
1220 To avoid this message, use "drop" to explicitly remove a commit.
1222 Use 'git config rebase.missingCommitsCheck' to change the level of warnings.
1223 The possible behaviours are: ignore, warn, error.
1225 You can fix this with 'git rebase --edit-todo' and then run 'git rebase --continue'.
1226 Or you can abort the rebase with 'git rebase --abort'.
1229 test_expect_success
'rebase -i respects rebase.missingCommitsCheck = error' '
1230 test_config rebase.missingCommitsCheck error &&
1231 rebase_setup_and_clean missing-commit &&
1233 test_must_fail env FAKE_LINES="1 2 4" \
1234 git rebase -i --root 2>actual &&
1235 test_i18ncmp expect actual &&
1236 cp .git/rebase-merge/git-rebase-todo.backup \
1237 .git/rebase-merge/git-rebase-todo &&
1238 FAKE_LINES="1 2 drop 3 4 drop 5" \
1239 git rebase --edit-todo &&
1240 git rebase --continue &&
1241 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1242 test B = $(git cat-file commit HEAD^ | sed -ne \$p)
1246 Warning: the command isn't recognized in the following line:
1247 - badcmd $(git rev-list --oneline -1 master~1)
1249 You can fix this with 'git rebase --edit-todo' and then run 'git rebase --continue'.
1250 Or you can abort the rebase with 'git rebase --abort'.
1253 test_expect_success
'static check of bad command' '
1254 rebase_setup_and_clean bad-cmd &&
1256 test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \
1257 git rebase -i --root 2>actual &&
1258 test_i18ncmp expect actual &&
1259 FAKE_LINES="1 2 3 drop 4 5" git rebase --edit-todo &&
1260 git rebase --continue &&
1261 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1262 test C = $(git cat-file commit HEAD^ | sed -ne \$p)
1265 test_expect_success
'tabs and spaces are accepted in the todolist' '
1266 rebase_setup_and_clean indented-comment &&
1267 write_script add-indent.sh <<-\EOF &&
1269 # Turn single spaces into space/tab mix
1270 sed "1s/ / /g; 2s/ / /g; 3s/ / /g" "$1"
1271 printf "\n\t# comment\n #more\n\t # comment\n"
1275 test_set_editor "$(pwd)/add-indent.sh" &&
1276 git rebase -i HEAD^^^ &&
1277 test E = $(git cat-file commit HEAD | sed -ne \$p)
1281 Warning: the SHA-1 is missing or isn't a commit in the following line:
1282 - edit XXXXXXX False commit
1284 You can fix this with 'git rebase --edit-todo' and then run 'git rebase --continue'.
1285 Or you can abort the rebase with 'git rebase --abort'.
1288 test_expect_success
'static check of bad SHA-1' '
1289 rebase_setup_and_clean bad-sha &&
1291 test_must_fail env FAKE_LINES="1 2 edit fakesha 3 4 5 #" \
1292 git rebase -i --root 2>actual &&
1293 test_i18ncmp expect actual &&
1294 FAKE_LINES="1 2 4 5 6" git rebase --edit-todo &&
1295 git rebase --continue &&
1296 test E = $(git cat-file commit HEAD | sed -ne \$p)
1299 test_expect_success
'editor saves as CR/LF' '
1300 git checkout -b with-crlf &&
1301 write_script add-crs.sh <<-\EOF &&
1302 sed -e "s/\$/Q/" <"$1" | tr Q "\\015" >"$1".new &&
1306 test_set_editor "$(pwd)/add-crs.sh" &&
1312 test_expect_success
'rebase -i --gpg-sign=<key-id>' '
1314 FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" HEAD^ \
1316 test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err