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".
30 . "$TEST_DIRECTORY"/lib-rebase.sh
32 test_expect_success 'setup' '
33 git switch -C primary &&
34 test_commit A file1 &&
35 test_commit B file1 &&
36 test_commit C file2 &&
37 test_commit D file1 &&
38 test_commit E file3 &&
39 git checkout -b branch1 A &&
40 test_commit F file4 &&
41 test_commit G file1 &&
42 test_commit H file5 &&
43 git checkout -b branch2 F &&
44 test_commit I file6 &&
45 git checkout -b conflict-branch A &&
46 test_commit one conflict &&
47 test_commit two conflict &&
48 test_commit three conflict &&
49 test_commit four conflict &&
50 git checkout -b no-conflict-branch A &&
51 test_commit J fileJ &&
52 test_commit K fileK &&
53 test_commit L fileL &&
54 test_commit M fileM &&
55 git checkout -b no-ff-branch A &&
56 test_commit N fileN &&
57 test_commit O fileO &&
61 # "exec" commands are run with the user shell by default, but this may
62 # be non-POSIX. For example, if SHELL=zsh then ">file" doesn't work
63 # to create a file. Unsetting SHELL avoids such non-portable behavior
64 # in tests. It must be exported for it to take effect where needed.
68 test_expect_success 'rebase --keep-empty' '
69 git checkout -b emptybranch primary &&
70 git commit --allow-empty -m "empty" &&
71 git rebase --keep-empty -i HEAD~2 &&
72 git log --oneline >actual &&
73 test_line_count = 6 actual
76 test_expect_success 'rebase -i with empty todo list' '
77 cat >expect <<-\EOF &&
82 test_must_fail env FAKE_LINES="#" \
83 git rebase -i HEAD^ >output 2>&1
85 tail -n 1 output >actual && # Ignore output about changing todo list
86 test_i18ncmp expect actual
89 test_expect_success 'rebase -i with the exec command' '
90 git checkout primary &&
93 FAKE_LINES="1 exec_>touch-one
94 2 exec_>touch-two exec_false exec_>touch-three
95 3 4 exec_>\"touch-file__name_with_spaces\";_>touch-after-semicolon 5" &&
97 test_must_fail git rebase -i A
99 test_path_is_file touch-one &&
100 test_path_is_file touch-two &&
101 test_path_is_missing touch-three " (should have stopped before)" &&
102 test_cmp_rev C HEAD &&
103 git rebase --continue &&
104 test_path_is_file touch-three &&
105 test_path_is_file "touch-file name with spaces" &&
106 test_path_is_file touch-after-semicolon &&
107 test_cmp_rev primary HEAD &&
111 test_expect_success 'rebase -i with the exec command runs from tree root' '
112 git checkout primary &&
113 mkdir subdir && (cd subdir &&
115 FAKE_LINES="1 exec_>touch-subdir" \
118 test_path_is_file touch-subdir &&
122 test_expect_success 'rebase -i with exec allows git commands in subdirs' '
123 test_when_finished "rm -rf subdir" &&
124 test_when_finished "git rebase --abort ||:" &&
125 git checkout primary &&
126 mkdir subdir && (cd subdir &&
128 FAKE_LINES="1 x_cd_subdir_&&_git_rev-parse_--is-inside-work-tree" \
133 test_expect_success 'rebase -i sets work tree properly' '
134 test_when_finished "rm -rf subdir" &&
135 test_when_finished "test_might_fail git rebase --abort" &&
137 git rebase -x "(cd subdir && git rev-parse --show-toplevel)" HEAD^ \
139 ! grep "/subdir$" actual
142 test_expect_success 'rebase -i with the exec command checks tree cleanness' '
143 git checkout primary &&
146 test_must_fail env FAKE_LINES="exec_echo_foo_>file1 1" \
149 test_cmp_rev primary^ HEAD &&
151 git rebase --continue
154 test_expect_success 'rebase -x with empty command fails' '
155 test_when_finished "git rebase --abort ||:" &&
156 test_must_fail env git rebase -x "" @ 2>actual &&
157 test_write_lines "error: empty exec command" >expected &&
158 test_i18ncmp expected actual &&
159 test_must_fail env git rebase -x " " @ 2>actual &&
160 test_i18ncmp expected actual
163 test_expect_success 'rebase -x with newline in command fails' '
164 test_when_finished "git rebase --abort ||:" &&
165 test_must_fail env git rebase -x "a${LF}b" @ 2>actual &&
166 test_write_lines "error: exec commands cannot contain newlines" \
168 test_i18ncmp expected actual
171 test_expect_success 'rebase -i with exec of inexistent command' '
172 git checkout primary &&
173 test_when_finished "git rebase --abort" &&
176 test_must_fail env FAKE_LINES="exec_this-command-does-not-exist 1" \
177 git rebase -i HEAD^ >actual 2>&1
179 ! grep "Maybe git-rebase is broken" actual
182 test_expect_success 'implicit interactive rebase does not invoke sequence editor' '
183 test_when_finished "git rebase --abort ||:" &&
184 GIT_SEQUENCE_EDITOR="echo bad >" git rebase -x"echo one" @^
187 test_expect_success 'no changes are a nop' '
188 git checkout branch2 &&
190 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
194 test_expect_success 'test the [branch] option' '
195 git checkout -b dead-end &&
197 git commit -m "stop here" &&
198 git rebase -i F branch2 &&
199 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
200 test_cmp_rev I branch2 &&
204 test_expect_success 'test --onto <branch>' '
205 git checkout -b test-onto branch2 &&
206 git rebase -i --onto branch1 F &&
207 test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" &&
208 test_cmp_rev HEAD^ branch1 &&
209 test_cmp_rev I branch2
212 test_expect_success 'rebase on top of a non-conflicting commit' '
213 git checkout branch1 &&
214 git tag original-branch1 &&
215 git rebase -i branch2 &&
216 test file6 = $(git diff --name-only original-branch1) &&
217 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
218 test_cmp_rev I branch2 &&
219 test_cmp_rev I HEAD~2
222 test_expect_success 'reflog for the branch shows state before rebase' '
223 test_cmp_rev branch1@{1} original-branch1
226 test_expect_success 'reflog for the branch shows correct finish message' '
227 printf "rebase (finish): refs/heads/branch1 onto %s\n" \
228 "$(git rev-parse branch2)" >expected &&
229 git log -g --pretty=%gs -1 refs/heads/branch1 >actual &&
230 test_cmp expected actual
233 test_expect_success 'exchange two commits' '
236 FAKE_LINES="2 1" git rebase -i HEAD~2
238 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
239 test G = $(git cat-file commit HEAD | sed -ne \$p) &&
240 blob1=$(git rev-parse --short HEAD^:file1) &&
241 blob2=$(git rev-parse --short HEAD:file1) &&
242 commit=$(git rev-parse --short HEAD)
245 test_expect_success 'stop on conflicting pick' '
246 cat >expect <<-EOF &&
247 diff --git a/file1 b/file1
248 index $blob1..$blob2 100644
255 cat >expect2 <<-EOF &&
262 git tag new-branch1 &&
263 test_must_fail git rebase -i primary &&
264 test "$(git rev-parse HEAD~3)" = "$(git rev-parse primary)" &&
265 test_cmp expect .git/rebase-merge/patch &&
266 test_cmp expect2 file1 &&
267 test "$(git diff --name-status |
268 sed -n -e "/^U/s/^U[^a-z]*//p")" = file1 &&
269 test 4 = $(grep -v "^#" < .git/rebase-merge/done | wc -l) &&
270 test 0 = $(grep -c "^[^#]" < .git/rebase-merge/git-rebase-todo)
273 test_expect_success 'show conflicted patch' '
274 GIT_TRACE=1 git rebase --show-current-patch >/dev/null 2>stderr &&
275 grep "show.*REBASE_HEAD" stderr &&
276 # the original stopped-sha1 is abbreviated
277 stopped_sha1="$(git rev-parse $(cat ".git/rebase-merge/stopped-sha"))" &&
278 test "$(git rev-parse REBASE_HEAD)" = "$stopped_sha1"
281 test_expect_success 'abort' '
282 git rebase --abort &&
283 test_cmp_rev new-branch1 HEAD &&
284 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
285 test_path_is_missing .git/rebase-merge
288 test_expect_success 'abort with error when new base cannot be checked out' '
289 git rm --cached file1 &&
290 git commit -m "remove file in base" &&
291 test_must_fail git rebase -i primary > output 2>&1 &&
292 test_i18ngrep "The following untracked working tree files would be overwritten by checkout:" \
294 test_i18ngrep "file1" output &&
295 test_path_is_missing .git/rebase-merge &&
296 git reset --hard HEAD^
299 test_expect_success 'retain authorship' '
303 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
305 git rebase -i --onto primary HEAD^ &&
306 git show HEAD | grep "^Author: Twerp Snog"
309 test_expect_success 'retain authorship w/ conflicts' '
310 oGIT_AUTHOR_NAME=$GIT_AUTHOR_NAME &&
311 test_when_finished "GIT_AUTHOR_NAME=\$oGIT_AUTHOR_NAME" &&
313 git reset --hard twerp &&
314 test_commit a conflict a conflict-a &&
315 git reset --hard twerp &&
317 GIT_AUTHOR_NAME=AttributeMe &&
318 export GIT_AUTHOR_NAME &&
319 test_commit b conflict b conflict-b &&
320 GIT_AUTHOR_NAME=$oGIT_AUTHOR_NAME &&
322 test_must_fail git rebase -i conflict-a &&
323 echo resolved >conflict &&
325 git rebase --continue &&
326 test_cmp_rev conflict-a^0 HEAD^ &&
331 test_expect_success 'squash' '
332 git reset --hard twerp &&
335 GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 &&
336 echo "******************************" &&
339 FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \
340 git rebase -i --onto primary HEAD~2
342 test B = $(cat file7) &&
343 test_cmp_rev HEAD^ primary
346 test_expect_success 'retain authorship when squashing' '
347 git show HEAD | grep "^Author: Twerp Snog"
350 test_expect_success REBASE_P '-p handles "no changes" gracefully' '
351 HEAD=$(git rev-parse HEAD) &&
352 git rebase -i -p HEAD^ &&
353 git update-index --refresh &&
354 git diff-files --quiet &&
355 git diff-index --quiet --cached HEAD -- &&
356 test $HEAD = $(git rev-parse HEAD)
359 test_expect_failure REBASE_P 'exchange two commits with -p' '
363 FAKE_LINES="2 1" git rebase -i -p HEAD~2
365 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
366 test G = $(git cat-file commit HEAD | sed -ne \$p)
369 test_expect_success REBASE_P 'preserve merges with -p' '
370 git checkout -b to-be-preserved primary^ &&
371 : > unrelated-file &&
372 git add unrelated-file &&
374 git commit -m "unrelated" &&
375 git checkout -b another-branch primary &&
378 git commit -m J file1 &&
380 git merge to-be-preserved &&
383 git commit -m K file1 &&
386 git commit -m L1 file1 &&
387 git checkout HEAD^ &&
388 echo 1 > unrelated-file &&
390 git commit -m L2 unrelated-file &&
392 git merge another-branch &&
395 git commit -m M file1 &&
396 git checkout -b to-be-rebased &&
398 git rebase -i -p --onto branch1 primary &&
399 git update-index --refresh &&
400 git diff-files --quiet &&
401 git diff-index --quiet --cached HEAD -- &&
402 test_cmp_rev HEAD~6 branch1 &&
403 test_cmp_rev HEAD~4^2 to-be-preserved &&
404 test_cmp_rev HEAD^^2^ HEAD^^^ &&
405 test $(git show HEAD~5:file1) = B &&
406 test $(git show HEAD~3:file1) = C &&
407 test $(git show HEAD:file1) = E &&
408 test $(git show HEAD:unrelated-file) = 1
411 test_expect_success REBASE_P 'edit ancestor with -p' '
414 FAKE_LINES="1 2 edit 3 4" git rebase -i -p HEAD~3
416 echo 2 > unrelated-file &&
418 git commit -m L2-modified --amend unrelated-file &&
419 git rebase --continue &&
420 git update-index --refresh &&
421 git diff-files --quiet &&
422 git diff-index --quiet --cached HEAD -- &&
423 test $(git show HEAD:unrelated-file) = 2
426 test_expect_success '--continue tries to commit' '
427 git reset --hard D &&
431 test_must_fail git rebase -i --onto new-branch1 HEAD^ &&
432 echo resolved > file1 &&
434 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue
436 test_cmp_rev HEAD^ new-branch1 &&
437 git show HEAD | grep chouette
440 test_expect_success 'verbose flag is heeded, even after --continue' '
441 git reset --hard primary@{1} &&
443 test_must_fail git rebase -v -i --onto new-branch1 HEAD^ &&
444 echo resolved > file1 &&
446 git rebase --continue > output &&
447 grep "^ file1 | 2 +-$" output
450 test_expect_success C_LOCALE_OUTPUT 'multi-squash only fires up editor once' '
451 base=$(git rev-parse HEAD~4) &&
454 FAKE_COMMIT_AMEND="ONCE" \
455 FAKE_LINES="1 squash 2 squash 3 squash 4" \
456 EXPECT_HEADER_COUNT=4 \
459 test $base = $(git rev-parse HEAD^) &&
460 test 1 = $(git show | grep ONCE | wc -l)
463 test_expect_success C_LOCALE_OUTPUT 'multi-fixup does not fire up editor' '
464 git checkout -b multi-fixup E &&
465 base=$(git rev-parse HEAD~4) &&
468 FAKE_COMMIT_AMEND="NEVER" \
469 FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \
472 test $base = $(git rev-parse HEAD^) &&
473 test 0 = $(git show | grep NEVER | wc -l) &&
474 git checkout @{-1} &&
475 git branch -D multi-fixup
478 test_expect_success 'commit message used after conflict' '
479 git checkout -b conflict-fixup conflict-branch &&
480 base=$(git rev-parse HEAD~4) &&
483 test_must_fail env FAKE_LINES="1 fixup 3 fixup 4" \
484 git rebase -i $base &&
485 echo three > conflict &&
487 FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \
488 git rebase --continue
490 test $base = $(git rev-parse HEAD^) &&
491 test 1 = $(git show | grep ONCE | wc -l) &&
492 git checkout @{-1} &&
493 git branch -D conflict-fixup
496 test_expect_success 'commit message retained after conflict' '
497 git checkout -b conflict-squash conflict-branch &&
498 base=$(git rev-parse HEAD~4) &&
501 test_must_fail env FAKE_LINES="1 fixup 3 squash 4" \
502 git rebase -i $base &&
503 echo three > conflict &&
505 FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \
506 git rebase --continue
508 test $base = $(git rev-parse HEAD^) &&
509 test 2 = $(git show | grep TWICE | wc -l) &&
510 git checkout @{-1} &&
511 git branch -D conflict-squash
514 test_expect_success C_LOCALE_OUTPUT 'squash and fixup generate correct log messages' '
515 cat >expect-squash-fixup <<-\EOF &&
522 git checkout -b squash-fixup E &&
523 base=$(git rev-parse HEAD~4) &&
526 FAKE_COMMIT_AMEND="ONCE" \
527 FAKE_LINES="1 fixup 2 squash 3 fixup 4" \
528 EXPECT_HEADER_COUNT=4 \
531 git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup &&
532 test_cmp expect-squash-fixup actual-squash-fixup &&
533 git cat-file commit HEAD@{2} |
534 grep "^# This is a combination of 3 commits\." &&
535 git cat-file commit HEAD@{3} |
536 grep "^# This is a combination of 2 commits\." &&
537 git checkout @{-1} &&
538 git branch -D squash-fixup
541 test_expect_success C_LOCALE_OUTPUT 'squash ignores comments' '
542 git checkout -b skip-comments E &&
543 base=$(git rev-parse HEAD~4) &&
546 FAKE_COMMIT_AMEND="ONCE" \
547 FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \
548 EXPECT_HEADER_COUNT=4 \
551 test $base = $(git rev-parse HEAD^) &&
552 test 1 = $(git show | grep ONCE | wc -l) &&
553 git checkout @{-1} &&
554 git branch -D skip-comments
557 test_expect_success C_LOCALE_OUTPUT 'squash ignores blank lines' '
558 git checkout -b skip-blank-lines E &&
559 base=$(git rev-parse HEAD~4) &&
562 FAKE_COMMIT_AMEND="ONCE" \
563 FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \
564 EXPECT_HEADER_COUNT=4 \
567 test $base = $(git rev-parse HEAD^) &&
568 test 1 = $(git show | grep ONCE | wc -l) &&
569 git checkout @{-1} &&
570 git branch -D skip-blank-lines
573 test_expect_success 'squash works as expected' '
574 git checkout -b squash-works no-conflict-branch &&
575 one=$(git rev-parse HEAD~3) &&
578 FAKE_LINES="1 s 3 2" EXPECT_HEADER_COUNT=2 git rebase -i HEAD~3
580 test $one = $(git rev-parse HEAD~2)
583 test_expect_success 'interrupted squash works as expected' '
584 git checkout -b interrupted-squash conflict-branch &&
585 one=$(git rev-parse HEAD~3) &&
588 test_must_fail env FAKE_LINES="1 squash 3 2" \
591 test_write_lines one two four > conflict &&
593 test_must_fail git rebase --continue &&
594 echo resolved > conflict &&
596 git rebase --continue &&
597 test $one = $(git rev-parse HEAD~2)
600 test_expect_success 'interrupted squash works as expected (case 2)' '
601 git checkout -b interrupted-squash2 conflict-branch &&
602 one=$(git rev-parse HEAD~3) &&
605 test_must_fail env FAKE_LINES="3 squash 1 2" \
608 test_write_lines one four > conflict &&
610 test_must_fail git rebase --continue &&
611 test_write_lines one two four > conflict &&
613 test_must_fail git rebase --continue &&
614 echo resolved > conflict &&
616 git rebase --continue &&
617 test $one = $(git rev-parse HEAD~2)
620 test_expect_success '--continue tries to commit, even for "edit"' '
621 echo unrelated > file7 &&
624 git commit -m "unrelated change" &&
625 parent=$(git rev-parse HEAD^) &&
629 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
630 echo edited > file7 &&
632 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue
634 test edited = $(git show HEAD:file7) &&
635 git show HEAD | grep chouette &&
636 test $parent = $(git rev-parse HEAD^)
639 test_expect_success 'aborted --continue does not squash commits after "edit"' '
640 old=$(git rev-parse HEAD) &&
644 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
645 echo "edited again" > file7 &&
647 test_must_fail env FAKE_COMMIT_MESSAGE=" " git rebase --continue
649 test $old = $(git rev-parse HEAD) &&
653 test_expect_success 'auto-amend only edited commits after "edit"' '
657 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
658 echo "edited again" > file7 &&
660 FAKE_COMMIT_MESSAGE="edited file7 again" git commit &&
661 echo "and again" > file7 &&
664 test_must_fail env FAKE_COMMIT_MESSAGE="and again" \
665 git rebase --continue
670 test_expect_success 'clean error after failed "exec"' '
672 test_when_finished "git rebase --abort || :" &&
675 test_must_fail env FAKE_LINES="1 exec_false" git rebase -i HEAD^
677 echo "edited again" > file7 &&
679 test_must_fail git rebase --continue 2>error &&
680 test_i18ngrep "you have staged changes in your working tree" error
683 test_expect_success 'rebase a detached HEAD' '
684 grandparent=$(git rev-parse HEAD~2) &&
685 git checkout $(git rev-parse HEAD) &&
689 FAKE_LINES="2 1" git rebase -i HEAD~2
691 test $grandparent = $(git rev-parse HEAD~2)
694 test_expect_success 'rebase a commit violating pre-commit' '
696 mkdir -p .git/hooks &&
697 write_script .git/hooks/pre-commit <<-\EOF &&
698 test -z "$(git diff --cached --check)"
700 echo "monde! " >> file1 &&
702 test_must_fail git commit -m doesnt-verify file1 &&
703 git commit -m doesnt-verify --no-verify file1 &&
707 FAKE_LINES=2 git rebase -i HEAD~2
711 test_expect_success 'rebase with a file named HEAD in worktree' '
715 git checkout -b branch3 A &&
718 GIT_AUTHOR_NAME="Squashed Away" &&
719 export GIT_AUTHOR_NAME &&
722 git commit -m "Add head" &&
725 git commit -m "Add body"
730 FAKE_LINES="1 squash 2" git rebase -i @{-1}
732 test "$(git show -s --pretty=format:%an)" = "Squashed Away"
736 test_expect_success 'do "noop" when there is nothing to cherry-pick' '
738 git checkout -b branch4 HEAD &&
739 GIT_EDITOR=: git commit --amend \
740 --author="Somebody else <somebody@else.com>" &&
741 test $(git rev-parse branch3) != $(git rev-parse branch4) &&
742 git rebase -i branch3 &&
743 test_cmp_rev branch3 branch4
747 test_expect_success 'submodule rebase setup' '
751 cd sub && git init && >elif &&
752 git add elif && git commit -m "submodule initial"
757 git commit -m "One" &&
760 git commit -a -m "Two" &&
762 cd sub && echo 3 >elif &&
763 git commit -a -m "submodule second"
766 git commit -a -m "Three changes submodule"
769 test_expect_success 'submodule rebase -i' '
772 FAKE_LINES="1 squash 2 3" git rebase -i A
776 test_expect_success 'submodule conflict setup' '
777 git tag submodule-base &&
778 git checkout HEAD^ &&
780 cd sub && git checkout HEAD^ && echo 4 >elif &&
781 git add elif && git commit -m "submodule conflict"
785 git commit -m "Conflict in submodule" &&
786 git tag submodule-topic
789 test_expect_success 'rebase -i continue with only submodule staged' '
790 test_must_fail git rebase -i submodule-base &&
792 git rebase --continue &&
793 test $(git rev-parse submodule-base) != $(git rev-parse HEAD)
796 test_expect_success 'rebase -i continue with unstaged submodule' '
797 git checkout submodule-topic &&
799 test_must_fail git rebase -i submodule-base &&
801 git rebase --continue &&
802 test_cmp_rev submodule-base HEAD
805 test_expect_success 'avoid unnecessary reset' '
806 git checkout primary &&
808 test-tool chmtime =123456789 file3 &&
809 git update-index --refresh &&
810 HEAD=$(git rev-parse HEAD) &&
811 git rebase -i HEAD~4 &&
812 test $HEAD = $(git rev-parse HEAD) &&
813 MTIME=$(test-tool chmtime --get file3) &&
814 test 123456789 = $MTIME
817 test_expect_success 'reword' '
818 git checkout -b reword-branch primary &&
821 FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" \
823 git show HEAD | grep "E changed" &&
824 test $(git rev-parse primary) != $(git rev-parse HEAD) &&
825 test_cmp_rev primary^ HEAD^ &&
826 FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" \
828 git show HEAD^ | grep "D changed" &&
829 FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" \
831 git show HEAD~3 | grep "B changed" &&
832 FAKE_LINES="1 r 2 pick 3 p 4" FAKE_COMMIT_MESSAGE="C changed" \
835 git show HEAD~2 | grep "C changed"
838 test_expect_success 'rebase -i can copy notes' '
839 git config notes.rewrite.rebase true &&
840 git config notes.rewriteRef "refs/notes/*" &&
844 git notes add -m"a note" n3 &&
845 git rebase -i --onto n1 n2 &&
846 test "a note" = "$(git notes show HEAD)"
849 test_expect_success 'rebase -i can copy notes over a fixup' '
850 cat >expect <<-\EOF &&
855 git reset --hard n3 &&
856 git notes add -m"an earlier note" n2 &&
859 GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 f 2" \
862 git notes show > output &&
863 test_cmp expect output
866 test_expect_success 'rebase while detaching HEAD' '
867 git symbolic-ref HEAD &&
868 grandparent=$(git rev-parse HEAD~2) &&
872 FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0
874 test $grandparent = $(git rev-parse HEAD~2) &&
875 test_must_fail git symbolic-ref HEAD
878 test_tick # Ensure that the rebased commits get a different timestamp.
879 test_expect_success 'always cherry-pick with --no-ff' '
880 git checkout no-ff-branch &&
881 git tag original-no-ff-branch &&
882 git rebase -i --no-ff A &&
885 test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) &&
886 git diff HEAD~$p original-no-ff-branch~$p > out &&
887 test_must_be_empty out
889 test_cmp_rev HEAD~3 original-no-ff-branch~3 &&
890 git diff HEAD~3 original-no-ff-branch~3 > out &&
891 test_must_be_empty out
894 test_expect_success 'set up commits with funny messages' '
895 git checkout -b funny A &&
898 git commit -a -m "end with slash\\" &&
901 git commit -a -m "something (\000) that looks like octal" &&
904 git commit -a -m "something (\n) that looks like a newline" &&
907 git commit -a -m "another commit"
910 test_expect_success 'rebase-i history with funny messages' '
911 git rev-list A..funny >expect &&
915 FAKE_LINES="1 2 3 4" git rebase -i A
917 git rev-list A.. >actual &&
918 test_cmp expect actual
921 test_expect_success 'prepare for rebase -i --exec' '
922 git checkout primary &&
923 git checkout -b execute &&
924 test_commit one_exec main.txt one_exec &&
925 test_commit two_exec main.txt two_exec &&
926 test_commit three_exec main.txt three_exec
929 test_expect_success 'running "git rebase -i --exec git show HEAD"' '
932 git rebase -i --exec "git show HEAD" HEAD~2 >actual &&
933 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
935 git rebase -i HEAD~2 >expect
937 sed -e "1,9d" expect >expected &&
938 test_cmp expected actual
941 test_expect_success 'running "git rebase --exec git show HEAD -i"' '
942 git reset --hard execute &&
945 git rebase --exec "git show HEAD" -i HEAD~2 >actual &&
946 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
948 git rebase -i HEAD~2 >expect
950 sed -e "1,9d" expect >expected &&
951 test_cmp expected actual
954 test_expect_success 'running "git rebase -ix git show HEAD"' '
955 git reset --hard execute &&
958 git rebase -ix "git show HEAD" HEAD~2 >actual &&
959 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
961 git rebase -i HEAD~2 >expect
963 sed -e "1,9d" expect >expected &&
964 test_cmp expected actual
968 test_expect_success 'rebase -ix with several <CMD>' '
969 git reset --hard execute &&
972 git rebase -ix "git show HEAD; pwd" HEAD~2 >actual &&
973 FAKE_LINES="1 exec_git_show_HEAD;_pwd 2 exec_git_show_HEAD;_pwd" &&
975 git rebase -i HEAD~2 >expect
977 sed -e "1,9d" expect >expected &&
978 test_cmp expected actual
981 test_expect_success 'rebase -ix with several instances of --exec' '
982 git reset --hard execute &&
985 git rebase -i --exec "git show HEAD" --exec "pwd" HEAD~2 >actual &&
986 FAKE_LINES="1 exec_git_show_HEAD exec_pwd 2
987 exec_git_show_HEAD exec_pwd" &&
989 git rebase -i HEAD~2 >expect
991 sed -e "1,11d" expect >expected &&
992 test_cmp expected actual
995 test_expect_success C_LOCALE_OUTPUT 'rebase -ix with --autosquash' '
996 git reset --hard execute &&
997 git checkout -b autosquash &&
998 echo second >second.txt &&
999 git add second.txt &&
1000 git commit -m "fixup! two_exec" &&
1001 echo bis >bis.txt &&
1003 git commit -m "fixup! two_exec" &&
1004 git checkout -b autosquash_actual &&
1005 git rebase -i --exec "git show HEAD" --autosquash HEAD~4 >actual &&
1006 git checkout autosquash &&
1009 git checkout -b autosquash_expected &&
1010 FAKE_LINES="1 fixup 3 fixup 4 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
1011 export FAKE_LINES &&
1012 git rebase -i HEAD~4 >expect
1014 sed -e "1,13d" expect >expected &&
1015 test_cmp expected actual
1018 test_expect_success 'rebase --exec works without -i ' '
1019 git reset --hard execute &&
1020 rm -rf exec_output &&
1021 EDITOR="echo >invoked_editor" git rebase --exec "echo a line >>exec_output" HEAD~2 2>actual &&
1022 test_i18ngrep "Successfully rebased and updated" actual &&
1023 test_line_count = 2 exec_output &&
1024 test_path_is_missing invoked_editor
1027 test_expect_success 'rebase -i --exec without <CMD>' '
1028 git reset --hard execute &&
1029 test_must_fail git rebase -i --exec 2>actual &&
1030 test_i18ngrep "requires a value" actual &&
1031 git checkout primary
1034 test_expect_success 'rebase -i --root re-order and drop commits' '
1038 FAKE_LINES="3 1 2 5" git rebase -i --root
1040 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1041 test B = $(git cat-file commit HEAD^ | sed -ne \$p) &&
1042 test A = $(git cat-file commit HEAD^^ | sed -ne \$p) &&
1043 test C = $(git cat-file commit HEAD^^^ | sed -ne \$p) &&
1044 test 0 = $(git cat-file commit HEAD^^^ | grep -c ^parent\ )
1047 test_expect_success 'rebase -i --root retain root commit author and message' '
1051 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
1054 FAKE_LINES="2" git rebase -i --root
1056 git cat-file commit HEAD | grep -q "^author Twerp Snog" &&
1057 git cat-file commit HEAD | grep -q "^different author$"
1060 test_expect_success 'rebase -i --root temporary sentinel commit' '
1064 test_must_fail env FAKE_LINES="2" git rebase -i --root
1066 git cat-file commit HEAD | grep "^tree $EMPTY_TREE" &&
1070 test_expect_success 'rebase -i --root fixup root commit' '
1074 FAKE_LINES="1 fixup 2" git rebase -i --root
1076 test A = $(git cat-file commit HEAD | sed -ne \$p) &&
1077 test B = $(git show HEAD:file1) &&
1078 test 0 = $(git cat-file commit HEAD | grep -c ^parent\ )
1081 test_expect_success 'rebase -i --root reword original root commit' '
1082 test_when_finished "test_might_fail git rebase --abort" &&
1083 git checkout -b reword-original-root-branch primary &&
1086 FAKE_LINES="reword 1 2" FAKE_COMMIT_MESSAGE="A changed" \
1087 git rebase -i --root
1089 git show HEAD^ | grep "A changed" &&
1090 test -z "$(git show -s --format=%p HEAD^)"
1093 test_expect_success 'rebase -i --root reword new root commit' '
1094 test_when_finished "test_might_fail git rebase --abort" &&
1095 git checkout -b reword-now-root-branch primary &&
1098 FAKE_LINES="reword 3 1" FAKE_COMMIT_MESSAGE="C changed" \
1099 git rebase -i --root
1101 git show HEAD^ | grep "C changed" &&
1102 test -z "$(git show -s --format=%p HEAD^)"
1105 test_expect_success 'rebase -i --root when root has untracked file conflict' '
1106 test_when_finished "reset_rebase" &&
1107 git checkout -b failing-root-pick A &&
1110 git commit -m "remove file 1 add file 2" &&
1114 test_must_fail env FAKE_LINES="1 2" git rebase -i --root
1117 git rebase --continue &&
1118 test "$(git log -1 --format=%B)" = "remove file 1 add file 2" &&
1119 test "$(git rev-list --count HEAD)" = 2
1122 test_expect_success 'rebase -i --root reword root when root has untracked file conflict' '
1123 test_when_finished "reset_rebase" &&
1127 test_must_fail env FAKE_LINES="reword 1 2" \
1128 FAKE_COMMIT_MESSAGE="Modified A" git rebase -i --root &&
1130 FAKE_COMMIT_MESSAGE="Reworded A" git rebase --continue
1132 test "$(git log -1 --format=%B HEAD^)" = "Reworded A" &&
1133 test "$(git rev-list --count HEAD)" = 2
1136 test_expect_success C_LOCALE_OUTPUT 'rebase --edit-todo does not work on non-interactive rebase' '
1137 git checkout reword-original-root-branch &&
1139 git checkout conflict-branch &&
1142 test_must_fail git rebase -f --apply --onto HEAD~2 HEAD~ &&
1143 test_must_fail git rebase --edit-todo
1148 test_expect_success 'rebase --edit-todo can be used to modify todo' '
1150 git checkout no-conflict-branch^0 &&
1153 FAKE_LINES="edit 1 2 3" git rebase -i HEAD~3 &&
1154 FAKE_LINES="2 1" git rebase --edit-todo &&
1155 git rebase --continue
1157 test M = $(git cat-file commit HEAD^ | sed -ne \$p) &&
1158 test L = $(git cat-file commit HEAD | sed -ne \$p)
1161 test_expect_success 'rebase -i produces readable reflog' '
1163 git branch -f branch-reflog-test H &&
1164 git rebase -i --onto I F branch-reflog-test &&
1165 cat >expect <<-\EOF &&
1166 rebase (finish): returning to refs/heads/branch-reflog-test
1169 rebase (start): checkout I
1171 git reflog -n4 HEAD |
1172 sed "s/[^:]*: //" >actual &&
1173 test_cmp expect actual
1176 test_expect_success 'rebase -i respects core.commentchar' '
1179 test_config core.commentchar "\\" &&
1180 write_script remove-all-but-first.sh <<-\EOF &&
1181 sed -e "2,\$s/^/\\\\/" "$1" >"$1.tmp" &&
1185 test_set_editor "$(pwd)/remove-all-but-first.sh" &&
1188 test B = $(git cat-file commit HEAD^ | sed -ne \$p)
1191 test_expect_success 'rebase -i respects core.commentchar=auto' '
1192 test_config core.commentchar auto &&
1193 write_script copy-edit-script.sh <<-\EOF &&
1196 test_when_finished "git rebase --abort || :" &&
1198 test_set_editor "$(pwd)/copy-edit-script.sh" &&
1201 test -z "$(grep -ve "^#" -e "^\$" -e "^pick" edit-script)"
1204 test_expect_success 'rebase -i, with <onto> and <upstream> specified as :/quuxery' '
1205 test_when_finished "git branch -D torebase" &&
1206 git checkout -b torebase branch1 &&
1207 upstream=$(git rev-parse ":/J") &&
1208 onto=$(git rev-parse ":/A") &&
1209 git rebase --onto $onto $upstream &&
1210 git reset --hard branch1 &&
1211 git rebase --onto ":/A" ":/J" &&
1212 git checkout branch1
1215 test_expect_success 'rebase -i with --strategy and -X' '
1216 git checkout -b conflict-merge-use-theirs conflict-branch &&
1217 git reset --hard HEAD^ &&
1218 echo five >conflict &&
1220 git commit -a -m "one file conflict" &&
1221 EDITOR=true git rebase -i --strategy=recursive -Xours conflict-branch &&
1222 test $(git show conflict-branch:conflict) = $(cat conflict) &&
1223 test $(cat file1) = Z
1226 test_expect_success 'interrupted rebase -i with --strategy and -X' '
1227 git checkout -b conflict-merge-use-theirs-interrupted conflict-branch &&
1228 git reset --hard HEAD^ &&
1230 git add breakpoint &&
1231 git commit -m "breakpoint for interactive mode" &&
1232 echo five >conflict &&
1234 git commit -a -m "one file conflict" &&
1237 FAKE_LINES="edit 1 2" git rebase -i --strategy=recursive \
1238 -Xours conflict-branch
1240 git rebase --continue &&
1241 test $(git show conflict-branch:conflict) = $(cat conflict) &&
1242 test $(cat file1) = Z
1245 test_expect_success 'rebase -i error on commits with \ in message' '
1246 current_head=$(git rev-parse HEAD) &&
1247 test_when_finished "git rebase --abort; git reset --hard $current_head; rm -f error" &&
1248 test_commit TO-REMOVE will-conflict old-content &&
1249 test_commit "\temp" will-conflict new-content dummy &&
1250 test_must_fail env EDITOR=true git rebase -i HEAD^ --onto HEAD^^ 2>error &&
1251 test_expect_code 1 grep " emp" error
1254 test_expect_success 'short commit ID setup' '
1255 test_when_finished "git checkout primary" &&
1256 git checkout --orphan collide &&
1260 test_commit collide1 collide &&
1261 test_commit --notick collide2 collide &&
1262 test_commit --notick collide3 collide
1266 if test -n "$GIT_TEST_FIND_COLLIDER"
1268 author="$(unset test_tick; test_tick; git var GIT_AUTHOR_IDENT)"
1269 committer="$(unset test_tick; test_tick; git var GIT_COMMITTER_IDENT)"
1270 blob="$(git rev-parse collide2:collide)"
1271 from="$(git rev-parse collide1^0)"
1272 repl="commit refs/heads/collider-&\\n"
1273 repl="${repl}author $author\\ncommitter $committer\\n"
1274 repl="${repl}data <<EOF\\ncollide2 &\\nEOF\\n"
1275 repl="${repl}from $from\\nM 100644 $blob collide\\n"
1276 test_seq 1 32768 | sed "s|.*|$repl|" >script &&
1277 git fast-import <script &&
1279 git for-each-ref >refs &&
1280 grep "^$(test_oid t3404_collision)" <refs >matches &&
1282 test_line_count -gt 2 matches || {
1283 echo "Could not find a collider" >&2
1288 test_expect_success 'short commit ID collide' '
1289 test_oid_cache <<-EOF &&
1290 # collision-related constants
1291 t3404_collision sha1:6bcd
1292 t3404_collision sha256:0161
1293 t3404_collider sha1:ac4f2ee
1294 t3404_collider sha256:16697
1296 test_when_finished "reset_rebase && git checkout primary" &&
1297 git checkout collide &&
1298 colliding_id=$(test_oid t3404_collision) &&
1299 hexsz=$(test_oid hexsz) &&
1300 test $colliding_id = "$(git rev-parse HEAD | cut -c 1-4)" &&
1301 test_config core.abbrev 4 &&
1306 FAKE_COMMIT_MESSAGE="collide2 $(test_oid t3404_collider)" \
1307 FAKE_LINES="reword 1 break 2" git rebase -i HEAD~2 &&
1308 test $colliding_id = "$(git rev-parse HEAD | cut -c 1-4)" &&
1309 grep "^pick $colliding_id " \
1310 .git/rebase-merge/git-rebase-todo.tmp &&
1311 grep "^pick [0-9a-f]\{$hexsz\}" \
1312 .git/rebase-merge/git-rebase-todo &&
1313 grep "^pick [0-9a-f]\{$hexsz\}" \
1314 .git/rebase-merge/git-rebase-todo.backup &&
1315 git rebase --continue
1317 collide2="$(git rev-parse HEAD~1 | cut -c 1-4)" &&
1318 collide3="$(git rev-parse collide3 | cut -c 1-4)" &&
1319 test "$collide2" = "$collide3"
1322 test_expect_success 'respect core.abbrev' '
1323 git config core.abbrev 12 &&
1325 set_cat_todo_editor &&
1326 test_must_fail git rebase -i HEAD~4 >todo-list
1328 test 4 = $(grep -c "pick [0-9a-f]\{12,\}" todo-list)
1331 test_expect_success 'todo count' '
1332 write_script dump-raw.sh <<-\EOF &&
1336 test_set_editor "$(pwd)/dump-raw.sh" &&
1337 git rebase -i HEAD~4 >actual
1339 test_i18ngrep "^# Rebase ..* onto ..* ([0-9]" actual
1342 test_expect_success 'rebase -i commits that overwrite untracked files (pick)' '
1343 git checkout --force branch2 &&
1347 FAKE_LINES="edit 1 2" git rebase -i A
1349 test_cmp_rev HEAD F &&
1350 test_path_is_missing file6 &&
1352 test_must_fail git rebase --continue &&
1353 test_cmp_rev HEAD F &&
1355 git rebase --continue &&
1359 test_expect_success 'rebase -i commits that overwrite untracked files (squash)' '
1360 git checkout --force branch2 &&
1362 git tag original-branch2 &&
1365 FAKE_LINES="edit 1 squash 2" git rebase -i A
1367 test_cmp_rev HEAD F &&
1368 test_path_is_missing file6 &&
1370 test_must_fail git rebase --continue &&
1371 test_cmp_rev HEAD F &&
1373 git rebase --continue &&
1374 test $(git cat-file commit HEAD | sed -ne \$p) = I &&
1375 git reset --hard original-branch2
1378 test_expect_success 'rebase -i commits that overwrite untracked files (no ff)' '
1379 git checkout --force branch2 &&
1383 FAKE_LINES="edit 1 2" git rebase -i --no-ff A
1385 test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1386 test_path_is_missing file6 &&
1388 test_must_fail git rebase --continue &&
1389 test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1391 git rebase --continue &&
1392 test $(git cat-file commit HEAD | sed -ne \$p) = I
1395 test_expect_success 'rebase --continue removes CHERRY_PICK_HEAD' '
1396 git checkout -b commit-to-skip &&
1399 test_seq 5 | sed "s/$double/&&/" >seq &&
1402 git commit -m seq-$double
1405 git reset --hard HEAD~2 &&
1406 git cherry-pick seq-onto &&
1409 test_must_fail env FAKE_LINES= git rebase -i seq-onto
1411 test -d .git/rebase-merge &&
1412 git rebase --continue &&
1413 git diff --exit-code seq-onto &&
1414 test ! -d .git/rebase-merge &&
1415 test ! -f .git/CHERRY_PICK_HEAD
1418 rebase_setup_and_clean () {
1419 test_when_finished "
1420 git checkout primary &&
1421 test_might_fail git branch -D $1 &&
1422 test_might_fail git rebase --abort
1424 git checkout -b $1 ${2:-primary}
1427 test_expect_success 'drop' '
1428 rebase_setup_and_clean drop-test &&
1431 FAKE_LINES="1 drop 2 3 d 4 5" git rebase -i --root
1433 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1434 test C = $(git cat-file commit HEAD^ | sed -ne \$p) &&
1435 test A = $(git cat-file commit HEAD^^ | sed -ne \$p)
1438 test_expect_success 'rebase -i respects rebase.missingCommitsCheck = ignore' '
1439 test_config rebase.missingCommitsCheck ignore &&
1440 rebase_setup_and_clean missing-commit &&
1443 FAKE_LINES="1 2 3 4" git rebase -i --root 2>actual
1445 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1447 "Successfully rebased and updated refs/heads/missing-commit" \
1451 test_expect_success 'rebase -i respects rebase.missingCommitsCheck = warn' '
1452 cat >expect <<-EOF &&
1453 Warning: some commits may have been dropped accidentally.
1454 Dropped commits (newer to older):
1455 - $(git rev-list --pretty=oneline --abbrev-commit -1 primary)
1456 To avoid this message, use "drop" to explicitly remove a commit.
1458 test_config rebase.missingCommitsCheck warn &&
1459 rebase_setup_and_clean missing-commit &&
1462 FAKE_LINES="1 2 3 4" git rebase -i --root 2>actual.2
1464 head -n4 actual.2 >actual &&
1465 test_i18ncmp expect actual &&
1466 test D = $(git cat-file commit HEAD | sed -ne \$p)
1469 test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' '
1470 cat >expect <<-EOF &&
1471 Warning: some commits may have been dropped accidentally.
1472 Dropped commits (newer to older):
1473 - $(git rev-list --pretty=oneline --abbrev-commit -1 primary)
1474 - $(git rev-list --pretty=oneline --abbrev-commit -1 primary~2)
1475 To avoid this message, use "drop" to explicitly remove a commit.
1477 Use '\''git config rebase.missingCommitsCheck'\'' to change the level of warnings.
1478 The possible behaviours are: ignore, warn, error.
1480 You can fix this with '\''git rebase --edit-todo'\'' and then run '\''git rebase --continue'\''.
1481 Or you can abort the rebase with '\''git rebase --abort'\''.
1483 test_config rebase.missingCommitsCheck error &&
1484 rebase_setup_and_clean missing-commit &&
1487 test_must_fail env FAKE_LINES="1 2 4" \
1488 git rebase -i --root 2>actual &&
1489 test_i18ncmp expect actual &&
1490 cp .git/rebase-merge/git-rebase-todo.backup \
1491 .git/rebase-merge/git-rebase-todo &&
1492 FAKE_LINES="1 2 drop 3 4 drop 5" git rebase --edit-todo
1494 git rebase --continue &&
1495 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1496 test B = $(git cat-file commit HEAD^ | sed -ne \$p)
1499 test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = ignore' '
1500 test_config rebase.missingCommitsCheck ignore &&
1501 rebase_setup_and_clean missing-commit &&
1504 FAKE_LINES="break 1 2 3 4 5" git rebase -i --root &&
1505 FAKE_LINES="1 2 3 4" git rebase --edit-todo &&
1506 git rebase --continue 2>actual
1508 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1510 "Successfully rebased and updated refs/heads/missing-commit" \
1514 test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = warn' '
1515 cat >expect <<-EOF &&
1516 error: invalid line 1: badcmd $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4)
1517 Warning: some commits may have been dropped accidentally.
1518 Dropped commits (newer to older):
1519 - $(git rev-list --pretty=oneline --abbrev-commit -1 primary)
1520 - $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4)
1521 To avoid this message, use "drop" to explicitly remove a commit.
1523 head -n4 expect >expect.2 &&
1524 tail -n1 expect >>expect.2 &&
1525 tail -n4 expect.2 >expect.3 &&
1526 test_config rebase.missingCommitsCheck warn &&
1527 rebase_setup_and_clean missing-commit &&
1530 test_must_fail env FAKE_LINES="bad 1 2 3 4 5" \
1531 git rebase -i --root &&
1532 cp .git/rebase-merge/git-rebase-todo.backup orig &&
1533 FAKE_LINES="2 3 4" git rebase --edit-todo 2>actual.2 &&
1534 head -n6 actual.2 >actual &&
1535 test_i18ncmp expect actual &&
1536 cp orig .git/rebase-merge/git-rebase-todo &&
1537 FAKE_LINES="1 2 3 4" git rebase --edit-todo 2>actual.2 &&
1538 head -n4 actual.2 >actual &&
1539 test_i18ncmp expect.3 actual &&
1540 git rebase --continue 2>actual
1542 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1544 "Successfully rebased and updated refs/heads/missing-commit" \
1548 test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = error' '
1549 cat >expect <<-EOF &&
1550 error: invalid line 1: badcmd $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4)
1551 Warning: some commits may have been dropped accidentally.
1552 Dropped commits (newer to older):
1553 - $(git rev-list --pretty=oneline --abbrev-commit -1 primary)
1554 - $(git rev-list --pretty=oneline --abbrev-commit -1 primary~4)
1555 To avoid this message, use "drop" to explicitly remove a commit.
1557 Use '\''git config rebase.missingCommitsCheck'\'' to change the level of warnings.
1558 The possible behaviours are: ignore, warn, error.
1560 You can fix this with '\''git rebase --edit-todo'\'' and then run '\''git rebase --continue'\''.
1561 Or you can abort the rebase with '\''git rebase --abort'\''.
1563 tail -n11 expect >expect.2 &&
1564 head -n3 expect.2 >expect.3 &&
1565 tail -n7 expect.2 >>expect.3 &&
1566 test_config rebase.missingCommitsCheck error &&
1567 rebase_setup_and_clean missing-commit &&
1570 test_must_fail env FAKE_LINES="bad 1 2 3 4 5" \
1571 git rebase -i --root &&
1572 cp .git/rebase-merge/git-rebase-todo.backup orig &&
1573 test_must_fail env FAKE_LINES="2 3 4" \
1574 git rebase --edit-todo 2>actual &&
1575 test_i18ncmp expect actual &&
1576 test_must_fail git rebase --continue 2>actual &&
1577 test_i18ncmp expect.2 actual &&
1578 test_must_fail git rebase --edit-todo &&
1579 cp orig .git/rebase-merge/git-rebase-todo &&
1580 test_must_fail env FAKE_LINES="1 2 3 4" \
1581 git rebase --edit-todo 2>actual &&
1582 test_i18ncmp expect.3 actual &&
1583 test_must_fail git rebase --continue 2>actual &&
1584 test_i18ncmp expect.3 actual &&
1585 cp orig .git/rebase-merge/git-rebase-todo &&
1586 FAKE_LINES="1 2 3 4 drop 5" git rebase --edit-todo &&
1587 git rebase --continue 2>actual
1589 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1591 "Successfully rebased and updated refs/heads/missing-commit" \
1595 test_expect_success 'rebase.missingCommitsCheck = error after resolving conflicts' '
1596 test_config rebase.missingCommitsCheck error &&
1599 FAKE_LINES="drop 1 break 2 3 4" git rebase -i A E
1601 git rebase --edit-todo &&
1602 test_must_fail git rebase --continue &&
1605 git rebase --continue
1608 test_expect_success 'rebase.missingCommitsCheck = error when editing for a second time' '
1609 test_config rebase.missingCommitsCheck error &&
1612 FAKE_LINES="1 break 2 3" git rebase -i A D &&
1613 cp .git/rebase-merge/git-rebase-todo todo &&
1614 test_must_fail env FAKE_LINES=2 git rebase --edit-todo &&
1615 GIT_SEQUENCE_EDITOR="cp todo" git rebase --edit-todo &&
1616 git rebase --continue
1620 test_expect_success 'respects rebase.abbreviateCommands with fixup, squash and exec' '
1621 rebase_setup_and_clean abbrevcmd &&
1622 test_commit "first" file1.txt "first line" first &&
1623 test_commit "second" file1.txt "another line" second &&
1624 test_commit "fixup! first" file2.txt "first line again" first_fixup &&
1625 test_commit "squash! second" file1.txt "another line here" second_squash &&
1626 cat >expected <<-EOF &&
1627 p $(git rev-list --abbrev-commit -1 first) first
1628 f $(git rev-list --abbrev-commit -1 first_fixup) fixup! first
1630 p $(git rev-list --abbrev-commit -1 second) second
1631 s $(git rev-list --abbrev-commit -1 second_squash) squash! second
1634 git checkout abbrevcmd &&
1635 test_config rebase.abbreviateCommands true &&
1637 set_cat_todo_editor &&
1638 test_must_fail git rebase -i --exec "git show HEAD" \
1639 --autosquash primary >actual
1641 test_cmp expected actual
1644 test_expect_success 'static check of bad command' '
1645 rebase_setup_and_clean bad-cmd &&
1648 test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \
1649 git rebase -i --root 2>actual &&
1650 test_i18ngrep "badcmd $(git rev-list --oneline -1 primary~1)" \
1652 test_i18ngrep "You can fix this with .git rebase --edit-todo.." \
1654 FAKE_LINES="1 2 3 drop 4 5" git rebase --edit-todo
1656 git rebase --continue &&
1657 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1658 test C = $(git cat-file commit HEAD^ | sed -ne \$p)
1661 test_expect_success 'tabs and spaces are accepted in the todolist' '
1662 rebase_setup_and_clean indented-comment &&
1663 write_script add-indent.sh <<-\EOF &&
1665 # Turn single spaces into space/tab mix
1666 sed "1s/ / /g; 2s/ / /g; 3s/ / /g" "$1"
1667 printf "\n\t# comment\n #more\n\t # comment\n"
1672 test_set_editor "$(pwd)/add-indent.sh" &&
1673 git rebase -i HEAD^^^
1675 test E = $(git cat-file commit HEAD | sed -ne \$p)
1678 test_expect_success 'static check of bad SHA-1' '
1679 rebase_setup_and_clean bad-sha &&
1682 test_must_fail env FAKE_LINES="1 2 edit fakesha 3 4 5 #" \
1683 git rebase -i --root 2>actual &&
1684 test_i18ngrep "edit XXXXXXX False commit" actual &&
1685 test_i18ngrep "You can fix this with .git rebase --edit-todo.." \
1687 FAKE_LINES="1 2 4 5 6" git rebase --edit-todo
1689 git rebase --continue &&
1690 test E = $(git cat-file commit HEAD | sed -ne \$p)
1693 test_expect_success 'editor saves as CR/LF' '
1694 git checkout -b with-crlf &&
1695 write_script add-crs.sh <<-\EOF &&
1696 sed -e "s/\$/Q/" <"$1" | tr Q "\\015" >"$1".new &&
1700 test_set_editor "$(pwd)/add-crs.sh" &&
1705 test_expect_success 'rebase -i --gpg-sign=<key-id>' '
1706 test_when_finished "test_might_fail git rebase --abort" &&
1709 FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" \
1712 test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err
1715 test_expect_success 'rebase -i --gpg-sign=<key-id> overrides commit.gpgSign' '
1716 test_when_finished "test_might_fail git rebase --abort" &&
1717 test_config commit.gpgsign true &&
1720 FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" \
1723 test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err
1726 test_expect_success 'valid author header after --root swap' '
1727 rebase_setup_and_clean author-header no-conflict-branch &&
1728 git commit --amend --author="Au ${SQ}thor <author@example.com>" --no-edit &&
1729 git cat-file commit HEAD | grep ^author >expected &&
1732 FAKE_LINES="5 1" git rebase -i --root
1734 git cat-file commit HEAD^ | grep ^author >actual &&
1735 test_cmp expected actual
1738 test_expect_success 'valid author header when author contains single quote' '
1739 rebase_setup_and_clean author-header no-conflict-branch &&
1740 git commit --amend --author="Au ${SQ}thor <author@example.com>" --no-edit &&
1741 git cat-file commit HEAD | grep ^author >expected &&
1744 FAKE_LINES="2" git rebase -i HEAD~2
1746 git cat-file commit HEAD | grep ^author >actual &&
1747 test_cmp expected actual
1750 test_expect_success 'post-commit hook is called' '
1751 test_when_finished "rm -f .git/hooks/post-commit" &&
1753 mkdir -p .git/hooks &&
1754 write_script .git/hooks/post-commit <<-\EOS &&
1755 git rev-parse HEAD >>actual
1759 FAKE_LINES="edit 4 1 reword 2 fixup 3" git rebase -i A E &&
1762 FAKE_COMMIT_MESSAGE=edited git rebase --continue
1764 git rev-parse HEAD@{5} HEAD@{4} HEAD@{3} HEAD@{2} HEAD@{1} HEAD \
1766 test_cmp expect actual
1769 test_expect_success 'correct error message for partial commit after empty pick' '
1770 test_when_finished "git rebase --abort" &&
1773 FAKE_LINES="2 1 1" &&
1774 export FAKE_LINES &&
1775 test_must_fail git rebase -i A D
1778 test_must_fail git commit file1 2>err &&
1779 test_i18ngrep "cannot do a partial commit during a rebase." err
1782 test_expect_success 'correct error message for commit --amend after empty pick' '
1783 test_when_finished "git rebase --abort" &&
1787 export FAKE_LINES &&
1788 test_must_fail git rebase -i A D
1791 test_must_fail git commit -a --amend 2>err &&
1792 test_i18ngrep "middle of a rebase -- cannot amend." err
1795 test_expect_success 'todo has correct onto hash' '
1796 GIT_SEQUENCE_EDITOR=cat git rebase -i no-conflict-branch~4 no-conflict-branch >actual &&
1797 onto=$(git rev-parse --short HEAD~4) &&
1798 test_i18ngrep "^# Rebase ..* onto $onto" actual
1801 test_expect_success 'ORIG_HEAD is updated correctly' '
1802 test_when_finished "git checkout primary && git branch -D test-orig-head" &&
1803 git checkout -b test-orig-head A &&
1804 git commit --allow-empty -m A1 &&
1805 git commit --allow-empty -m A2 &&
1806 git commit --allow-empty -m A3 &&
1807 git commit --allow-empty -m A4 &&
1808 git rebase primary &&
1809 test_cmp_rev ORIG_HEAD test-orig-head@{1}
1812 # This must be the last test in this file
1813 test_expect_success '$EDITOR and friends are unchanged' '
1814 test_editor_unchanged