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 (primary)
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 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=master
29 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
33 .
"$TEST_DIRECTORY"/lib-rebase.sh
35 test_expect_success
'setup' '
36 git switch -C primary &&
37 test_commit A file1 &&
38 test_commit B file1 &&
39 test_commit C file2 &&
40 test_commit D file1 &&
41 test_commit E file3 &&
42 git checkout -b branch1 A &&
43 test_commit F file4 &&
44 test_commit G file1 &&
45 test_commit H file5 &&
46 git checkout -b branch2 F &&
47 test_commit I file6 &&
48 git checkout -b conflict-branch A &&
49 test_commit one conflict &&
50 test_commit two conflict &&
51 test_commit three conflict &&
52 test_commit four conflict &&
53 git checkout -b no-conflict-branch A &&
54 test_commit J fileJ &&
55 test_commit K fileK &&
56 test_commit L fileL &&
57 test_commit M fileM &&
58 git checkout -b no-ff-branch A &&
59 test_commit N fileN &&
60 test_commit O fileO &&
64 # "exec" commands are run with the user shell by default, but this may
65 # be non-POSIX. For example, if SHELL=zsh then ">file" doesn't work
66 # to create a file. Unsetting SHELL avoids such non-portable behavior
67 # in tests. It must be exported for it to take effect where needed.
71 test_expect_success
'rebase --keep-empty' '
72 git checkout -b emptybranch primary &&
73 git commit --allow-empty -m "empty" &&
74 git rebase --keep-empty -i HEAD~2 &&
75 git log --oneline >actual &&
76 test_line_count = 6 actual
79 test_expect_success
'rebase -i with empty todo list' '
80 cat >expect <<-\EOF &&
85 test_must_fail env FAKE_LINES="#" \
86 git rebase -i HEAD^ >output 2>&1
88 tail -n 1 output >actual && # Ignore output about changing todo list
89 test_cmp expect actual
92 test_expect_success
'rebase -i with the exec command' '
93 git checkout primary &&
96 FAKE_LINES="1 exec_>touch-one
97 2 exec_>touch-two exec_false exec_>touch-three
98 3 4 exec_>\"touch-file__name_with_spaces\";_>touch-after-semicolon 5" &&
100 test_must_fail git rebase -i A
102 test_path_is_file touch-one &&
103 test_path_is_file touch-two &&
104 # Missing because we should have stopped by now.
105 test_path_is_missing touch-three &&
106 test_cmp_rev C HEAD &&
107 git rebase --continue &&
108 test_path_is_file touch-three &&
109 test_path_is_file "touch-file name with spaces" &&
110 test_path_is_file touch-after-semicolon &&
111 test_cmp_rev primary HEAD &&
115 test_expect_success
'rebase -i with the exec command runs from tree root' '
116 git checkout primary &&
117 mkdir subdir && (cd subdir &&
119 FAKE_LINES="1 exec_>touch-subdir" \
122 test_path_is_file touch-subdir &&
126 test_expect_success
'rebase -i with exec allows git commands in subdirs' '
127 test_when_finished "rm -rf subdir" &&
128 test_when_finished "git rebase --abort ||:" &&
129 git checkout primary &&
130 mkdir subdir && (cd subdir &&
132 FAKE_LINES="1 x_cd_subdir_&&_git_rev-parse_--is-inside-work-tree" \
137 test_expect_success
'rebase -i sets work tree properly' '
138 test_when_finished "rm -rf subdir" &&
139 test_when_finished "test_might_fail git rebase --abort" &&
141 git rebase -x "(cd subdir && git rev-parse --show-toplevel)" HEAD^ \
143 ! grep "/subdir$" actual
146 test_expect_success
'rebase -i with the exec command checks tree cleanness' '
147 git checkout primary &&
150 test_must_fail env FAKE_LINES="exec_echo_foo_>file1 1" \
153 test_cmp_rev primary^ HEAD &&
155 git rebase --continue
158 test_expect_success
'rebase -x with empty command fails' '
159 test_when_finished "git rebase --abort ||:" &&
160 test_must_fail env git rebase -x "" @ 2>actual &&
161 test_write_lines "error: empty exec command" >expected &&
162 test_cmp expected actual &&
163 test_must_fail env git rebase -x " " @ 2>actual &&
164 test_cmp expected actual
167 test_expect_success
'rebase -x with newline in command fails' '
168 test_when_finished "git rebase --abort ||:" &&
169 test_must_fail env git rebase -x "a${LF}b" @ 2>actual &&
170 test_write_lines "error: exec commands cannot contain newlines" \
172 test_cmp expected actual
175 test_expect_success
'rebase -i with exec of inexistent command' '
176 git checkout primary &&
177 test_when_finished "git rebase --abort" &&
180 test_must_fail env FAKE_LINES="exec_this-command-does-not-exist 1" \
181 git rebase -i HEAD^ >actual 2>&1
183 ! grep "Maybe git-rebase is broken" actual
186 test_expect_success
'implicit interactive rebase does not invoke sequence editor' '
187 test_when_finished "git rebase --abort ||:" &&
188 GIT_SEQUENCE_EDITOR="echo bad >" git rebase -x"echo one" @^
191 test_expect_success
'no changes are a nop' '
192 git checkout branch2 &&
194 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
198 test_expect_success
'test the [branch] option' '
199 git checkout -b dead-end &&
201 git commit -m "stop here" &&
202 git rebase -i F branch2 &&
203 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
204 test_cmp_rev I branch2 &&
208 test_expect_success
'test --onto <branch>' '
209 git checkout -b test-onto branch2 &&
210 git rebase -i --onto branch1 F &&
211 test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" &&
212 test_cmp_rev HEAD^ branch1 &&
213 test_cmp_rev I branch2
216 test_expect_success
'rebase on top of a non-conflicting commit' '
217 git checkout branch1 &&
218 git tag original-branch1 &&
219 git rebase -i branch2 &&
220 test file6 = $(git diff --name-only original-branch1) &&
221 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
222 test_cmp_rev I branch2 &&
223 test_cmp_rev I HEAD~2
226 test_expect_success
'reflog for the branch shows state before rebase' '
227 test_cmp_rev branch1@{1} original-branch1
230 test_expect_success
'reflog for the branch shows correct finish message' '
231 printf "rebase (finish): refs/heads/branch1 onto %s\n" \
232 "$(git rev-parse branch2)" >expected &&
233 git log -g --pretty=%gs -1 refs/heads/branch1 >actual &&
234 test_cmp expected actual
237 test_expect_success
'exchange two commits' '
240 FAKE_LINES="2 1" git rebase -i HEAD~2
242 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
243 test G = $(git cat-file commit HEAD | sed -ne \$p) &&
244 blob1=$(git rev-parse --short HEAD^:file1) &&
245 blob2=$(git rev-parse --short HEAD:file1) &&
246 commit=$(git rev-parse --short HEAD)
249 test_expect_success
'stop on conflicting pick' '
250 cat >expect <<-EOF &&
251 diff --git a/file1 b/file1
252 index $blob1..$blob2 100644
259 cat >expect2 <<-EOF &&
266 git tag new-branch1 &&
267 test_must_fail git rebase -i primary &&
268 test "$(git rev-parse HEAD~3)" = "$(git rev-parse primary)" &&
269 test_cmp expect .git/rebase-merge/patch &&
270 test_cmp expect2 file1 &&
271 test "$(git diff --name-status |
272 sed -n -e "/^U/s/^U[^a-z]*//p")" = file1 &&
273 test 4 = $(grep -v "^#" < .git/rebase-merge/done | wc -l) &&
274 test 0 = $(grep -c "^[^#]" < .git/rebase-merge/git-rebase-todo)
277 test_expect_success
'show conflicted patch' '
278 GIT_TRACE=1 git rebase --show-current-patch >/dev/null 2>stderr &&
279 grep "show.*REBASE_HEAD" stderr &&
280 # the original stopped-sha1 is abbreviated
281 stopped_sha1="$(git rev-parse $(cat ".git/rebase-merge/stopped-sha"))" &&
282 test "$(git rev-parse REBASE_HEAD)" = "$stopped_sha1"
285 test_expect_success
'abort' '
286 git rebase --abort &&
287 test_cmp_rev new-branch1 HEAD &&
288 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
289 test_path_is_missing .git/rebase-merge
292 test_expect_success
'abort with error when new base cannot be checked out' '
293 git rm --cached file1 &&
294 git commit -m "remove file in base" &&
295 test_must_fail git rebase -i primary > output 2>&1 &&
296 test_i18ngrep "The following untracked working tree files would be overwritten by checkout:" \
298 test_i18ngrep "file1" output &&
299 test_path_is_missing .git/rebase-merge &&
300 git reset --hard HEAD^
303 test_expect_success
'retain authorship' '
307 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
309 git rebase -i --onto primary HEAD^ &&
310 git show HEAD | grep "^Author: Twerp Snog"
313 test_expect_success
'retain authorship w/ conflicts' '
314 oGIT_AUTHOR_NAME=$GIT_AUTHOR_NAME &&
315 test_when_finished "GIT_AUTHOR_NAME=\$oGIT_AUTHOR_NAME" &&
317 git reset --hard twerp &&
318 test_commit a conflict a conflict-a &&
319 git reset --hard twerp &&
321 GIT_AUTHOR_NAME=AttributeMe &&
322 export GIT_AUTHOR_NAME &&
323 test_commit b conflict b conflict-b &&
324 GIT_AUTHOR_NAME=$oGIT_AUTHOR_NAME &&
326 test_must_fail git rebase -i conflict-a &&
327 echo resolved >conflict &&
329 git rebase --continue &&
330 test_cmp_rev conflict-a^0 HEAD^ &&
335 test_expect_success
'squash' '
336 git reset --hard twerp &&
339 GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 &&
340 echo "******************************" &&
343 FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \
344 git rebase -i --onto primary HEAD~2
346 test B = $(cat file7) &&
347 test_cmp_rev HEAD^ primary
350 test_expect_success
'retain authorship when squashing' '
351 git show HEAD | grep "^Author: Twerp Snog"
354 test_expect_success REBASE_P
'-p handles "no changes" gracefully' '
355 HEAD=$(git rev-parse HEAD) &&
356 git rebase -i -p HEAD^ &&
357 git update-index --refresh &&
358 git diff-files --quiet &&
359 git diff-index --quiet --cached HEAD -- &&
360 test $HEAD = $(git rev-parse HEAD)
363 test_expect_failure REBASE_P
'exchange two commits with -p' '
367 FAKE_LINES="2 1" git rebase -i -p HEAD~2
369 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
370 test G = $(git cat-file commit HEAD | sed -ne \$p)
373 test_expect_success REBASE_P
'preserve merges with -p' '
374 git checkout -b to-be-preserved primary^ &&
375 : > unrelated-file &&
376 git add unrelated-file &&
378 git commit -m "unrelated" &&
379 git checkout -b another-branch primary &&
382 git commit -m J file1 &&
384 git merge to-be-preserved &&
387 git commit -m K file1 &&
390 git commit -m L1 file1 &&
391 git checkout HEAD^ &&
392 echo 1 > unrelated-file &&
394 git commit -m L2 unrelated-file &&
396 git merge another-branch &&
399 git commit -m M file1 &&
400 git checkout -b to-be-rebased &&
402 git rebase -i -p --onto branch1 primary &&
403 git update-index --refresh &&
404 git diff-files --quiet &&
405 git diff-index --quiet --cached HEAD -- &&
406 test_cmp_rev HEAD~6 branch1 &&
407 test_cmp_rev HEAD~4^2 to-be-preserved &&
408 test_cmp_rev HEAD^^2^ HEAD^^^ &&
409 test $(git show HEAD~5:file1) = B &&
410 test $(git show HEAD~3:file1) = C &&
411 test $(git show HEAD:file1) = E &&
412 test $(git show HEAD:unrelated-file) = 1
415 test_expect_success REBASE_P
'edit ancestor with -p' '
418 FAKE_LINES="1 2 edit 3 4" git rebase -i -p HEAD~3
420 echo 2 > unrelated-file &&
422 git commit -m L2-modified --amend unrelated-file &&
423 git rebase --continue &&
424 git update-index --refresh &&
425 git diff-files --quiet &&
426 git diff-index --quiet --cached HEAD -- &&
427 test $(git show HEAD:unrelated-file) = 2
430 test_expect_success
'--continue tries to commit' '
431 git reset --hard D &&
435 test_must_fail git rebase -i --onto new-branch1 HEAD^ &&
436 echo resolved > file1 &&
438 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue
440 test_cmp_rev HEAD^ new-branch1 &&
441 git show HEAD | grep chouette
444 test_expect_success
'verbose flag is heeded, even after --continue' '
445 git reset --hard primary@{1} &&
447 test_must_fail git rebase -v -i --onto new-branch1 HEAD^ &&
448 echo resolved > file1 &&
450 git rebase --continue > output &&
451 grep "^ file1 | 2 +-$" output
454 test_expect_success
'multi-squash only fires up editor once' '
455 base=$(git rev-parse HEAD~4) &&
458 FAKE_COMMIT_AMEND="ONCE" \
459 FAKE_LINES="1 squash 2 squash 3 squash 4" \
460 EXPECT_HEADER_COUNT=4 \
463 test $base = $(git rev-parse HEAD^) &&
464 test 1 = $(git show | grep ONCE | wc -l)
467 test_expect_success
'multi-fixup does not fire up editor' '
468 git checkout -b multi-fixup E &&
469 base=$(git rev-parse HEAD~4) &&
472 FAKE_COMMIT_AMEND="NEVER" \
473 FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \
476 test $base = $(git rev-parse HEAD^) &&
477 test 0 = $(git show | grep NEVER | wc -l) &&
478 git checkout @{-1} &&
479 git branch -D multi-fixup
482 test_expect_success
'commit message used after conflict' '
483 git checkout -b conflict-fixup conflict-branch &&
484 base=$(git rev-parse HEAD~4) &&
487 test_must_fail env FAKE_LINES="1 fixup 3 fixup 4" \
488 git rebase -i $base &&
489 echo three > conflict &&
491 FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \
492 git rebase --continue
494 test $base = $(git rev-parse HEAD^) &&
495 test 1 = $(git show | grep ONCE | wc -l) &&
496 git checkout @{-1} &&
497 git branch -D conflict-fixup
500 test_expect_success
'commit message retained after conflict' '
501 git checkout -b conflict-squash conflict-branch &&
502 base=$(git rev-parse HEAD~4) &&
505 test_must_fail env FAKE_LINES="1 fixup 3 squash 4" \
506 git rebase -i $base &&
507 echo three > conflict &&
509 FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \
510 git rebase --continue
512 test $base = $(git rev-parse HEAD^) &&
513 test 2 = $(git show | grep TWICE | wc -l) &&
514 git checkout @{-1} &&
515 git branch -D conflict-squash
518 test_expect_success
'squash and fixup generate correct log messages' '
519 cat >expect-squash-fixup <<-\EOF &&
526 git checkout -b squash-fixup E &&
527 base=$(git rev-parse HEAD~4) &&
530 FAKE_COMMIT_AMEND="ONCE" \
531 FAKE_LINES="1 fixup 2 squash 3 fixup 4" \
532 EXPECT_HEADER_COUNT=4 \
535 git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup &&
536 test_cmp expect-squash-fixup actual-squash-fixup &&
537 git cat-file commit HEAD@{2} |
538 grep "^# This is a combination of 3 commits\." &&
539 git cat-file commit HEAD@{3} |
540 grep "^# This is a combination of 2 commits\." &&
541 git checkout @{-1} &&
542 git branch -D squash-fixup
545 test_expect_success
'squash ignores comments' '
546 git checkout -b skip-comments E &&
547 base=$(git rev-parse HEAD~4) &&
550 FAKE_COMMIT_AMEND="ONCE" \
551 FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \
552 EXPECT_HEADER_COUNT=4 \
555 test $base = $(git rev-parse HEAD^) &&
556 test 1 = $(git show | grep ONCE | wc -l) &&
557 git checkout @{-1} &&
558 git branch -D skip-comments
561 test_expect_success
'squash ignores blank lines' '
562 git checkout -b skip-blank-lines E &&
563 base=$(git rev-parse HEAD~4) &&
566 FAKE_COMMIT_AMEND="ONCE" \
567 FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \
568 EXPECT_HEADER_COUNT=4 \
571 test $base = $(git rev-parse HEAD^) &&
572 test 1 = $(git show | grep ONCE | wc -l) &&
573 git checkout @{-1} &&
574 git branch -D skip-blank-lines
577 test_expect_success
'squash works as expected' '
578 git checkout -b squash-works no-conflict-branch &&
579 one=$(git rev-parse HEAD~3) &&
582 FAKE_LINES="1 s 3 2" EXPECT_HEADER_COUNT=2 git rebase -i HEAD~3
584 test $one = $(git rev-parse HEAD~2)
587 test_expect_success
'interrupted squash works as expected' '
588 git checkout -b interrupted-squash conflict-branch &&
589 one=$(git rev-parse HEAD~3) &&
592 test_must_fail env FAKE_LINES="1 squash 3 2" \
595 test_write_lines one two four > conflict &&
597 test_must_fail git rebase --continue &&
598 echo resolved > conflict &&
600 git rebase --continue &&
601 test $one = $(git rev-parse HEAD~2)
604 test_expect_success
'interrupted squash works as expected (case 2)' '
605 git checkout -b interrupted-squash2 conflict-branch &&
606 one=$(git rev-parse HEAD~3) &&
609 test_must_fail env FAKE_LINES="3 squash 1 2" \
612 test_write_lines one four > conflict &&
614 test_must_fail git rebase --continue &&
615 test_write_lines one two four > conflict &&
617 test_must_fail git rebase --continue &&
618 echo resolved > conflict &&
620 git rebase --continue &&
621 test $one = $(git rev-parse HEAD~2)
624 test_expect_success
'--continue tries to commit, even for "edit"' '
625 echo unrelated > file7 &&
628 git commit -m "unrelated change" &&
629 parent=$(git rev-parse HEAD^) &&
633 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
634 echo edited > file7 &&
636 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue
638 test edited = $(git show HEAD:file7) &&
639 git show HEAD | grep chouette &&
640 test $parent = $(git rev-parse HEAD^)
643 test_expect_success
'aborted --continue does not squash commits after "edit"' '
644 old=$(git rev-parse HEAD) &&
648 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
649 echo "edited again" > file7 &&
651 test_must_fail env FAKE_COMMIT_MESSAGE=" " git rebase --continue
653 test $old = $(git rev-parse HEAD) &&
657 test_expect_success
'auto-amend only edited commits after "edit"' '
661 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
662 echo "edited again" > file7 &&
664 FAKE_COMMIT_MESSAGE="edited file7 again" git commit &&
665 echo "and again" > file7 &&
668 test_must_fail env FAKE_COMMIT_MESSAGE="and again" \
669 git rebase --continue
674 test_expect_success
'clean error after failed "exec"' '
676 test_when_finished "git rebase --abort || :" &&
679 test_must_fail env FAKE_LINES="1 exec_false" git rebase -i HEAD^
681 echo "edited again" > file7 &&
683 test_must_fail git rebase --continue 2>error &&
684 test_i18ngrep "you have staged changes in your working tree" error
687 test_expect_success
'rebase a detached HEAD' '
688 grandparent=$(git rev-parse HEAD~2) &&
689 git checkout $(git rev-parse HEAD) &&
693 FAKE_LINES="2 1" git rebase -i HEAD~2
695 test $grandparent = $(git rev-parse HEAD~2)
698 test_expect_success
'rebase a commit violating pre-commit' '
700 mkdir -p .git/hooks &&
701 write_script .git/hooks/pre-commit <<-\EOF &&
702 test -z "$(git diff --cached --check)"
704 echo "monde! " >> file1 &&
706 test_must_fail git commit -m doesnt-verify file1 &&
707 git commit -m doesnt-verify --no-verify file1 &&
711 FAKE_LINES=2 git rebase -i HEAD~2
715 test_expect_success
'rebase with a file named HEAD in worktree' '
719 git checkout -b branch3 A &&
722 GIT_AUTHOR_NAME="Squashed Away" &&
723 export GIT_AUTHOR_NAME &&
726 git commit -m "Add head" &&
729 git commit -m "Add body"
734 FAKE_LINES="1 squash 2" git rebase -i @{-1}
736 test "$(git show -s --pretty=format:%an)" = "Squashed Away"
740 test_expect_success
'do "noop" when there is nothing to cherry-pick' '
742 git checkout -b branch4 HEAD &&
743 GIT_EDITOR=: git commit --amend \
744 --author="Somebody else <somebody@else.com>" &&
745 test $(git rev-parse branch3) != $(git rev-parse branch4) &&
746 git rebase -i branch3 &&
747 test_cmp_rev branch3 branch4
751 test_expect_success
'submodule rebase setup' '
755 cd sub && git init && >elif &&
756 git add elif && git commit -m "submodule initial"
761 git commit -m "One" &&
764 git commit -a -m "Two" &&
766 cd sub && echo 3 >elif &&
767 git commit -a -m "submodule second"
770 git commit -a -m "Three changes submodule"
773 test_expect_success
'submodule rebase -i' '
776 FAKE_LINES="1 squash 2 3" git rebase -i A
780 test_expect_success
'submodule conflict setup' '
781 git tag submodule-base &&
782 git checkout HEAD^ &&
784 cd sub && git checkout HEAD^ && echo 4 >elif &&
785 git add elif && git commit -m "submodule conflict"
789 git commit -m "Conflict in submodule" &&
790 git tag submodule-topic
793 test_expect_success
'rebase -i continue with only submodule staged' '
794 test_must_fail git rebase -i submodule-base &&
796 git rebase --continue &&
797 test $(git rev-parse submodule-base) != $(git rev-parse HEAD)
800 test_expect_success
'rebase -i continue with unstaged submodule' '
801 git checkout submodule-topic &&
803 test_must_fail git rebase -i submodule-base &&
805 git rebase --continue &&
806 test_cmp_rev submodule-base HEAD
809 test_expect_success
'avoid unnecessary reset' '
810 git checkout primary &&
812 test-tool chmtime =123456789 file3 &&
813 git update-index --refresh &&
814 HEAD=$(git rev-parse HEAD) &&
815 git rebase -i HEAD~4 &&
816 test $HEAD = $(git rev-parse HEAD) &&
817 MTIME=$(test-tool chmtime --get file3) &&
818 test 123456789 = $MTIME
821 test_expect_success
'reword' '
822 git checkout -b reword-branch primary &&
825 FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" \
827 git show HEAD | grep "E changed" &&
828 test $(git rev-parse primary) != $(git rev-parse HEAD) &&
829 test_cmp_rev primary^ HEAD^ &&
830 FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" \
832 git show HEAD^ | grep "D changed" &&
833 FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" \
835 git show HEAD~3 | grep "B changed" &&
836 FAKE_LINES="1 r 2 pick 3 p 4" FAKE_COMMIT_MESSAGE="C changed" \
839 git show HEAD~2 | grep "C changed"
842 test_expect_success
'rebase -i can copy notes' '
843 git config notes.rewrite.rebase true &&
844 git config notes.rewriteRef "refs/notes/*" &&
848 git notes add -m"a note" n3 &&
849 git rebase -i --onto n1 n2 &&
850 test "a note" = "$(git notes show HEAD)"
853 test_expect_success
'rebase -i can copy notes over a fixup' '
854 cat >expect <<-\EOF &&
859 git reset --hard n3 &&
860 git notes add -m"an earlier note" n2 &&
863 GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 f 2" \
866 git notes show > output &&
867 test_cmp expect output
870 test_expect_success
'rebase while detaching HEAD' '
871 git symbolic-ref HEAD &&
872 grandparent=$(git rev-parse HEAD~2) &&
876 FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0
878 test $grandparent = $(git rev-parse HEAD~2) &&
879 test_must_fail git symbolic-ref HEAD
882 test_tick
# Ensure that the rebased commits get a different timestamp.
883 test_expect_success
'always cherry-pick with --no-ff' '
884 git checkout no-ff-branch &&
885 git tag original-no-ff-branch &&
886 git rebase -i --no-ff A &&
889 test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) &&
890 git diff HEAD~$p original-no-ff-branch~$p > out &&
891 test_must_be_empty out
893 test_cmp_rev HEAD~3 original-no-ff-branch~3 &&
894 git diff HEAD~3 original-no-ff-branch~3 > out &&
895 test_must_be_empty out
898 test_expect_success
'set up commits with funny messages' '
899 git checkout -b funny A &&
902 git commit -a -m "end with slash\\" &&
905 git commit -a -m "something (\000) that looks like octal" &&
908 git commit -a -m "something (\n) that looks like a newline" &&
911 git commit -a -m "another commit"
914 test_expect_success
'rebase-i history with funny messages' '
915 git rev-list A..funny >expect &&
919 FAKE_LINES="1 2 3 4" git rebase -i A
921 git rev-list A.. >actual &&
922 test_cmp expect actual
925 test_expect_success
'prepare for rebase -i --exec' '
926 git checkout primary &&
927 git checkout -b execute &&
928 test_commit one_exec main.txt one_exec &&
929 test_commit two_exec main.txt two_exec &&
930 test_commit three_exec main.txt three_exec
933 test_expect_success
'running "git rebase -i --exec git show HEAD"' '
936 git rebase -i --exec "git show HEAD" HEAD~2 >actual &&
937 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
939 git rebase -i HEAD~2 >expect
941 sed -e "1,9d" expect >expected &&
942 test_cmp expected actual
945 test_expect_success
'running "git rebase --exec git show HEAD -i"' '
946 git reset --hard execute &&
949 git rebase --exec "git show HEAD" -i HEAD~2 >actual &&
950 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
952 git rebase -i HEAD~2 >expect
954 sed -e "1,9d" expect >expected &&
955 test_cmp expected actual
958 test_expect_success
'running "git rebase -ix git show HEAD"' '
959 git reset --hard execute &&
962 git rebase -ix "git show HEAD" HEAD~2 >actual &&
963 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
965 git rebase -i HEAD~2 >expect
967 sed -e "1,9d" expect >expected &&
968 test_cmp expected actual
972 test_expect_success
'rebase -ix with several <CMD>' '
973 git reset --hard execute &&
976 git rebase -ix "git show HEAD; pwd" HEAD~2 >actual &&
977 FAKE_LINES="1 exec_git_show_HEAD;_pwd 2 exec_git_show_HEAD;_pwd" &&
979 git rebase -i HEAD~2 >expect
981 sed -e "1,9d" expect >expected &&
982 test_cmp expected actual
985 test_expect_success
'rebase -ix with several instances of --exec' '
986 git reset --hard execute &&
989 git rebase -i --exec "git show HEAD" --exec "pwd" HEAD~2 >actual &&
990 FAKE_LINES="1 exec_git_show_HEAD exec_pwd 2
991 exec_git_show_HEAD exec_pwd" &&
993 git rebase -i HEAD~2 >expect
995 sed -e "1,11d" expect >expected &&
996 test_cmp expected actual
999 test_expect_success
'rebase -ix with --autosquash' '
1000 git reset --hard execute &&
1001 git checkout -b autosquash &&
1002 echo second >second.txt &&
1003 git add second.txt &&
1004 git commit -m "fixup! two_exec" &&
1005 echo bis >bis.txt &&
1007 git commit -m "fixup! two_exec" &&
1008 git checkout -b autosquash_actual &&
1009 git rebase -i --exec "git show HEAD" --autosquash HEAD~4 >actual &&
1010 git checkout autosquash &&
1013 git checkout -b autosquash_expected &&
1014 FAKE_LINES="1 fixup 3 fixup 4 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
1015 export FAKE_LINES &&
1016 git rebase -i HEAD~4 >expect
1018 sed -e "1,13d" expect >expected &&
1019 test_cmp expected actual
1022 test_expect_success
'rebase --exec works without -i ' '
1023 git reset --hard execute &&
1024 rm -rf exec_output &&
1025 EDITOR="echo >invoked_editor" git rebase --exec "echo a line >>exec_output" HEAD~2 2>actual &&
1026 test_i18ngrep "Successfully rebased and updated" actual &&
1027 test_line_count = 2 exec_output &&
1028 test_path_is_missing invoked_editor
1031 test_expect_success
'rebase -i --exec without <CMD>' '
1032 git reset --hard execute &&
1033 test_must_fail git rebase -i --exec 2>actual &&
1034 test_i18ngrep "requires a value" actual &&
1035 git checkout primary
1038 test_expect_success
'rebase -i --root re-order and drop commits' '
1042 FAKE_LINES="3 1 2 5" git rebase -i --root
1044 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1045 test B = $(git cat-file commit HEAD^ | sed -ne \$p) &&
1046 test A = $(git cat-file commit HEAD^^ | sed -ne \$p) &&
1047 test C = $(git cat-file commit HEAD^^^ | sed -ne \$p) &&
1048 test 0 = $(git cat-file commit HEAD^^^ | grep -c ^parent\ )
1051 test_expect_success
'rebase -i --root retain root commit author and message' '
1055 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
1058 FAKE_LINES="2" git rebase -i --root
1060 git cat-file commit HEAD | grep -q "^author Twerp Snog" &&
1061 git cat-file commit HEAD | grep -q "^different author$"
1064 test_expect_success
'rebase -i --root temporary sentinel commit' '
1068 test_must_fail env FAKE_LINES="2" git rebase -i --root
1070 git cat-file commit HEAD | grep "^tree $EMPTY_TREE" &&
1074 test_expect_success
'rebase -i --root fixup root commit' '
1078 FAKE_LINES="1 fixup 2" git rebase -i --root
1080 test A = $(git cat-file commit HEAD | sed -ne \$p) &&
1081 test B = $(git show HEAD:file1) &&
1082 test 0 = $(git cat-file commit HEAD | grep -c ^parent\ )
1085 test_expect_success
'rebase -i --root reword original root commit' '
1086 test_when_finished "test_might_fail git rebase --abort" &&
1087 git checkout -b reword-original-root-branch primary &&
1090 FAKE_LINES="reword 1 2" FAKE_COMMIT_MESSAGE="A changed" \
1091 git rebase -i --root
1093 git show HEAD^ | grep "A changed" &&
1094 test -z "$(git show -s --format=%p HEAD^)"
1097 test_expect_success
'rebase -i --root reword new root commit' '
1098 test_when_finished "test_might_fail git rebase --abort" &&
1099 git checkout -b reword-now-root-branch primary &&
1102 FAKE_LINES="reword 3 1" FAKE_COMMIT_MESSAGE="C changed" \
1103 git rebase -i --root
1105 git show HEAD^ | grep "C changed" &&
1106 test -z "$(git show -s --format=%p HEAD^)"
1109 test_expect_success
'rebase -i --root when root has untracked file conflict' '
1110 test_when_finished "reset_rebase" &&
1111 git checkout -b failing-root-pick A &&
1114 git commit -m "remove file 1 add file 2" &&
1118 test_must_fail env FAKE_LINES="1 2" git rebase -i --root
1121 git rebase --continue &&
1122 test "$(git log -1 --format=%B)" = "remove file 1 add file 2" &&
1123 test "$(git rev-list --count HEAD)" = 2
1126 test_expect_success
'rebase -i --root reword root when root has untracked file conflict' '
1127 test_when_finished "reset_rebase" &&
1131 test_must_fail env FAKE_LINES="reword 1 2" \
1132 FAKE_COMMIT_MESSAGE="Modified A" git rebase -i --root &&
1134 FAKE_COMMIT_MESSAGE="Reworded A" git rebase --continue
1136 test "$(git log -1 --format=%B HEAD^)" = "Reworded A" &&
1137 test "$(git rev-list --count HEAD)" = 2
1140 test_expect_success
'rebase --edit-todo does not work on non-interactive rebase' '
1141 git checkout reword-original-root-branch &&
1143 git checkout conflict-branch &&
1146 test_must_fail git rebase -f --apply --onto HEAD~2 HEAD~ &&
1147 test_must_fail git rebase --edit-todo
1152 test_expect_success
'rebase --edit-todo can be used to modify todo' '
1154 git checkout no-conflict-branch^0 &&
1157 FAKE_LINES="edit 1 2 3" git rebase -i HEAD~3 &&
1158 FAKE_LINES="2 1" git rebase --edit-todo &&
1159 git rebase --continue
1161 test M = $(git cat-file commit HEAD^ | sed -ne \$p) &&
1162 test L = $(git cat-file commit HEAD | sed -ne \$p)
1165 test_expect_success
'rebase -i produces readable reflog' '
1167 git branch -f branch-reflog-test H &&
1168 git rebase -i --onto I F branch-reflog-test &&
1169 cat >expect <<-\EOF &&
1170 rebase (finish): returning to refs/heads/branch-reflog-test
1173 rebase (start): checkout I
1175 git reflog -n4 HEAD |
1176 sed "s/[^:]*: //" >actual &&
1177 test_cmp expect actual
1180 test_expect_success
'rebase -i respects core.commentchar' '
1183 test_config core.commentchar "\\" &&
1184 write_script remove-all-but-first.sh <<-\EOF &&
1185 sed -e "2,\$s/^/\\\\/" "$1" >"$1.tmp" &&
1189 test_set_editor "$(pwd)/remove-all-but-first.sh" &&
1192 test B = $(git cat-file commit HEAD^ | sed -ne \$p)
1195 test_expect_success
'rebase -i respects core.commentchar=auto' '
1196 test_config core.commentchar auto &&
1197 write_script copy-edit-script.sh <<-\EOF &&
1200 test_when_finished "git rebase --abort || :" &&
1202 test_set_editor "$(pwd)/copy-edit-script.sh" &&
1205 test -z "$(grep -ve "^#" -e "^\$" -e "^pick" edit-script)"
1208 test_expect_success
'rebase -i, with <onto> and <upstream> specified as :/quuxery' '
1209 test_when_finished "git branch -D torebase" &&
1210 git checkout -b torebase branch1 &&
1211 upstream=$(git rev-parse ":/J") &&
1212 onto=$(git rev-parse ":/A") &&
1213 git rebase --onto $onto $upstream &&
1214 git reset --hard branch1 &&
1215 git rebase --onto ":/A" ":/J" &&
1216 git checkout branch1
1219 test_expect_success
'rebase -i with --strategy and -X' '
1220 git checkout -b conflict-merge-use-theirs conflict-branch &&
1221 git reset --hard HEAD^ &&
1222 echo five >conflict &&
1224 git commit -a -m "one file conflict" &&
1225 EDITOR=true git rebase -i --strategy=recursive -Xours conflict-branch &&
1226 test $(git show conflict-branch:conflict) = $(cat conflict) &&
1227 test $(cat file1) = Z
1230 test_expect_success
'interrupted rebase -i with --strategy and -X' '
1231 git checkout -b conflict-merge-use-theirs-interrupted conflict-branch &&
1232 git reset --hard HEAD^ &&
1234 git add breakpoint &&
1235 git commit -m "breakpoint for interactive mode" &&
1236 echo five >conflict &&
1238 git commit -a -m "one file conflict" &&
1241 FAKE_LINES="edit 1 2" git rebase -i --strategy=recursive \
1242 -Xours conflict-branch
1244 git rebase --continue &&
1245 test $(git show conflict-branch:conflict) = $(cat conflict) &&
1246 test $(cat file1) = Z
1249 test_expect_success
'rebase -i error on commits with \ in message' '
1250 current_head=$(git rev-parse HEAD) &&
1251 test_when_finished "git rebase --abort; git reset --hard $current_head; rm -f error" &&
1252 test_commit TO-REMOVE will-conflict old-content &&
1253 test_commit "\temp" will-conflict new-content dummy &&
1254 test_must_fail env EDITOR=true git rebase -i HEAD^ --onto HEAD^^ 2>error &&
1255 test_expect_code 1 grep " emp" error
1258 test_expect_success
'short commit ID setup' '
1259 test_when_finished "git checkout primary" &&
1260 git checkout --orphan collide &&
1264 test_commit collide1 collide &&
1265 test_commit --notick collide2 collide &&
1266 test_commit --notick collide3 collide
1270 if test -n "$GIT_TEST_FIND_COLLIDER"
1272 author
="$(unset test_tick; test_tick; git var GIT_AUTHOR_IDENT)"
1273 committer
="$(unset test_tick; test_tick; git var GIT_COMMITTER_IDENT)"
1274 blob
="$(git rev-parse collide2:collide)"
1275 from
="$(git rev-parse collide1^0)"
1276 repl
="commit refs/heads/collider-&\\n"
1277 repl
="${repl}author $author\\ncommitter $committer\\n"
1278 repl
="${repl}data <<EOF\\ncollide2 &\\nEOF\\n"
1279 repl
="${repl}from $from\\nM 100644 $blob collide\\n"
1280 test_seq
1 32768 |
sed "s|.*|$repl|" >script &&
1281 git fast-import
<script &&
1283 git for-each-ref
>refs
&&
1284 grep "^$(test_oid t3404_collision)" <refs
>matches
&&
1286 test_line_count
-gt 2 matches ||
{
1287 echo "Could not find a collider" >&2
1292 test_expect_success
'short commit ID collide' '
1293 test_oid_cache <<-EOF &&
1294 # collision-related constants
1295 t3404_collision sha1:6bcd
1296 t3404_collision sha256:0161
1297 t3404_collider sha1:ac4f2ee
1298 t3404_collider sha256:16697
1300 test_when_finished "reset_rebase && git checkout primary" &&
1301 git checkout collide &&
1302 colliding_id=$(test_oid t3404_collision) &&
1303 hexsz=$(test_oid hexsz) &&
1304 test $colliding_id = "$(git rev-parse HEAD | cut -c 1-4)" &&
1305 test_config core.abbrev 4 &&
1310 FAKE_COMMIT_MESSAGE="collide2 $(test_oid t3404_collider)" \
1311 FAKE_LINES="reword 1 break 2" git rebase -i HEAD~2 &&
1312 test $colliding_id = "$(git rev-parse HEAD | cut -c 1-4)" &&
1313 grep "^pick $colliding_id " \
1314 .git/rebase-merge/git-rebase-todo.tmp &&
1315 grep "^pick [0-9a-f]\{$hexsz\}" \
1316 .git/rebase-merge/git-rebase-todo &&
1317 grep "^pick [0-9a-f]\{$hexsz\}" \
1318 .git/rebase-merge/git-rebase-todo.backup &&
1319 git rebase --continue
1321 collide2="$(git rev-parse HEAD~1 | cut -c 1-4)" &&
1322 collide3="$(git rev-parse collide3 | cut -c 1-4)" &&
1323 test "$collide2" = "$collide3"
1326 test_expect_success
'respect core.abbrev' '
1327 git config core.abbrev 12 &&
1329 set_cat_todo_editor &&
1330 test_must_fail git rebase -i HEAD~4 >todo-list
1332 test 4 = $(grep -c "pick [0-9a-f]\{12,\}" todo-list)
1335 test_expect_success
'todo count' '
1336 write_script dump-raw.sh <<-\EOF &&
1340 test_set_editor "$(pwd)/dump-raw.sh" &&
1341 git rebase -i HEAD~4 >actual
1343 test_i18ngrep "^# Rebase ..* onto ..* ([0-9]" actual
1346 test_expect_success
'rebase -i commits that overwrite untracked files (pick)' '
1347 git checkout --force branch2 &&
1351 FAKE_LINES="edit 1 2" git rebase -i A
1353 test_cmp_rev HEAD F &&
1354 test_path_is_missing file6 &&
1356 test_must_fail git rebase --continue &&
1357 test_cmp_rev HEAD F &&
1359 git rebase --continue &&
1363 test_expect_success
'rebase -i commits that overwrite untracked files (squash)' '
1364 git checkout --force branch2 &&
1366 git tag original-branch2 &&
1369 FAKE_LINES="edit 1 squash 2" git rebase -i A
1371 test_cmp_rev HEAD F &&
1372 test_path_is_missing file6 &&
1374 test_must_fail git rebase --continue &&
1375 test_cmp_rev HEAD F &&
1377 git rebase --continue &&
1378 test $(git cat-file commit HEAD | sed -ne \$p) = I &&
1379 git reset --hard original-branch2
1382 test_expect_success
'rebase -i commits that overwrite untracked files (no ff)' '
1383 git checkout --force branch2 &&
1387 FAKE_LINES="edit 1 2" git rebase -i --no-ff A
1389 test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1390 test_path_is_missing file6 &&
1392 test_must_fail git rebase --continue &&
1393 test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1395 git rebase --continue &&
1396 test $(git cat-file commit HEAD | sed -ne \$p) = I
1399 test_expect_success
'rebase --continue removes CHERRY_PICK_HEAD' '
1400 git checkout -b commit-to-skip &&
1403 test_seq 5 | sed "s/$double/&&/" >seq &&
1406 git commit -m seq-$double
1409 git reset --hard HEAD~2 &&
1410 git cherry-pick seq-onto &&
1413 test_must_fail env FAKE_LINES= git rebase -i seq-onto
1415 test -d .git/rebase-merge &&
1416 git rebase --continue &&
1417 git diff --exit-code seq-onto &&
1418 test ! -d .git/rebase-merge &&
1419 test ! -f .git/CHERRY_PICK_HEAD
1422 rebase_setup_and_clean
() {
1423 test_when_finished
"
1424 git checkout primary &&
1425 test_might_fail git branch -D $1 &&
1426 test_might_fail git rebase --abort
1428 git checkout
-b $1 ${2:-primary}
1431 test_expect_success
'drop' '
1432 rebase_setup_and_clean drop-test &&
1435 FAKE_LINES="1 drop 2 3 d 4 5" git rebase -i --root
1437 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1438 test C = $(git cat-file commit HEAD^ | sed -ne \$p) &&
1439 test A = $(git cat-file commit HEAD^^ | sed -ne \$p)
1442 test_expect_success
'rebase -i respects rebase.missingCommitsCheck = ignore' '
1443 test_config rebase.missingCommitsCheck ignore &&
1444 rebase_setup_and_clean missing-commit &&
1447 FAKE_LINES="1 2 3 4" git rebase -i --root 2>actual
1449 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1451 "Successfully rebased and updated refs/heads/missing-commit" \
1455 test_expect_success
'rebase -i respects rebase.missingCommitsCheck = warn' '
1456 cat >expect <<-EOF &&
1457 Warning: some commits may have been dropped accidentally.
1458 Dropped commits (newer to older):
1459 - $(git rev-list --pretty=oneline --abbrev-commit -1 primary)
1460 To avoid this message, use "drop" to explicitly remove a commit.
1462 test_config rebase.missingCommitsCheck warn &&
1463 rebase_setup_and_clean missing-commit &&
1466 FAKE_LINES="1 2 3 4" git rebase -i --root 2>actual.2
1468 head -n4 actual.2 >actual &&
1469 test_cmp expect actual &&
1470 test D = $(git cat-file commit HEAD | sed -ne \$p)
1473 test_expect_success
'rebase -i respects rebase.missingCommitsCheck = error' '
1474 cat >expect <<-EOF &&
1475 Warning: some commits may have been dropped accidentally.
1476 Dropped commits (newer to older):
1477 - $(git rev-list --pretty=oneline --abbrev-commit -1 primary)
1478 - $(git rev-list --pretty=oneline --abbrev-commit -1 primary~2)
1479 To avoid this message, use "drop" to explicitly remove a commit.
1481 Use '\''git config rebase.missingCommitsCheck'\'' to change the level of warnings.
1482 The possible behaviours are: ignore, warn, error.
1484 You can fix this with '\''git rebase --edit-todo'\'' and then run '\''git rebase --continue'\''.
1485 Or you can abort the rebase with '\''git rebase --abort'\''.
1487 test_config rebase.missingCommitsCheck error &&
1488 rebase_setup_and_clean missing-commit &&
1491 test_must_fail env FAKE_LINES="1 2 4" \
1492 git rebase -i --root 2>actual &&
1493 test_cmp expect actual &&
1494 cp .git/rebase-merge/git-rebase-todo.backup \
1495 .git/rebase-merge/git-rebase-todo &&
1496 FAKE_LINES="1 2 drop 3 4 drop 5" git rebase --edit-todo
1498 git rebase --continue &&
1499 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1500 test B = $(git cat-file commit HEAD^ | sed -ne \$p)
1503 test_expect_success
'rebase --edit-todo respects rebase.missingCommitsCheck = ignore' '
1504 test_config rebase.missingCommitsCheck ignore &&
1505 rebase_setup_and_clean missing-commit &&
1508 FAKE_LINES="break 1 2 3 4 5" git rebase -i --root &&
1509 FAKE_LINES="1 2 3 4" git rebase --edit-todo &&
1510 git rebase --continue 2>actual
1512 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1514 "Successfully rebased and updated refs/heads/missing-commit" \
1518 test_expect_success
'rebase --edit-todo respects rebase.missingCommitsCheck = warn' '
1519 cat >expect <<-EOF &&
1520 error: invalid line 1: badcmd $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4)
1521 Warning: some commits may have been dropped accidentally.
1522 Dropped commits (newer to older):
1523 - $(git rev-list --pretty=oneline --abbrev-commit -1 primary)
1524 - $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4)
1525 To avoid this message, use "drop" to explicitly remove a commit.
1527 head -n4 expect >expect.2 &&
1528 tail -n1 expect >>expect.2 &&
1529 tail -n4 expect.2 >expect.3 &&
1530 test_config rebase.missingCommitsCheck warn &&
1531 rebase_setup_and_clean missing-commit &&
1534 test_must_fail env FAKE_LINES="bad 1 2 3 4 5" \
1535 git rebase -i --root &&
1536 cp .git/rebase-merge/git-rebase-todo.backup orig &&
1537 FAKE_LINES="2 3 4" git rebase --edit-todo 2>actual.2 &&
1538 head -n6 actual.2 >actual &&
1539 test_cmp expect actual &&
1540 cp orig .git/rebase-merge/git-rebase-todo &&
1541 FAKE_LINES="1 2 3 4" git rebase --edit-todo 2>actual.2 &&
1542 head -n4 actual.2 >actual &&
1543 test_cmp expect.3 actual &&
1544 git rebase --continue 2>actual
1546 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1548 "Successfully rebased and updated refs/heads/missing-commit" \
1552 test_expect_success
'rebase --edit-todo respects rebase.missingCommitsCheck = error' '
1553 cat >expect <<-EOF &&
1554 error: invalid line 1: badcmd $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4)
1555 Warning: some commits may have been dropped accidentally.
1556 Dropped commits (newer to older):
1557 - $(git rev-list --pretty=oneline --abbrev-commit -1 primary)
1558 - $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4)
1559 To avoid this message, use "drop" to explicitly remove a commit.
1561 Use '\''git config rebase.missingCommitsCheck'\'' to change the level of warnings.
1562 The possible behaviours are: ignore, warn, error.
1564 You can fix this with '\''git rebase --edit-todo'\'' and then run '\''git rebase --continue'\''.
1565 Or you can abort the rebase with '\''git rebase --abort'\''.
1567 tail -n11 expect >expect.2 &&
1568 head -n3 expect.2 >expect.3 &&
1569 tail -n7 expect.2 >>expect.3 &&
1570 test_config rebase.missingCommitsCheck error &&
1571 rebase_setup_and_clean missing-commit &&
1574 test_must_fail env FAKE_LINES="bad 1 2 3 4 5" \
1575 git rebase -i --root &&
1576 cp .git/rebase-merge/git-rebase-todo.backup orig &&
1577 test_must_fail env FAKE_LINES="2 3 4" \
1578 git rebase --edit-todo 2>actual &&
1579 test_cmp expect actual &&
1580 test_must_fail git rebase --continue 2>actual &&
1581 test_cmp expect.2 actual &&
1582 test_must_fail git rebase --edit-todo &&
1583 cp orig .git/rebase-merge/git-rebase-todo &&
1584 test_must_fail env FAKE_LINES="1 2 3 4" \
1585 git rebase --edit-todo 2>actual &&
1586 test_cmp expect.3 actual &&
1587 test_must_fail git rebase --continue 2>actual &&
1588 test_cmp expect.3 actual &&
1589 cp orig .git/rebase-merge/git-rebase-todo &&
1590 FAKE_LINES="1 2 3 4 drop 5" git rebase --edit-todo &&
1591 git rebase --continue 2>actual
1593 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1595 "Successfully rebased and updated refs/heads/missing-commit" \
1599 test_expect_success
'rebase.missingCommitsCheck = error after resolving conflicts' '
1600 test_config rebase.missingCommitsCheck error &&
1603 FAKE_LINES="drop 1 break 2 3 4" git rebase -i A E
1605 git rebase --edit-todo &&
1606 test_must_fail git rebase --continue &&
1609 git rebase --continue
1612 test_expect_success
'rebase.missingCommitsCheck = error when editing for a second time' '
1613 test_config rebase.missingCommitsCheck error &&
1616 FAKE_LINES="1 break 2 3" git rebase -i A D &&
1617 cp .git/rebase-merge/git-rebase-todo todo &&
1618 test_must_fail env FAKE_LINES=2 git rebase --edit-todo &&
1619 GIT_SEQUENCE_EDITOR="cp todo" git rebase --edit-todo &&
1620 git rebase --continue
1624 test_expect_success
'respects rebase.abbreviateCommands with fixup, squash and exec' '
1625 rebase_setup_and_clean abbrevcmd &&
1626 test_commit "first" file1.txt "first line" first &&
1627 test_commit "second" file1.txt "another line" second &&
1628 test_commit "fixup! first" file2.txt "first line again" first_fixup &&
1629 test_commit "squash! second" file1.txt "another line here" second_squash &&
1630 cat >expected <<-EOF &&
1631 p $(git rev-list --abbrev-commit -1 first) first
1632 f $(git rev-list --abbrev-commit -1 first_fixup) fixup! first
1634 p $(git rev-list --abbrev-commit -1 second) second
1635 s $(git rev-list --abbrev-commit -1 second_squash) squash! second
1638 git checkout abbrevcmd &&
1639 test_config rebase.abbreviateCommands true &&
1641 set_cat_todo_editor &&
1642 test_must_fail git rebase -i --exec "git show HEAD" \
1643 --autosquash primary >actual
1645 test_cmp expected actual
1648 test_expect_success
'static check of bad command' '
1649 rebase_setup_and_clean bad-cmd &&
1652 test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \
1653 git rebase -i --root 2>actual &&
1654 test_i18ngrep "badcmd $(git rev-list --oneline -1 primary~1)" \
1656 test_i18ngrep "You can fix this with .git rebase --edit-todo.." \
1658 FAKE_LINES="1 2 3 drop 4 5" git rebase --edit-todo
1660 git rebase --continue &&
1661 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1662 test C = $(git cat-file commit HEAD^ | sed -ne \$p)
1665 test_expect_success
'tabs and spaces are accepted in the todolist' '
1666 rebase_setup_and_clean indented-comment &&
1667 write_script add-indent.sh <<-\EOF &&
1669 # Turn single spaces into space/tab mix
1670 sed "1s/ / /g; 2s/ / /g; 3s/ / /g" "$1"
1671 printf "\n\t# comment\n #more\n\t # comment\n"
1676 test_set_editor "$(pwd)/add-indent.sh" &&
1677 git rebase -i HEAD^^^
1679 test E = $(git cat-file commit HEAD | sed -ne \$p)
1682 test_expect_success
'static check of bad SHA-1' '
1683 rebase_setup_and_clean bad-sha &&
1686 test_must_fail env FAKE_LINES="1 2 edit fakesha 3 4 5 #" \
1687 git rebase -i --root 2>actual &&
1688 test_i18ngrep "edit XXXXXXX False commit" actual &&
1689 test_i18ngrep "You can fix this with .git rebase --edit-todo.." \
1691 FAKE_LINES="1 2 4 5 6" git rebase --edit-todo
1693 git rebase --continue &&
1694 test E = $(git cat-file commit HEAD | sed -ne \$p)
1697 test_expect_success
'editor saves as CR/LF' '
1698 git checkout -b with-crlf &&
1699 write_script add-crs.sh <<-\EOF &&
1700 sed -e "s/\$/Q/" <"$1" | tr Q "\\015" >"$1".new &&
1704 test_set_editor "$(pwd)/add-crs.sh" &&
1709 test_expect_success
'rebase -i --gpg-sign=<key-id>' '
1710 test_when_finished "test_might_fail git rebase --abort" &&
1713 FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" \
1716 test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err
1719 test_expect_success
'rebase -i --gpg-sign=<key-id> overrides commit.gpgSign' '
1720 test_when_finished "test_might_fail git rebase --abort" &&
1721 test_config commit.gpgsign true &&
1724 FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" \
1727 test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err
1730 test_expect_success
'valid author header after --root swap' '
1731 rebase_setup_and_clean author-header no-conflict-branch &&
1732 git commit --amend --author="Au ${SQ}thor <author@example.com>" --no-edit &&
1733 git cat-file commit HEAD | grep ^author >expected &&
1736 FAKE_LINES="5 1" git rebase -i --root
1738 git cat-file commit HEAD^ | grep ^author >actual &&
1739 test_cmp expected actual
1742 test_expect_success
'valid author header when author contains single quote' '
1743 rebase_setup_and_clean author-header no-conflict-branch &&
1744 git commit --amend --author="Au ${SQ}thor <author@example.com>" --no-edit &&
1745 git cat-file commit HEAD | grep ^author >expected &&
1748 FAKE_LINES="2" git rebase -i HEAD~2
1750 git cat-file commit HEAD | grep ^author >actual &&
1751 test_cmp expected actual
1754 test_expect_success
'post-commit hook is called' '
1755 test_when_finished "rm -f .git/hooks/post-commit" &&
1757 mkdir -p .git/hooks &&
1758 write_script .git/hooks/post-commit <<-\EOS &&
1759 git rev-parse HEAD >>actual
1763 FAKE_LINES="edit 4 1 reword 2 fixup 3" git rebase -i A E &&
1766 FAKE_COMMIT_MESSAGE=edited git rebase --continue
1768 git rev-parse HEAD@{5} HEAD@{4} HEAD@{3} HEAD@{2} HEAD@{1} HEAD \
1770 test_cmp expect actual
1773 test_expect_success
'correct error message for partial commit after empty pick' '
1774 test_when_finished "git rebase --abort" &&
1777 FAKE_LINES="2 1 1" &&
1778 export FAKE_LINES &&
1779 test_must_fail git rebase -i A D
1782 test_must_fail git commit file1 2>err &&
1783 test_i18ngrep "cannot do a partial commit during a rebase." err
1786 test_expect_success
'correct error message for commit --amend after empty pick' '
1787 test_when_finished "git rebase --abort" &&
1791 export FAKE_LINES &&
1792 test_must_fail git rebase -i A D
1795 test_must_fail git commit -a --amend 2>err &&
1796 test_i18ngrep "middle of a rebase -- cannot amend." err
1799 test_expect_success
'todo has correct onto hash' '
1800 GIT_SEQUENCE_EDITOR=cat git rebase -i no-conflict-branch~4 no-conflict-branch >actual &&
1801 onto=$(git rev-parse --short HEAD~4) &&
1802 test_i18ngrep "^# Rebase ..* onto $onto" actual
1805 test_expect_success
'ORIG_HEAD is updated correctly' '
1806 test_when_finished "git checkout primary && git branch -D test-orig-head" &&
1807 git checkout -b test-orig-head A &&
1808 git commit --allow-empty -m A1 &&
1809 git commit --allow-empty -m A2 &&
1810 git commit --allow-empty -m A3 &&
1811 git commit --allow-empty -m A4 &&
1812 git rebase primary &&
1813 test_cmp_rev ORIG_HEAD test-orig-head@{1}
1816 # This must be the last test in this file
1817 test_expect_success
'$EDITOR and friends are unchanged' '
1818 test_editor_unchanged