3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description='git rebase interactive
8 This test runs git rebase "interactively", by faking an edit, and verifies
9 that the result still makes sense.
13 one - two - three - four (conflict-branch)
15 A - B - C - D - E (master)
21 | J - K - L - M (no-conflict-branch)
23 N - O - P (no-ff-branch)
25 where A, B, D and G all touch file1, and one, two, three, four all
26 touch file "conflict".
30 . "$TEST_DIRECTORY"/lib-rebase.sh
32 test_expect_success 'setup' '
33 test_commit A file1 &&
34 test_commit B file1 &&
35 test_commit C file2 &&
36 test_commit D file1 &&
37 test_commit E file3 &&
38 git checkout -b branch1 A &&
39 test_commit F file4 &&
40 test_commit G file1 &&
41 test_commit H file5 &&
42 git checkout -b branch2 F &&
43 test_commit I file6 &&
44 git checkout -b conflict-branch A &&
45 test_commit one conflict &&
46 test_commit two conflict &&
47 test_commit three conflict &&
48 test_commit four conflict &&
49 git checkout -b no-conflict-branch A &&
50 test_commit J fileJ &&
51 test_commit K fileK &&
52 test_commit L fileL &&
53 test_commit M fileM &&
54 git checkout -b no-ff-branch A &&
55 test_commit N fileN &&
56 test_commit O fileO &&
60 # "exec" commands are run with the user shell by default, but this may
61 # be non-POSIX. For example, if SHELL=zsh then ">file" doesn't work
62 # to create a file. Unsetting SHELL avoids such non-portable behavior
63 # in tests. It must be exported for it to take effect where needed.
67 test_expect_success 'rebase --keep-empty' '
68 git checkout -b emptybranch master &&
69 git commit --allow-empty -m "empty" &&
70 git rebase --keep-empty -i HEAD~2 &&
71 git log --oneline >actual &&
72 test_line_count = 6 actual
75 test_expect_success 'rebase -i with empty todo list' '
76 cat >expect <<-\EOF &&
81 test_must_fail env FAKE_LINES="#" \
82 git rebase -i HEAD^ >output 2>&1
84 tail -n 1 output >actual && # Ignore output about changing todo list
85 test_i18ncmp expect actual
88 test_expect_success 'rebase -i with the exec command' '
89 git checkout master &&
92 FAKE_LINES="1 exec_>touch-one
93 2 exec_>touch-two exec_false exec_>touch-three
94 3 4 exec_>\"touch-file__name_with_spaces\";_>touch-after-semicolon 5" &&
96 test_must_fail git rebase -i A
98 test_path_is_file touch-one &&
99 test_path_is_file touch-two &&
100 test_path_is_missing touch-three " (should have stopped before)" &&
101 test_cmp_rev C HEAD &&
102 git rebase --continue &&
103 test_path_is_file touch-three &&
104 test_path_is_file "touch-file name with spaces" &&
105 test_path_is_file touch-after-semicolon &&
106 test_cmp_rev master HEAD &&
110 test_expect_success 'rebase -i with the exec command runs from tree root' '
111 git checkout master &&
112 mkdir subdir && (cd subdir &&
114 FAKE_LINES="1 exec_>touch-subdir" \
117 test_path_is_file touch-subdir &&
121 test_expect_success 'rebase -i with exec allows git commands in subdirs' '
122 test_when_finished "rm -rf subdir" &&
123 test_when_finished "git rebase --abort ||:" &&
124 git checkout master &&
125 mkdir subdir && (cd subdir &&
127 FAKE_LINES="1 x_cd_subdir_&&_git_rev-parse_--is-inside-work-tree" \
132 test_expect_success 'rebase -i sets work tree properly' '
133 test_when_finished "rm -rf subdir" &&
134 test_when_finished "test_might_fail git rebase --abort" &&
136 git rebase -x "(cd subdir && git rev-parse --show-toplevel)" HEAD^ \
138 ! grep "/subdir$" actual
141 test_expect_success 'rebase -i with the exec command checks tree cleanness' '
142 git checkout master &&
145 test_must_fail env FAKE_LINES="exec_echo_foo_>file1 1" \
148 test_cmp_rev master^ HEAD &&
150 git rebase --continue
153 test_expect_success 'rebase -x with empty command fails' '
154 test_when_finished "git rebase --abort ||:" &&
155 test_must_fail env git rebase -x "" @ 2>actual &&
156 test_write_lines "error: empty exec command" >expected &&
157 test_i18ncmp expected actual &&
158 test_must_fail env git rebase -x " " @ 2>actual &&
159 test_i18ncmp expected actual
162 test_expect_success 'rebase -x with newline in command fails' '
163 test_when_finished "git rebase --abort ||:" &&
164 test_must_fail env git rebase -x "a${LF}b" @ 2>actual &&
165 test_write_lines "error: exec commands cannot contain newlines" \
167 test_i18ncmp expected actual
170 test_expect_success 'rebase -i with exec of inexistent command' '
171 git checkout master &&
172 test_when_finished "git rebase --abort" &&
175 test_must_fail env FAKE_LINES="exec_this-command-does-not-exist 1" \
176 git rebase -i HEAD^ >actual 2>&1
178 ! grep "Maybe git-rebase is broken" actual
181 test_expect_success 'implicit interactive rebase does not invoke sequence editor' '
182 test_when_finished "git rebase --abort ||:" &&
183 GIT_SEQUENCE_EDITOR="echo bad >" git rebase -x"echo one" @^
186 test_expect_success 'no changes are a nop' '
187 git checkout branch2 &&
189 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
193 test_expect_success 'test the [branch] option' '
194 git checkout -b dead-end &&
196 git commit -m "stop here" &&
197 git rebase -i F branch2 &&
198 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
199 test_cmp_rev I branch2 &&
203 test_expect_success 'test --onto <branch>' '
204 git checkout -b test-onto branch2 &&
205 git rebase -i --onto branch1 F &&
206 test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" &&
207 test_cmp_rev HEAD^ branch1 &&
208 test_cmp_rev I branch2
211 test_expect_success 'rebase on top of a non-conflicting commit' '
212 git checkout branch1 &&
213 git tag original-branch1 &&
214 git rebase -i branch2 &&
215 test file6 = $(git diff --name-only original-branch1) &&
216 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
217 test_cmp_rev I branch2 &&
218 test_cmp_rev I HEAD~2
221 test_expect_success 'reflog for the branch shows state before rebase' '
222 test_cmp_rev branch1@{1} original-branch1
225 test_expect_success 'reflog for the branch shows correct finish message' '
226 printf "rebase (finish): refs/heads/branch1 onto %s\n" \
227 "$(git rev-parse branch2)" >expected &&
228 git log -g --pretty=%gs -1 refs/heads/branch1 >actual &&
229 test_cmp expected actual
232 test_expect_success 'exchange two commits' '
235 FAKE_LINES="2 1" git rebase -i HEAD~2
237 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
238 test G = $(git cat-file commit HEAD | sed -ne \$p) &&
239 blob1=$(git rev-parse --short HEAD^:file1) &&
240 blob2=$(git rev-parse --short HEAD:file1) &&
241 commit=$(git rev-parse --short HEAD)
244 test_expect_success 'stop on conflicting pick' '
245 cat >expect <<-EOF &&
246 diff --git a/file1 b/file1
247 index $blob1..$blob2 100644
254 cat >expect2 <<-EOF &&
261 git tag new-branch1 &&
262 test_must_fail git rebase -i master &&
263 test "$(git rev-parse HEAD~3)" = "$(git rev-parse master)" &&
264 test_cmp expect .git/rebase-merge/patch &&
265 test_cmp expect2 file1 &&
266 test "$(git diff --name-status |
267 sed -n -e "/^U/s/^U[^a-z]*//p")" = file1 &&
268 test 4 = $(grep -v "^#" < .git/rebase-merge/done | wc -l) &&
269 test 0 = $(grep -c "^[^#]" < .git/rebase-merge/git-rebase-todo)
272 test_expect_success 'show conflicted patch' '
273 GIT_TRACE=1 git rebase --show-current-patch >/dev/null 2>stderr &&
274 grep "show.*REBASE_HEAD" stderr &&
275 # the original stopped-sha1 is abbreviated
276 stopped_sha1="$(git rev-parse $(cat ".git/rebase-merge/stopped-sha"))" &&
277 test "$(git rev-parse REBASE_HEAD)" = "$stopped_sha1"
280 test_expect_success 'abort' '
281 git rebase --abort &&
282 test_cmp_rev new-branch1 HEAD &&
283 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
284 test_path_is_missing .git/rebase-merge
287 test_expect_success 'abort with error when new base cannot be checked out' '
288 git rm --cached file1 &&
289 git commit -m "remove file in base" &&
290 test_must_fail git rebase -i master > output 2>&1 &&
291 test_i18ngrep "The following untracked working tree files would be overwritten by checkout:" \
293 test_i18ngrep "file1" output &&
294 test_path_is_missing .git/rebase-merge &&
295 git reset --hard HEAD^
298 test_expect_success 'retain authorship' '
302 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
304 git rebase -i --onto master HEAD^ &&
305 git show HEAD | grep "^Author: Twerp Snog"
308 test_expect_success 'retain authorship w/ conflicts' '
309 oGIT_AUTHOR_NAME=$GIT_AUTHOR_NAME &&
310 test_when_finished "GIT_AUTHOR_NAME=\$oGIT_AUTHOR_NAME" &&
312 git reset --hard twerp &&
313 test_commit a conflict a conflict-a &&
314 git reset --hard twerp &&
316 GIT_AUTHOR_NAME=AttributeMe &&
317 export GIT_AUTHOR_NAME &&
318 test_commit b conflict b conflict-b &&
319 GIT_AUTHOR_NAME=$oGIT_AUTHOR_NAME &&
321 test_must_fail git rebase -i conflict-a &&
322 echo resolved >conflict &&
324 git rebase --continue &&
325 test_cmp_rev conflict-a^0 HEAD^ &&
330 test_expect_success 'squash' '
331 git reset --hard twerp &&
334 GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 &&
335 echo "******************************" &&
338 FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \
339 git rebase -i --onto master HEAD~2
341 test B = $(cat file7) &&
342 test_cmp_rev HEAD^ master
345 test_expect_success 'retain authorship when squashing' '
346 git show HEAD | grep "^Author: Twerp Snog"
349 test_expect_success REBASE_P '-p handles "no changes" gracefully' '
350 HEAD=$(git rev-parse HEAD) &&
351 git rebase -i -p HEAD^ &&
352 git update-index --refresh &&
353 git diff-files --quiet &&
354 git diff-index --quiet --cached HEAD -- &&
355 test $HEAD = $(git rev-parse HEAD)
358 test_expect_failure REBASE_P 'exchange two commits with -p' '
362 FAKE_LINES="2 1" git rebase -i -p HEAD~2
364 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
365 test G = $(git cat-file commit HEAD | sed -ne \$p)
368 test_expect_success REBASE_P 'preserve merges with -p' '
369 git checkout -b to-be-preserved master^ &&
370 : > unrelated-file &&
371 git add unrelated-file &&
373 git commit -m "unrelated" &&
374 git checkout -b another-branch master &&
377 git commit -m J file1 &&
379 git merge to-be-preserved &&
382 git commit -m K file1 &&
385 git commit -m L1 file1 &&
386 git checkout HEAD^ &&
387 echo 1 > unrelated-file &&
389 git commit -m L2 unrelated-file &&
391 git merge another-branch &&
394 git commit -m M file1 &&
395 git checkout -b to-be-rebased &&
397 git rebase -i -p --onto branch1 master &&
398 git update-index --refresh &&
399 git diff-files --quiet &&
400 git diff-index --quiet --cached HEAD -- &&
401 test_cmp_rev HEAD~6 branch1 &&
402 test_cmp_rev HEAD~4^2 to-be-preserved &&
403 test_cmp_rev HEAD^^2^ HEAD^^^ &&
404 test $(git show HEAD~5:file1) = B &&
405 test $(git show HEAD~3:file1) = C &&
406 test $(git show HEAD:file1) = E &&
407 test $(git show HEAD:unrelated-file) = 1
410 test_expect_success REBASE_P 'edit ancestor with -p' '
413 FAKE_LINES="1 2 edit 3 4" git rebase -i -p HEAD~3
415 echo 2 > unrelated-file &&
417 git commit -m L2-modified --amend unrelated-file &&
418 git rebase --continue &&
419 git update-index --refresh &&
420 git diff-files --quiet &&
421 git diff-index --quiet --cached HEAD -- &&
422 test $(git show HEAD:unrelated-file) = 2
425 test_expect_success '--continue tries to commit' '
426 git reset --hard D &&
430 test_must_fail git rebase -i --onto new-branch1 HEAD^ &&
431 echo resolved > file1 &&
433 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue
435 test_cmp_rev HEAD^ new-branch1 &&
436 git show HEAD | grep chouette
439 test_expect_success 'verbose flag is heeded, even after --continue' '
440 git reset --hard master@{1} &&
442 test_must_fail git rebase -v -i --onto new-branch1 HEAD^ &&
443 echo resolved > file1 &&
445 git rebase --continue > output &&
446 grep "^ file1 | 2 +-$" output
449 test_expect_success C_LOCALE_OUTPUT 'multi-squash only fires up editor once' '
450 base=$(git rev-parse HEAD~4) &&
453 FAKE_COMMIT_AMEND="ONCE" \
454 FAKE_LINES="1 squash 2 squash 3 squash 4" \
455 EXPECT_HEADER_COUNT=4 \
458 test $base = $(git rev-parse HEAD^) &&
459 test 1 = $(git show | grep ONCE | wc -l)
462 test_expect_success C_LOCALE_OUTPUT 'multi-fixup does not fire up editor' '
463 git checkout -b multi-fixup E &&
464 base=$(git rev-parse HEAD~4) &&
467 FAKE_COMMIT_AMEND="NEVER" \
468 FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \
471 test $base = $(git rev-parse HEAD^) &&
472 test 0 = $(git show | grep NEVER | wc -l) &&
473 git checkout @{-1} &&
474 git branch -D multi-fixup
477 test_expect_success 'commit message used after conflict' '
478 git checkout -b conflict-fixup conflict-branch &&
479 base=$(git rev-parse HEAD~4) &&
482 test_must_fail env FAKE_LINES="1 fixup 3 fixup 4" \
483 git rebase -i $base &&
484 echo three > conflict &&
486 FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \
487 git rebase --continue
489 test $base = $(git rev-parse HEAD^) &&
490 test 1 = $(git show | grep ONCE | wc -l) &&
491 git checkout @{-1} &&
492 git branch -D conflict-fixup
495 test_expect_success 'commit message retained after conflict' '
496 git checkout -b conflict-squash conflict-branch &&
497 base=$(git rev-parse HEAD~4) &&
500 test_must_fail env FAKE_LINES="1 fixup 3 squash 4" \
501 git rebase -i $base &&
502 echo three > conflict &&
504 FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \
505 git rebase --continue
507 test $base = $(git rev-parse HEAD^) &&
508 test 2 = $(git show | grep TWICE | wc -l) &&
509 git checkout @{-1} &&
510 git branch -D conflict-squash
513 test_expect_success C_LOCALE_OUTPUT 'squash and fixup generate correct log messages' '
514 cat >expect-squash-fixup <<-\EOF &&
521 git checkout -b squash-fixup E &&
522 base=$(git rev-parse HEAD~4) &&
525 FAKE_COMMIT_AMEND="ONCE" \
526 FAKE_LINES="1 fixup 2 squash 3 fixup 4" \
527 EXPECT_HEADER_COUNT=4 \
530 git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup &&
531 test_cmp expect-squash-fixup actual-squash-fixup &&
532 git cat-file commit HEAD@{2} |
533 grep "^# This is a combination of 3 commits\." &&
534 git cat-file commit HEAD@{3} |
535 grep "^# This is a combination of 2 commits\." &&
536 git checkout @{-1} &&
537 git branch -D squash-fixup
540 test_expect_success C_LOCALE_OUTPUT 'squash ignores comments' '
541 git checkout -b skip-comments E &&
542 base=$(git rev-parse HEAD~4) &&
545 FAKE_COMMIT_AMEND="ONCE" \
546 FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \
547 EXPECT_HEADER_COUNT=4 \
550 test $base = $(git rev-parse HEAD^) &&
551 test 1 = $(git show | grep ONCE | wc -l) &&
552 git checkout @{-1} &&
553 git branch -D skip-comments
556 test_expect_success C_LOCALE_OUTPUT 'squash ignores blank lines' '
557 git checkout -b skip-blank-lines E &&
558 base=$(git rev-parse HEAD~4) &&
561 FAKE_COMMIT_AMEND="ONCE" \
562 FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \
563 EXPECT_HEADER_COUNT=4 \
566 test $base = $(git rev-parse HEAD^) &&
567 test 1 = $(git show | grep ONCE | wc -l) &&
568 git checkout @{-1} &&
569 git branch -D skip-blank-lines
572 test_expect_success 'squash works as expected' '
573 git checkout -b squash-works no-conflict-branch &&
574 one=$(git rev-parse HEAD~3) &&
577 FAKE_LINES="1 s 3 2" EXPECT_HEADER_COUNT=2 git rebase -i HEAD~3
579 test $one = $(git rev-parse HEAD~2)
582 test_expect_success 'interrupted squash works as expected' '
583 git checkout -b interrupted-squash conflict-branch &&
584 one=$(git rev-parse HEAD~3) &&
587 test_must_fail env FAKE_LINES="1 squash 3 2" \
590 test_write_lines one two four > conflict &&
592 test_must_fail git rebase --continue &&
593 echo resolved > conflict &&
595 git rebase --continue &&
596 test $one = $(git rev-parse HEAD~2)
599 test_expect_success 'interrupted squash works as expected (case 2)' '
600 git checkout -b interrupted-squash2 conflict-branch &&
601 one=$(git rev-parse HEAD~3) &&
604 test_must_fail env FAKE_LINES="3 squash 1 2" \
607 test_write_lines one four > conflict &&
609 test_must_fail git rebase --continue &&
610 test_write_lines one two four > conflict &&
612 test_must_fail git rebase --continue &&
613 echo resolved > conflict &&
615 git rebase --continue &&
616 test $one = $(git rev-parse HEAD~2)
619 test_expect_success '--continue tries to commit, even for "edit"' '
620 echo unrelated > file7 &&
623 git commit -m "unrelated change" &&
624 parent=$(git rev-parse HEAD^) &&
628 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
629 echo edited > file7 &&
631 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue
633 test edited = $(git show HEAD:file7) &&
634 git show HEAD | grep chouette &&
635 test $parent = $(git rev-parse HEAD^)
638 test_expect_success 'aborted --continue does not squash commits after "edit"' '
639 old=$(git rev-parse HEAD) &&
643 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
644 echo "edited again" > file7 &&
646 test_must_fail env FAKE_COMMIT_MESSAGE=" " git rebase --continue
648 test $old = $(git rev-parse HEAD) &&
652 test_expect_success 'auto-amend only edited commits after "edit"' '
656 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
657 echo "edited again" > file7 &&
659 FAKE_COMMIT_MESSAGE="edited file7 again" git commit &&
660 echo "and again" > file7 &&
663 test_must_fail env FAKE_COMMIT_MESSAGE="and again" \
664 git rebase --continue
669 test_expect_success 'clean error after failed "exec"' '
671 test_when_finished "git rebase --abort || :" &&
674 test_must_fail env FAKE_LINES="1 exec_false" git rebase -i HEAD^
676 echo "edited again" > file7 &&
678 test_must_fail git rebase --continue 2>error &&
679 test_i18ngrep "you have staged changes in your working tree" error
682 test_expect_success 'rebase a detached HEAD' '
683 grandparent=$(git rev-parse HEAD~2) &&
684 git checkout $(git rev-parse HEAD) &&
688 FAKE_LINES="2 1" git rebase -i HEAD~2
690 test $grandparent = $(git rev-parse HEAD~2)
693 test_expect_success 'rebase a commit violating pre-commit' '
695 mkdir -p .git/hooks &&
696 write_script .git/hooks/pre-commit <<-\EOF &&
697 test -z "$(git diff --cached --check)"
699 echo "monde! " >> file1 &&
701 test_must_fail git commit -m doesnt-verify file1 &&
702 git commit -m doesnt-verify --no-verify file1 &&
706 FAKE_LINES=2 git rebase -i HEAD~2
710 test_expect_success 'rebase with a file named HEAD in worktree' '
714 git checkout -b branch3 A &&
717 GIT_AUTHOR_NAME="Squashed Away" &&
718 export GIT_AUTHOR_NAME &&
721 git commit -m "Add head" &&
724 git commit -m "Add body"
729 FAKE_LINES="1 squash 2" git rebase -i @{-1}
731 test "$(git show -s --pretty=format:%an)" = "Squashed Away"
735 test_expect_success 'do "noop" when there is nothing to cherry-pick' '
737 git checkout -b branch4 HEAD &&
738 GIT_EDITOR=: git commit --amend \
739 --author="Somebody else <somebody@else.com>" &&
740 test $(git rev-parse branch3) != $(git rev-parse branch4) &&
741 git rebase -i branch3 &&
742 test_cmp_rev branch3 branch4
746 test_expect_success 'submodule rebase setup' '
750 cd sub && git init && >elif &&
751 git add elif && git commit -m "submodule initial"
756 git commit -m "One" &&
759 git commit -a -m "Two" &&
761 cd sub && echo 3 >elif &&
762 git commit -a -m "submodule second"
765 git commit -a -m "Three changes submodule"
768 test_expect_success 'submodule rebase -i' '
771 FAKE_LINES="1 squash 2 3" git rebase -i A
775 test_expect_success 'submodule conflict setup' '
776 git tag submodule-base &&
777 git checkout HEAD^ &&
779 cd sub && git checkout HEAD^ && echo 4 >elif &&
780 git add elif && git commit -m "submodule conflict"
784 git commit -m "Conflict in submodule" &&
785 git tag submodule-topic
788 test_expect_success 'rebase -i continue with only submodule staged' '
789 test_must_fail git rebase -i submodule-base &&
791 git rebase --continue &&
792 test $(git rev-parse submodule-base) != $(git rev-parse HEAD)
795 test_expect_success 'rebase -i continue with unstaged submodule' '
796 git checkout submodule-topic &&
798 test_must_fail git rebase -i submodule-base &&
800 git rebase --continue &&
801 test_cmp_rev submodule-base HEAD
804 test_expect_success 'avoid unnecessary reset' '
805 git checkout master &&
807 test-tool chmtime =123456789 file3 &&
808 git update-index --refresh &&
809 HEAD=$(git rev-parse HEAD) &&
810 git rebase -i HEAD~4 &&
811 test $HEAD = $(git rev-parse HEAD) &&
812 MTIME=$(test-tool chmtime --get file3) &&
813 test 123456789 = $MTIME
816 test_expect_success 'reword' '
817 git checkout -b reword-branch master &&
820 FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" \
822 git show HEAD | grep "E changed" &&
823 test $(git rev-parse master) != $(git rev-parse HEAD) &&
824 test_cmp_rev master^ HEAD^ &&
825 FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" \
827 git show HEAD^ | grep "D changed" &&
828 FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" \
830 git show HEAD~3 | grep "B changed" &&
831 FAKE_LINES="1 r 2 pick 3 p 4" FAKE_COMMIT_MESSAGE="C changed" \
834 git show HEAD~2 | grep "C changed"
837 test_expect_success 'rebase -i can copy notes' '
838 git config notes.rewrite.rebase true &&
839 git config notes.rewriteRef "refs/notes/*" &&
843 git notes add -m"a note" n3 &&
844 git rebase -i --onto n1 n2 &&
845 test "a note" = "$(git notes show HEAD)"
848 test_expect_success 'rebase -i can copy notes over a fixup' '
849 cat >expect <<-\EOF &&
854 git reset --hard n3 &&
855 git notes add -m"an earlier note" n2 &&
858 GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 f 2" \
861 git notes show > output &&
862 test_cmp expect output
865 test_expect_success 'rebase while detaching HEAD' '
866 git symbolic-ref HEAD &&
867 grandparent=$(git rev-parse HEAD~2) &&
871 FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0
873 test $grandparent = $(git rev-parse HEAD~2) &&
874 test_must_fail git symbolic-ref HEAD
877 test_tick # Ensure that the rebased commits get a different timestamp.
878 test_expect_success 'always cherry-pick with --no-ff' '
879 git checkout no-ff-branch &&
880 git tag original-no-ff-branch &&
881 git rebase -i --no-ff A &&
884 test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) &&
885 git diff HEAD~$p original-no-ff-branch~$p > out &&
886 test_must_be_empty out
888 test_cmp_rev HEAD~3 original-no-ff-branch~3 &&
889 git diff HEAD~3 original-no-ff-branch~3 > out &&
890 test_must_be_empty out
893 test_expect_success 'set up commits with funny messages' '
894 git checkout -b funny A &&
897 git commit -a -m "end with slash\\" &&
900 git commit -a -m "something (\000) that looks like octal" &&
903 git commit -a -m "something (\n) that looks like a newline" &&
906 git commit -a -m "another commit"
909 test_expect_success 'rebase-i history with funny messages' '
910 git rev-list A..funny >expect &&
914 FAKE_LINES="1 2 3 4" git rebase -i A
916 git rev-list A.. >actual &&
917 test_cmp expect actual
920 test_expect_success 'prepare for rebase -i --exec' '
921 git checkout master &&
922 git checkout -b execute &&
923 test_commit one_exec main.txt one_exec &&
924 test_commit two_exec main.txt two_exec &&
925 test_commit three_exec main.txt three_exec
928 test_expect_success 'running "git rebase -i --exec git show HEAD"' '
931 git rebase -i --exec "git show HEAD" HEAD~2 >actual &&
932 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
934 git rebase -i HEAD~2 >expect
936 sed -e "1,9d" expect >expected &&
937 test_cmp expected actual
940 test_expect_success 'running "git rebase --exec git show HEAD -i"' '
941 git reset --hard execute &&
944 git rebase --exec "git show HEAD" -i HEAD~2 >actual &&
945 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
947 git rebase -i HEAD~2 >expect
949 sed -e "1,9d" expect >expected &&
950 test_cmp expected actual
953 test_expect_success 'running "git rebase -ix git show HEAD"' '
954 git reset --hard execute &&
957 git rebase -ix "git show HEAD" HEAD~2 >actual &&
958 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
960 git rebase -i HEAD~2 >expect
962 sed -e "1,9d" expect >expected &&
963 test_cmp expected actual
967 test_expect_success 'rebase -ix with several <CMD>' '
968 git reset --hard execute &&
971 git rebase -ix "git show HEAD; pwd" HEAD~2 >actual &&
972 FAKE_LINES="1 exec_git_show_HEAD;_pwd 2 exec_git_show_HEAD;_pwd" &&
974 git rebase -i HEAD~2 >expect
976 sed -e "1,9d" expect >expected &&
977 test_cmp expected actual
980 test_expect_success 'rebase -ix with several instances of --exec' '
981 git reset --hard execute &&
984 git rebase -i --exec "git show HEAD" --exec "pwd" HEAD~2 >actual &&
985 FAKE_LINES="1 exec_git_show_HEAD exec_pwd 2
986 exec_git_show_HEAD exec_pwd" &&
988 git rebase -i HEAD~2 >expect
990 sed -e "1,11d" expect >expected &&
991 test_cmp expected actual
994 test_expect_success C_LOCALE_OUTPUT 'rebase -ix with --autosquash' '
995 git reset --hard execute &&
996 git checkout -b autosquash &&
997 echo second >second.txt &&
998 git add second.txt &&
999 git commit -m "fixup! two_exec" &&
1000 echo bis >bis.txt &&
1002 git commit -m "fixup! two_exec" &&
1003 git checkout -b autosquash_actual &&
1004 git rebase -i --exec "git show HEAD" --autosquash HEAD~4 >actual &&
1005 git checkout autosquash &&
1008 git checkout -b autosquash_expected &&
1009 FAKE_LINES="1 fixup 3 fixup 4 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
1010 export FAKE_LINES &&
1011 git rebase -i HEAD~4 >expect
1013 sed -e "1,13d" expect >expected &&
1014 test_cmp expected actual
1017 test_expect_success 'rebase --exec works without -i ' '
1018 git reset --hard execute &&
1019 rm -rf exec_output &&
1020 EDITOR="echo >invoked_editor" git rebase --exec "echo a line >>exec_output" HEAD~2 2>actual &&
1021 test_i18ngrep "Successfully rebased and updated" actual &&
1022 test_line_count = 2 exec_output &&
1023 test_path_is_missing invoked_editor
1026 test_expect_success 'rebase -i --exec without <CMD>' '
1027 git reset --hard execute &&
1028 test_must_fail git rebase -i --exec 2>actual &&
1029 test_i18ngrep "requires a value" actual &&
1033 test_expect_success 'rebase -i --root re-order and drop commits' '
1037 FAKE_LINES="3 1 2 5" git rebase -i --root
1039 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1040 test B = $(git cat-file commit HEAD^ | sed -ne \$p) &&
1041 test A = $(git cat-file commit HEAD^^ | sed -ne \$p) &&
1042 test C = $(git cat-file commit HEAD^^^ | sed -ne \$p) &&
1043 test 0 = $(git cat-file commit HEAD^^^ | grep -c ^parent\ )
1046 test_expect_success 'rebase -i --root retain root commit author and message' '
1050 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
1053 FAKE_LINES="2" git rebase -i --root
1055 git cat-file commit HEAD | grep -q "^author Twerp Snog" &&
1056 git cat-file commit HEAD | grep -q "^different author$"
1059 test_expect_success 'rebase -i --root temporary sentinel commit' '
1063 test_must_fail env FAKE_LINES="2" git rebase -i --root
1065 git cat-file commit HEAD | grep "^tree $EMPTY_TREE" &&
1069 test_expect_success 'rebase -i --root fixup root commit' '
1073 FAKE_LINES="1 fixup 2" git rebase -i --root
1075 test A = $(git cat-file commit HEAD | sed -ne \$p) &&
1076 test B = $(git show HEAD:file1) &&
1077 test 0 = $(git cat-file commit HEAD | grep -c ^parent\ )
1080 test_expect_success 'rebase -i --root reword original root commit' '
1081 test_when_finished "test_might_fail git rebase --abort" &&
1082 git checkout -b reword-original-root-branch master &&
1085 FAKE_LINES="reword 1 2" FAKE_COMMIT_MESSAGE="A changed" \
1086 git rebase -i --root
1088 git show HEAD^ | grep "A changed" &&
1089 test -z "$(git show -s --format=%p HEAD^)"
1092 test_expect_success 'rebase -i --root reword new root commit' '
1093 test_when_finished "test_might_fail git rebase --abort" &&
1094 git checkout -b reword-now-root-branch master &&
1097 FAKE_LINES="reword 3 1" FAKE_COMMIT_MESSAGE="C changed" \
1098 git rebase -i --root
1100 git show HEAD^ | grep "C changed" &&
1101 test -z "$(git show -s --format=%p HEAD^)"
1104 test_expect_success 'rebase -i --root when root has untracked file conflict' '
1105 test_when_finished "reset_rebase" &&
1106 git checkout -b failing-root-pick A &&
1109 git commit -m "remove file 1 add file 2" &&
1113 test_must_fail env FAKE_LINES="1 2" git rebase -i --root
1116 git rebase --continue &&
1117 test "$(git log -1 --format=%B)" = "remove file 1 add file 2" &&
1118 test "$(git rev-list --count HEAD)" = 2
1121 test_expect_success 'rebase -i --root reword root when root has untracked file conflict' '
1122 test_when_finished "reset_rebase" &&
1126 test_must_fail env FAKE_LINES="reword 1 2" \
1127 FAKE_COMMIT_MESSAGE="Modified A" git rebase -i --root &&
1129 FAKE_COMMIT_MESSAGE="Reworded A" git rebase --continue
1131 test "$(git log -1 --format=%B HEAD^)" = "Reworded A" &&
1132 test "$(git rev-list --count HEAD)" = 2
1135 test_expect_success C_LOCALE_OUTPUT 'rebase --edit-todo does not work on non-interactive rebase' '
1136 git checkout reword-original-root-branch &&
1138 git checkout conflict-branch &&
1141 test_must_fail git rebase -f --apply --onto HEAD~2 HEAD~ &&
1142 test_must_fail git rebase --edit-todo
1147 test_expect_success 'rebase --edit-todo can be used to modify todo' '
1149 git checkout no-conflict-branch^0 &&
1152 FAKE_LINES="edit 1 2 3" git rebase -i HEAD~3 &&
1153 FAKE_LINES="2 1" git rebase --edit-todo &&
1154 git rebase --continue
1156 test M = $(git cat-file commit HEAD^ | sed -ne \$p) &&
1157 test L = $(git cat-file commit HEAD | sed -ne \$p)
1160 test_expect_success 'rebase -i produces readable reflog' '
1162 git branch -f branch-reflog-test H &&
1163 git rebase -i --onto I F branch-reflog-test &&
1164 cat >expect <<-\EOF &&
1165 rebase (finish): returning to refs/heads/branch-reflog-test
1168 rebase (start): checkout I
1170 git reflog -n4 HEAD |
1171 sed "s/[^:]*: //" >actual &&
1172 test_cmp expect actual
1175 test_expect_success 'rebase -i respects core.commentchar' '
1178 test_config core.commentchar "\\" &&
1179 write_script remove-all-but-first.sh <<-\EOF &&
1180 sed -e "2,\$s/^/\\\\/" "$1" >"$1.tmp" &&
1184 test_set_editor "$(pwd)/remove-all-but-first.sh" &&
1187 test B = $(git cat-file commit HEAD^ | sed -ne \$p)
1190 test_expect_success 'rebase -i respects core.commentchar=auto' '
1191 test_config core.commentchar auto &&
1192 write_script copy-edit-script.sh <<-\EOF &&
1195 test_when_finished "git rebase --abort || :" &&
1197 test_set_editor "$(pwd)/copy-edit-script.sh" &&
1200 test -z "$(grep -ve "^#" -e "^\$" -e "^pick" edit-script)"
1203 test_expect_success 'rebase -i, with <onto> and <upstream> specified as :/quuxery' '
1204 test_when_finished "git branch -D torebase" &&
1205 git checkout -b torebase branch1 &&
1206 upstream=$(git rev-parse ":/J") &&
1207 onto=$(git rev-parse ":/A") &&
1208 git rebase --onto $onto $upstream &&
1209 git reset --hard branch1 &&
1210 git rebase --onto ":/A" ":/J" &&
1211 git checkout branch1
1214 test_expect_success 'rebase -i with --strategy and -X' '
1215 git checkout -b conflict-merge-use-theirs conflict-branch &&
1216 git reset --hard HEAD^ &&
1217 echo five >conflict &&
1219 git commit -a -m "one file conflict" &&
1220 EDITOR=true git rebase -i --strategy=recursive -Xours conflict-branch &&
1221 test $(git show conflict-branch:conflict) = $(cat conflict) &&
1222 test $(cat file1) = Z
1225 test_expect_success 'interrupted rebase -i with --strategy and -X' '
1226 git checkout -b conflict-merge-use-theirs-interrupted conflict-branch &&
1227 git reset --hard HEAD^ &&
1229 git add breakpoint &&
1230 git commit -m "breakpoint for interactive mode" &&
1231 echo five >conflict &&
1233 git commit -a -m "one file conflict" &&
1236 FAKE_LINES="edit 1 2" git rebase -i --strategy=recursive \
1237 -Xours conflict-branch
1239 git rebase --continue &&
1240 test $(git show conflict-branch:conflict) = $(cat conflict) &&
1241 test $(cat file1) = Z
1244 test_expect_success 'rebase -i error on commits with \ in message' '
1245 current_head=$(git rev-parse HEAD) &&
1246 test_when_finished "git rebase --abort; git reset --hard $current_head; rm -f error" &&
1247 test_commit TO-REMOVE will-conflict old-content &&
1248 test_commit "\temp" will-conflict new-content dummy &&
1249 test_must_fail env EDITOR=true git rebase -i HEAD^ --onto HEAD^^ 2>error &&
1250 test_expect_code 1 grep " emp" error
1253 test_expect_success 'short commit ID setup' '
1254 test_when_finished "git checkout master" &&
1255 git checkout --orphan collide &&
1259 test_commit collide1 collide &&
1260 test_commit --notick collide2 collide &&
1261 test_commit --notick collide3 collide
1265 if test -n "$GIT_TEST_FIND_COLLIDER"
1267 author="$(unset test_tick; test_tick; git var GIT_AUTHOR_IDENT)"
1268 committer="$(unset test_tick; test_tick; git var GIT_COMMITTER_IDENT)"
1269 blob="$(git rev-parse collide2:collide)"
1270 from="$(git rev-parse collide1^0)"
1271 repl="commit refs/heads/collider-&\\n"
1272 repl="${repl}author $author\\ncommitter $committer\\n"
1273 repl="${repl}data <<EOF\\ncollide2 &\\nEOF\\n"
1274 repl="${repl}from $from\\nM 100644 $blob collide\\n"
1275 test_seq 1 32768 | sed "s|.*|$repl|" >script &&
1276 git fast-import <script &&
1278 git for-each-ref >refs &&
1279 grep "^$(test_oid t3404_collision)" <refs >matches &&
1281 test_line_count -gt 2 matches || {
1282 echo "Could not find a collider" >&2
1287 test_expect_success 'short commit ID collide' '
1288 test_oid_cache <<-EOF &&
1289 # collision-related constants
1290 t3404_collision sha1:6bcd
1291 t3404_collision sha256:0161
1292 t3404_collider sha1:ac4f2ee
1293 t3404_collider sha256:16697
1295 test_when_finished "reset_rebase && git checkout master" &&
1296 git checkout collide &&
1297 colliding_id=$(test_oid t3404_collision) &&
1298 hexsz=$(test_oid hexsz) &&
1299 test $colliding_id = "$(git rev-parse HEAD | cut -c 1-4)" &&
1300 test_config core.abbrev 4 &&
1305 FAKE_COMMIT_MESSAGE="collide2 $(test_oid t3404_collider)" \
1306 FAKE_LINES="reword 1 break 2" git rebase -i HEAD~2 &&
1307 test $colliding_id = "$(git rev-parse HEAD | cut -c 1-4)" &&
1308 grep "^pick $colliding_id " \
1309 .git/rebase-merge/git-rebase-todo.tmp &&
1310 grep "^pick [0-9a-f]\{$hexsz\}" \
1311 .git/rebase-merge/git-rebase-todo &&
1312 grep "^pick [0-9a-f]\{$hexsz\}" \
1313 .git/rebase-merge/git-rebase-todo.backup &&
1314 git rebase --continue
1316 collide2="$(git rev-parse HEAD~1 | cut -c 1-4)" &&
1317 collide3="$(git rev-parse collide3 | cut -c 1-4)" &&
1318 test "$collide2" = "$collide3"
1321 test_expect_success 'respect core.abbrev' '
1322 git config core.abbrev 12 &&
1324 set_cat_todo_editor &&
1325 test_must_fail git rebase -i HEAD~4 >todo-list
1327 test 4 = $(grep -c "pick [0-9a-f]\{12,\}" todo-list)
1330 test_expect_success 'todo count' '
1331 write_script dump-raw.sh <<-\EOF &&
1335 test_set_editor "$(pwd)/dump-raw.sh" &&
1336 git rebase -i HEAD~4 >actual
1338 test_i18ngrep "^# Rebase ..* onto ..* ([0-9]" actual
1341 test_expect_success 'rebase -i commits that overwrite untracked files (pick)' '
1342 git checkout --force branch2 &&
1346 FAKE_LINES="edit 1 2" git rebase -i A
1348 test_cmp_rev HEAD F &&
1349 test_path_is_missing file6 &&
1351 test_must_fail git rebase --continue &&
1352 test_cmp_rev HEAD F &&
1354 git rebase --continue &&
1358 test_expect_success 'rebase -i commits that overwrite untracked files (squash)' '
1359 git checkout --force branch2 &&
1361 git tag original-branch2 &&
1364 FAKE_LINES="edit 1 squash 2" git rebase -i A
1366 test_cmp_rev HEAD F &&
1367 test_path_is_missing file6 &&
1369 test_must_fail git rebase --continue &&
1370 test_cmp_rev HEAD F &&
1372 git rebase --continue &&
1373 test $(git cat-file commit HEAD | sed -ne \$p) = I &&
1374 git reset --hard original-branch2
1377 test_expect_success 'rebase -i commits that overwrite untracked files (no ff)' '
1378 git checkout --force branch2 &&
1382 FAKE_LINES="edit 1 2" git rebase -i --no-ff A
1384 test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1385 test_path_is_missing file6 &&
1387 test_must_fail git rebase --continue &&
1388 test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1390 git rebase --continue &&
1391 test $(git cat-file commit HEAD | sed -ne \$p) = I
1394 test_expect_success 'rebase --continue removes CHERRY_PICK_HEAD' '
1395 git checkout -b commit-to-skip &&
1398 test_seq 5 | sed "s/$double/&&/" >seq &&
1401 git commit -m seq-$double
1404 git reset --hard HEAD~2 &&
1405 git cherry-pick seq-onto &&
1408 test_must_fail env FAKE_LINES= git rebase -i seq-onto
1410 test -d .git/rebase-merge &&
1411 git rebase --continue &&
1412 git diff --exit-code seq-onto &&
1413 test ! -d .git/rebase-merge &&
1414 test ! -f .git/CHERRY_PICK_HEAD
1417 rebase_setup_and_clean () {
1418 test_when_finished "
1419 git checkout master &&
1420 test_might_fail git branch -D $1 &&
1421 test_might_fail git rebase --abort
1423 git checkout -b $1 ${2:-master}
1426 test_expect_success 'drop' '
1427 rebase_setup_and_clean drop-test &&
1430 FAKE_LINES="1 drop 2 3 d 4 5" git rebase -i --root
1432 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1433 test C = $(git cat-file commit HEAD^ | sed -ne \$p) &&
1434 test A = $(git cat-file commit HEAD^^ | sed -ne \$p)
1437 test_expect_success 'rebase -i respects rebase.missingCommitsCheck = ignore' '
1438 test_config rebase.missingCommitsCheck ignore &&
1439 rebase_setup_and_clean missing-commit &&
1442 FAKE_LINES="1 2 3 4" git rebase -i --root 2>actual
1444 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1446 "Successfully rebased and updated refs/heads/missing-commit" \
1450 test_expect_success 'rebase -i respects rebase.missingCommitsCheck = warn' '
1451 cat >expect <<-EOF &&
1452 Warning: some commits may have been dropped accidentally.
1453 Dropped commits (newer to older):
1454 - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
1455 To avoid this message, use "drop" to explicitly remove a commit.
1457 test_config rebase.missingCommitsCheck warn &&
1458 rebase_setup_and_clean missing-commit &&
1461 FAKE_LINES="1 2 3 4" git rebase -i --root 2>actual.2
1463 head -n4 actual.2 >actual &&
1464 test_i18ncmp expect actual &&
1465 test D = $(git cat-file commit HEAD | sed -ne \$p)
1468 test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' '
1469 cat >expect <<-EOF &&
1470 Warning: some commits may have been dropped accidentally.
1471 Dropped commits (newer to older):
1472 - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
1473 - $(git rev-list --pretty=oneline --abbrev-commit -1 master~2)
1474 To avoid this message, use "drop" to explicitly remove a commit.
1476 Use '\''git config rebase.missingCommitsCheck'\'' to change the level of warnings.
1477 The possible behaviours are: ignore, warn, error.
1479 You can fix this with '\''git rebase --edit-todo'\'' and then run '\''git rebase --continue'\''.
1480 Or you can abort the rebase with '\''git rebase --abort'\''.
1482 test_config rebase.missingCommitsCheck error &&
1483 rebase_setup_and_clean missing-commit &&
1486 test_must_fail env FAKE_LINES="1 2 4" \
1487 git rebase -i --root 2>actual &&
1488 test_i18ncmp expect actual &&
1489 cp .git/rebase-merge/git-rebase-todo.backup \
1490 .git/rebase-merge/git-rebase-todo &&
1491 FAKE_LINES="1 2 drop 3 4 drop 5" git rebase --edit-todo
1493 git rebase --continue &&
1494 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1495 test B = $(git cat-file commit HEAD^ | sed -ne \$p)
1498 test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = ignore' '
1499 test_config rebase.missingCommitsCheck ignore &&
1500 rebase_setup_and_clean missing-commit &&
1503 FAKE_LINES="break 1 2 3 4 5" git rebase -i --root &&
1504 FAKE_LINES="1 2 3 4" git rebase --edit-todo &&
1505 git rebase --continue 2>actual
1507 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1509 "Successfully rebased and updated refs/heads/missing-commit" \
1513 test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = warn' '
1514 cat >expect <<-EOF &&
1515 error: invalid line 1: badcmd $(git rev-list --pretty=oneline --abbrev-commit -1 master~4)
1516 Warning: some commits may have been dropped accidentally.
1517 Dropped commits (newer to older):
1518 - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
1519 - $(git rev-list --pretty=oneline --abbrev-commit -1 master~4)
1520 To avoid this message, use "drop" to explicitly remove a commit.
1522 head -n4 expect >expect.2 &&
1523 tail -n1 expect >>expect.2 &&
1524 tail -n4 expect.2 >expect.3 &&
1525 test_config rebase.missingCommitsCheck warn &&
1526 rebase_setup_and_clean missing-commit &&
1529 test_must_fail env FAKE_LINES="bad 1 2 3 4 5" \
1530 git rebase -i --root &&
1531 cp .git/rebase-merge/git-rebase-todo.backup orig &&
1532 FAKE_LINES="2 3 4" git rebase --edit-todo 2>actual.2 &&
1533 head -n6 actual.2 >actual &&
1534 test_i18ncmp expect actual &&
1535 cp orig .git/rebase-merge/git-rebase-todo &&
1536 FAKE_LINES="1 2 3 4" git rebase --edit-todo 2>actual.2 &&
1537 head -n4 actual.2 >actual &&
1538 test_i18ncmp expect.3 actual &&
1539 git rebase --continue 2>actual
1541 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1543 "Successfully rebased and updated refs/heads/missing-commit" \
1547 test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = error' '
1548 cat >expect <<-EOF &&
1549 error: invalid line 1: badcmd $(git rev-list --pretty=oneline --abbrev-commit -1 master~4)
1550 Warning: some commits may have been dropped accidentally.
1551 Dropped commits (newer to older):
1552 - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
1553 - $(git rev-list --pretty=oneline --abbrev-commit -1 master~4)
1554 To avoid this message, use "drop" to explicitly remove a commit.
1556 Use '\''git config rebase.missingCommitsCheck'\'' to change the level of warnings.
1557 The possible behaviours are: ignore, warn, error.
1559 You can fix this with '\''git rebase --edit-todo'\'' and then run '\''git rebase --continue'\''.
1560 Or you can abort the rebase with '\''git rebase --abort'\''.
1562 tail -n11 expect >expect.2 &&
1563 head -n3 expect.2 >expect.3 &&
1564 tail -n7 expect.2 >>expect.3 &&
1565 test_config rebase.missingCommitsCheck error &&
1566 rebase_setup_and_clean missing-commit &&
1569 test_must_fail env FAKE_LINES="bad 1 2 3 4 5" \
1570 git rebase -i --root &&
1571 cp .git/rebase-merge/git-rebase-todo.backup orig &&
1572 test_must_fail env FAKE_LINES="2 3 4" \
1573 git rebase --edit-todo 2>actual &&
1574 test_i18ncmp expect actual &&
1575 test_must_fail git rebase --continue 2>actual &&
1576 test_i18ncmp expect.2 actual &&
1577 test_must_fail git rebase --edit-todo &&
1578 cp orig .git/rebase-merge/git-rebase-todo &&
1579 test_must_fail env FAKE_LINES="1 2 3 4" \
1580 git rebase --edit-todo 2>actual &&
1581 test_i18ncmp expect.3 actual &&
1582 test_must_fail git rebase --continue 2>actual &&
1583 test_i18ncmp expect.3 actual &&
1584 cp orig .git/rebase-merge/git-rebase-todo &&
1585 FAKE_LINES="1 2 3 4 drop 5" git rebase --edit-todo &&
1586 git rebase --continue 2>actual
1588 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1590 "Successfully rebased and updated refs/heads/missing-commit" \
1594 test_expect_success 'rebase.missingCommitsCheck = error after resolving conflicts' '
1595 test_config rebase.missingCommitsCheck error &&
1598 FAKE_LINES="drop 1 break 2 3 4" git rebase -i A E
1600 git rebase --edit-todo &&
1601 test_must_fail git rebase --continue &&
1604 git rebase --continue
1607 test_expect_success 'rebase.missingCommitsCheck = error when editing for a second time' '
1608 test_config rebase.missingCommitsCheck error &&
1611 FAKE_LINES="1 break 2 3" git rebase -i A D &&
1612 cp .git/rebase-merge/git-rebase-todo todo &&
1613 test_must_fail env FAKE_LINES=2 git rebase --edit-todo &&
1614 GIT_SEQUENCE_EDITOR="cp todo" git rebase --edit-todo &&
1615 git rebase --continue
1619 test_expect_success 'respects rebase.abbreviateCommands with fixup, squash and exec' '
1620 rebase_setup_and_clean abbrevcmd &&
1621 test_commit "first" file1.txt "first line" first &&
1622 test_commit "second" file1.txt "another line" second &&
1623 test_commit "fixup! first" file2.txt "first line again" first_fixup &&
1624 test_commit "squash! second" file1.txt "another line here" second_squash &&
1625 cat >expected <<-EOF &&
1626 p $(git rev-list --abbrev-commit -1 first) first
1627 f $(git rev-list --abbrev-commit -1 first_fixup) fixup! first
1629 p $(git rev-list --abbrev-commit -1 second) second
1630 s $(git rev-list --abbrev-commit -1 second_squash) squash! second
1633 git checkout abbrevcmd &&
1634 test_config rebase.abbreviateCommands true &&
1636 set_cat_todo_editor &&
1637 test_must_fail git rebase -i --exec "git show HEAD" \
1638 --autosquash master >actual
1640 test_cmp expected actual
1643 test_expect_success 'static check of bad command' '
1644 rebase_setup_and_clean bad-cmd &&
1647 test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \
1648 git rebase -i --root 2>actual &&
1649 test_i18ngrep "badcmd $(git rev-list --oneline -1 master~1)" \
1651 test_i18ngrep "You can fix this with .git rebase --edit-todo.." \
1653 FAKE_LINES="1 2 3 drop 4 5" git rebase --edit-todo
1655 git rebase --continue &&
1656 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1657 test C = $(git cat-file commit HEAD^ | sed -ne \$p)
1660 test_expect_success 'tabs and spaces are accepted in the todolist' '
1661 rebase_setup_and_clean indented-comment &&
1662 write_script add-indent.sh <<-\EOF &&
1664 # Turn single spaces into space/tab mix
1665 sed "1s/ / /g; 2s/ / /g; 3s/ / /g" "$1"
1666 printf "\n\t# comment\n #more\n\t # comment\n"
1671 test_set_editor "$(pwd)/add-indent.sh" &&
1672 git rebase -i HEAD^^^
1674 test E = $(git cat-file commit HEAD | sed -ne \$p)
1677 test_expect_success 'static check of bad SHA-1' '
1678 rebase_setup_and_clean bad-sha &&
1681 test_must_fail env FAKE_LINES="1 2 edit fakesha 3 4 5 #" \
1682 git rebase -i --root 2>actual &&
1683 test_i18ngrep "edit XXXXXXX False commit" actual &&
1684 test_i18ngrep "You can fix this with .git rebase --edit-todo.." \
1686 FAKE_LINES="1 2 4 5 6" git rebase --edit-todo
1688 git rebase --continue &&
1689 test E = $(git cat-file commit HEAD | sed -ne \$p)
1692 test_expect_success 'editor saves as CR/LF' '
1693 git checkout -b with-crlf &&
1694 write_script add-crs.sh <<-\EOF &&
1695 sed -e "s/\$/Q/" <"$1" | tr Q "\\015" >"$1".new &&
1699 test_set_editor "$(pwd)/add-crs.sh" &&
1704 test_expect_success 'rebase -i --gpg-sign=<key-id>' '
1705 test_when_finished "test_might_fail git rebase --abort" &&
1708 FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" \
1711 test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err
1714 test_expect_success 'rebase -i --gpg-sign=<key-id> overrides commit.gpgSign' '
1715 test_when_finished "test_might_fail git rebase --abort" &&
1716 test_config commit.gpgsign true &&
1719 FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" \
1722 test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err
1725 test_expect_success 'valid author header after --root swap' '
1726 rebase_setup_and_clean author-header no-conflict-branch &&
1727 git commit --amend --author="Au ${SQ}thor <author@example.com>" --no-edit &&
1728 git cat-file commit HEAD | grep ^author >expected &&
1731 FAKE_LINES="5 1" git rebase -i --root
1733 git cat-file commit HEAD^ | grep ^author >actual &&
1734 test_cmp expected actual
1737 test_expect_success 'valid author header when author contains single quote' '
1738 rebase_setup_and_clean author-header no-conflict-branch &&
1739 git commit --amend --author="Au ${SQ}thor <author@example.com>" --no-edit &&
1740 git cat-file commit HEAD | grep ^author >expected &&
1743 FAKE_LINES="2" git rebase -i HEAD~2
1745 git cat-file commit HEAD | grep ^author >actual &&
1746 test_cmp expected actual
1749 test_expect_success 'post-commit hook is called' '
1750 test_when_finished "rm -f .git/hooks/post-commit" &&
1752 mkdir -p .git/hooks &&
1753 write_script .git/hooks/post-commit <<-\EOS &&
1754 git rev-parse HEAD >>actual
1758 FAKE_LINES="edit 4 1 reword 2 fixup 3" git rebase -i A E &&
1761 FAKE_COMMIT_MESSAGE=edited git rebase --continue
1763 git rev-parse HEAD@{5} HEAD@{4} HEAD@{3} HEAD@{2} HEAD@{1} HEAD \
1765 test_cmp expect actual
1768 test_expect_success 'correct error message for partial commit after empty pick' '
1769 test_when_finished "git rebase --abort" &&
1772 FAKE_LINES="2 1 1" &&
1773 export FAKE_LINES &&
1774 test_must_fail git rebase -i A D
1777 test_must_fail git commit file1 2>err &&
1778 test_i18ngrep "cannot do a partial commit during a rebase." err
1781 test_expect_success 'correct error message for commit --amend after empty pick' '
1782 test_when_finished "git rebase --abort" &&
1786 export FAKE_LINES &&
1787 test_must_fail git rebase -i A D
1790 test_must_fail git commit -a --amend 2>err &&
1791 test_i18ngrep "middle of a rebase -- cannot amend." err
1794 test_expect_success 'todo has correct onto hash' '
1795 GIT_SEQUENCE_EDITOR=cat git rebase -i no-conflict-branch~4 no-conflict-branch >actual &&
1796 onto=$(git rev-parse --short HEAD~4) &&
1797 test_i18ngrep "^# Rebase ..* onto $onto" actual
1800 # This must be the last test in this file
1801 test_expect_success '$EDITOR and friends are unchanged' '
1802 test_editor_unchanged