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 HEAD' '
76 cat >expect <<-\EOF &&
81 test_must_fail env FAKE_LINES="1 exec_true" \
82 git rebase -i HEAD^ >actual 2>&1
84 test_i18ncmp expect actual
87 test_expect_success 'rebase -i with the exec command' '
88 git checkout master &&
91 FAKE_LINES="1 exec_>touch-one
92 2 exec_>touch-two exec_false exec_>touch-three
93 3 4 exec_>\"touch-file__name_with_spaces\";_>touch-after-semicolon 5" &&
95 test_must_fail git rebase -i A
97 test_path_is_file touch-one &&
98 test_path_is_file touch-two &&
99 test_path_is_missing touch-three " (should have stopped before)" &&
100 test_cmp_rev C HEAD &&
101 git rebase --continue &&
102 test_path_is_file touch-three &&
103 test_path_is_file "touch-file name with spaces" &&
104 test_path_is_file touch-after-semicolon &&
105 test_cmp_rev master HEAD &&
109 test_expect_success 'rebase -i with the exec command runs from tree root' '
110 git checkout master &&
111 mkdir subdir && (cd subdir &&
113 FAKE_LINES="1 exec_>touch-subdir" \
116 test_path_is_file touch-subdir &&
120 test_expect_success 'rebase -i with exec allows git commands in subdirs' '
121 test_when_finished "rm -rf subdir" &&
122 test_when_finished "git rebase --abort ||:" &&
123 git checkout master &&
124 mkdir subdir && (cd subdir &&
126 FAKE_LINES="1 x_cd_subdir_&&_git_rev-parse_--is-inside-work-tree" \
131 test_expect_success 'rebase -i sets work tree properly' '
132 test_when_finished "rm -rf subdir" &&
133 test_when_finished "test_might_fail git rebase --abort" &&
135 git rebase -x "(cd subdir && git rev-parse --show-toplevel)" HEAD^ \
137 ! grep "/subdir$" actual
140 test_expect_success 'rebase -i with the exec command checks tree cleanness' '
141 git checkout master &&
144 test_must_fail env FAKE_LINES="exec_echo_foo_>file1 1" \
147 test_cmp_rev master^ HEAD &&
149 git rebase --continue
152 test_expect_success 'rebase -x with empty command fails' '
153 test_when_finished "git rebase --abort ||:" &&
154 test_must_fail env git rebase -x "" @ 2>actual &&
155 test_write_lines "error: empty exec command" >expected &&
156 test_i18ncmp expected actual &&
157 test_must_fail env git rebase -x " " @ 2>actual &&
158 test_i18ncmp expected actual
161 test_expect_success 'rebase -x with newline in command fails' '
162 test_when_finished "git rebase --abort ||:" &&
163 test_must_fail env git rebase -x "a${LF}b" @ 2>actual &&
164 test_write_lines "error: exec commands cannot contain newlines" \
166 test_i18ncmp expected actual
169 test_expect_success 'rebase -i with exec of inexistent command' '
170 git checkout master &&
171 test_when_finished "git rebase --abort" &&
174 test_must_fail env FAKE_LINES="exec_this-command-does-not-exist 1" \
175 git rebase -i HEAD^ >actual 2>&1
177 ! grep "Maybe git-rebase is broken" actual
180 test_expect_success 'implicit interactive rebase does not invoke sequence editor' '
181 test_when_finished "git rebase --abort ||:" &&
182 GIT_SEQUENCE_EDITOR="echo bad >" git rebase -x"echo one" @^
185 test_expect_success 'no changes are a nop' '
186 git checkout branch2 &&
188 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
189 test $(git rev-parse I) = $(git rev-parse HEAD)
192 test_expect_success 'test the [branch] option' '
193 git checkout -b dead-end &&
195 git commit -m "stop here" &&
196 git rebase -i F branch2 &&
197 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
198 test $(git rev-parse I) = $(git rev-parse branch2) &&
199 test $(git rev-parse I) = $(git rev-parse HEAD)
202 test_expect_success 'test --onto <branch>' '
203 git checkout -b test-onto branch2 &&
204 git rebase -i --onto branch1 F &&
205 test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" &&
206 test $(git rev-parse HEAD^) = $(git rev-parse branch1) &&
207 test $(git rev-parse I) = $(git rev-parse branch2)
210 test_expect_success 'rebase on top of a non-conflicting commit' '
211 git checkout branch1 &&
212 git tag original-branch1 &&
213 git rebase -i branch2 &&
214 test file6 = $(git diff --name-only original-branch1) &&
215 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
216 test $(git rev-parse I) = $(git rev-parse branch2) &&
217 test $(git rev-parse I) = $(git rev-parse HEAD~2)
220 test_expect_success 'reflog for the branch shows state before rebase' '
221 test $(git rev-parse branch1@{1}) = $(git rev-parse original-branch1)
224 test_expect_success 'reflog for the branch shows correct finish message' '
225 printf "rebase -i (finish): refs/heads/branch1 onto %s\n" \
226 "$(git rev-parse branch2)" >expected &&
227 git log -g --pretty=%gs -1 refs/heads/branch1 >actual &&
228 test_cmp expected actual
231 test_expect_success 'exchange two commits' '
234 FAKE_LINES="2 1" git rebase -i HEAD~2
236 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
237 test G = $(git cat-file commit HEAD | sed -ne \$p) &&
238 blob1=$(git rev-parse --short HEAD^:file1) &&
239 blob2=$(git rev-parse --short HEAD:file1) &&
240 commit=$(git rev-parse --short HEAD)
243 test_expect_success 'stop on conflicting pick' '
244 cat >expect <<-EOF &&
245 diff --git a/file1 b/file1
246 index $blob1..$blob2 100644
253 cat >expect2 <<-EOF &&
260 git tag new-branch1 &&
261 test_must_fail git rebase -i master &&
262 test "$(git rev-parse HEAD~3)" = "$(git rev-parse master)" &&
263 test_cmp expect .git/rebase-merge/patch &&
264 test_cmp expect2 file1 &&
265 test "$(git diff --name-status |
266 sed -n -e "/^U/s/^U[^a-z]*//p")" = file1 &&
267 test 4 = $(grep -v "^#" < .git/rebase-merge/done | wc -l) &&
268 test 0 = $(grep -c "^[^#]" < .git/rebase-merge/git-rebase-todo)
271 test_expect_success 'show conflicted patch' '
272 GIT_TRACE=1 git rebase --show-current-patch >/dev/null 2>stderr &&
273 grep "show.*REBASE_HEAD" stderr &&
274 # the original stopped-sha1 is abbreviated
275 stopped_sha1="$(git rev-parse $(cat ".git/rebase-merge/stopped-sha"))" &&
276 test "$(git rev-parse REBASE_HEAD)" = "$stopped_sha1"
279 test_expect_success 'abort' '
280 git rebase --abort &&
281 test $(git rev-parse new-branch1) = $(git rev-parse HEAD) &&
282 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
283 test_path_is_missing .git/rebase-merge
286 test_expect_success 'abort with error when new base cannot be checked out' '
287 git rm --cached file1 &&
288 git commit -m "remove file in base" &&
289 test_must_fail git rebase -i master > output 2>&1 &&
290 test_i18ngrep "The following untracked working tree files would be overwritten by checkout:" \
292 test_i18ngrep "file1" output &&
293 test_path_is_missing .git/rebase-merge &&
294 git reset --hard HEAD^
297 test_expect_success 'retain authorship' '
301 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
303 git rebase -i --onto master HEAD^ &&
304 git show HEAD | grep "^Author: Twerp Snog"
307 test_expect_success 'retain authorship w/ conflicts' '
308 oGIT_AUTHOR_NAME=$GIT_AUTHOR_NAME &&
309 test_when_finished "GIT_AUTHOR_NAME=\$oGIT_AUTHOR_NAME" &&
311 git reset --hard twerp &&
312 test_commit a conflict a conflict-a &&
313 git reset --hard twerp &&
315 GIT_AUTHOR_NAME=AttributeMe &&
316 export GIT_AUTHOR_NAME &&
317 test_commit b conflict b conflict-b &&
318 GIT_AUTHOR_NAME=$oGIT_AUTHOR_NAME &&
320 test_must_fail git rebase -i conflict-a &&
321 echo resolved >conflict &&
323 git rebase --continue &&
324 test $(git rev-parse conflict-a^0) = $(git rev-parse HEAD^) &&
329 test_expect_success 'squash' '
330 git reset --hard twerp &&
333 GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 &&
334 echo "******************************" &&
337 FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \
338 git rebase -i --onto master HEAD~2
340 test B = $(cat file7) &&
341 test $(git rev-parse HEAD^) = $(git rev-parse master)
344 test_expect_success 'retain authorship when squashing' '
345 git show HEAD | grep "^Author: Twerp Snog"
348 test_expect_success REBASE_P '-p handles "no changes" gracefully' '
349 HEAD=$(git rev-parse HEAD) &&
350 git rebase -i -p HEAD^ &&
351 git update-index --refresh &&
352 git diff-files --quiet &&
353 git diff-index --quiet --cached HEAD -- &&
354 test $HEAD = $(git rev-parse HEAD)
357 test_expect_failure REBASE_P 'exchange two commits with -p' '
361 FAKE_LINES="2 1" git rebase -i -p HEAD~2
363 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
364 test G = $(git cat-file commit HEAD | sed -ne \$p)
367 test_expect_success REBASE_P 'preserve merges with -p' '
368 git checkout -b to-be-preserved master^ &&
369 : > unrelated-file &&
370 git add unrelated-file &&
372 git commit -m "unrelated" &&
373 git checkout -b another-branch master &&
376 git commit -m J file1 &&
378 git merge to-be-preserved &&
381 git commit -m K file1 &&
384 git commit -m L1 file1 &&
385 git checkout HEAD^ &&
386 echo 1 > unrelated-file &&
388 git commit -m L2 unrelated-file &&
390 git merge another-branch &&
393 git commit -m M file1 &&
394 git checkout -b to-be-rebased &&
396 git rebase -i -p --onto branch1 master &&
397 git update-index --refresh &&
398 git diff-files --quiet &&
399 git diff-index --quiet --cached HEAD -- &&
400 test $(git rev-parse HEAD~6) = $(git rev-parse branch1) &&
401 test $(git rev-parse HEAD~4^2) = $(git rev-parse to-be-preserved) &&
402 test $(git rev-parse HEAD^^2^) = $(git rev-parse HEAD^^^) &&
403 test $(git show HEAD~5:file1) = B &&
404 test $(git show HEAD~3:file1) = C &&
405 test $(git show HEAD:file1) = E &&
406 test $(git show HEAD:unrelated-file) = 1
409 test_expect_success REBASE_P 'edit ancestor with -p' '
412 FAKE_LINES="1 2 edit 3 4" git rebase -i -p HEAD~3
414 echo 2 > unrelated-file &&
416 git commit -m L2-modified --amend unrelated-file &&
417 git rebase --continue &&
418 git update-index --refresh &&
419 git diff-files --quiet &&
420 git diff-index --quiet --cached HEAD -- &&
421 test $(git show HEAD:unrelated-file) = 2
424 test_expect_success '--continue tries to commit' '
425 git reset --hard D &&
429 test_must_fail git rebase -i --onto new-branch1 HEAD^ &&
430 echo resolved > file1 &&
432 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue
434 test $(git rev-parse HEAD^) = $(git rev-parse new-branch1) &&
435 git show HEAD | grep chouette
438 test_expect_success 'verbose flag is heeded, even after --continue' '
439 git reset --hard master@{1} &&
441 test_must_fail git rebase -v -i --onto new-branch1 HEAD^ &&
442 echo resolved > file1 &&
444 git rebase --continue > output &&
445 grep "^ file1 | 2 +-$" output
448 test_expect_success C_LOCALE_OUTPUT 'multi-squash only fires up editor once' '
449 base=$(git rev-parse HEAD~4) &&
452 FAKE_COMMIT_AMEND="ONCE" \
453 FAKE_LINES="1 squash 2 squash 3 squash 4" \
454 EXPECT_HEADER_COUNT=4 \
457 test $base = $(git rev-parse HEAD^) &&
458 test 1 = $(git show | grep ONCE | wc -l)
461 test_expect_success C_LOCALE_OUTPUT 'multi-fixup does not fire up editor' '
462 git checkout -b multi-fixup E &&
463 base=$(git rev-parse HEAD~4) &&
466 FAKE_COMMIT_AMEND="NEVER" \
467 FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \
470 test $base = $(git rev-parse HEAD^) &&
471 test 0 = $(git show | grep NEVER | wc -l) &&
472 git checkout @{-1} &&
473 git branch -D multi-fixup
476 test_expect_success 'commit message used after conflict' '
477 git checkout -b conflict-fixup conflict-branch &&
478 base=$(git rev-parse HEAD~4) &&
481 test_must_fail env FAKE_LINES="1 fixup 3 fixup 4" \
482 git rebase -i $base &&
483 echo three > conflict &&
485 FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \
486 git rebase --continue
488 test $base = $(git rev-parse HEAD^) &&
489 test 1 = $(git show | grep ONCE | wc -l) &&
490 git checkout @{-1} &&
491 git branch -D conflict-fixup
494 test_expect_success 'commit message retained after conflict' '
495 git checkout -b conflict-squash conflict-branch &&
496 base=$(git rev-parse HEAD~4) &&
499 test_must_fail env FAKE_LINES="1 fixup 3 squash 4" \
500 git rebase -i $base &&
501 echo three > conflict &&
503 FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \
504 git rebase --continue
506 test $base = $(git rev-parse HEAD^) &&
507 test 2 = $(git show | grep TWICE | wc -l) &&
508 git checkout @{-1} &&
509 git branch -D conflict-squash
512 test_expect_success C_LOCALE_OUTPUT 'squash and fixup generate correct log messages' '
513 cat >expect-squash-fixup <<-\EOF &&
520 git checkout -b squash-fixup E &&
521 base=$(git rev-parse HEAD~4) &&
524 FAKE_COMMIT_AMEND="ONCE" \
525 FAKE_LINES="1 fixup 2 squash 3 fixup 4" \
526 EXPECT_HEADER_COUNT=4 \
529 git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup &&
530 test_cmp expect-squash-fixup actual-squash-fixup &&
531 git cat-file commit HEAD@{2} |
532 grep "^# This is a combination of 3 commits\." &&
533 git cat-file commit HEAD@{3} |
534 grep "^# This is a combination of 2 commits\." &&
535 git checkout @{-1} &&
536 git branch -D squash-fixup
539 test_expect_success C_LOCALE_OUTPUT 'squash ignores comments' '
540 git checkout -b skip-comments E &&
541 base=$(git rev-parse HEAD~4) &&
544 FAKE_COMMIT_AMEND="ONCE" \
545 FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \
546 EXPECT_HEADER_COUNT=4 \
549 test $base = $(git rev-parse HEAD^) &&
550 test 1 = $(git show | grep ONCE | wc -l) &&
551 git checkout @{-1} &&
552 git branch -D skip-comments
555 test_expect_success C_LOCALE_OUTPUT 'squash ignores blank lines' '
556 git checkout -b skip-blank-lines E &&
557 base=$(git rev-parse HEAD~4) &&
560 FAKE_COMMIT_AMEND="ONCE" \
561 FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \
562 EXPECT_HEADER_COUNT=4 \
565 test $base = $(git rev-parse HEAD^) &&
566 test 1 = $(git show | grep ONCE | wc -l) &&
567 git checkout @{-1} &&
568 git branch -D skip-blank-lines
571 test_expect_success 'squash works as expected' '
572 git checkout -b squash-works no-conflict-branch &&
573 one=$(git rev-parse HEAD~3) &&
576 FAKE_LINES="1 s 3 2" EXPECT_HEADER_COUNT=2 git rebase -i HEAD~3
578 test $one = $(git rev-parse HEAD~2)
581 test_expect_success 'interrupted squash works as expected' '
582 git checkout -b interrupted-squash conflict-branch &&
583 one=$(git rev-parse HEAD~3) &&
586 test_must_fail env FAKE_LINES="1 squash 3 2" \
589 test_write_lines one two four > conflict &&
591 test_must_fail git rebase --continue &&
592 echo resolved > conflict &&
594 git rebase --continue &&
595 test $one = $(git rev-parse HEAD~2)
598 test_expect_success 'interrupted squash works as expected (case 2)' '
599 git checkout -b interrupted-squash2 conflict-branch &&
600 one=$(git rev-parse HEAD~3) &&
603 test_must_fail env FAKE_LINES="3 squash 1 2" \
606 test_write_lines one four > conflict &&
608 test_must_fail git rebase --continue &&
609 test_write_lines one two four > conflict &&
611 test_must_fail git rebase --continue &&
612 echo resolved > conflict &&
614 git rebase --continue &&
615 test $one = $(git rev-parse HEAD~2)
618 test_expect_success '--continue tries to commit, even for "edit"' '
619 echo unrelated > file7 &&
622 git commit -m "unrelated change" &&
623 parent=$(git rev-parse HEAD^) &&
627 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
628 echo edited > file7 &&
630 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue
632 test edited = $(git show HEAD:file7) &&
633 git show HEAD | grep chouette &&
634 test $parent = $(git rev-parse HEAD^)
637 test_expect_success 'aborted --continue does not squash commits after "edit"' '
638 old=$(git rev-parse HEAD) &&
642 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
643 echo "edited again" > file7 &&
645 test_must_fail env FAKE_COMMIT_MESSAGE=" " git rebase --continue
647 test $old = $(git rev-parse HEAD) &&
651 test_expect_success 'auto-amend only edited commits after "edit"' '
655 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
656 echo "edited again" > file7 &&
658 FAKE_COMMIT_MESSAGE="edited file7 again" git commit &&
659 echo "and again" > file7 &&
662 test_must_fail env FAKE_COMMIT_MESSAGE="and again" \
663 git rebase --continue
668 test_expect_success 'clean error after failed "exec"' '
670 test_when_finished "git rebase --abort || :" &&
673 test_must_fail env FAKE_LINES="1 exec_false" git rebase -i HEAD^
675 echo "edited again" > file7 &&
677 test_must_fail git rebase --continue 2>error &&
678 test_i18ngrep "you have staged changes in your working tree" error
681 test_expect_success 'rebase a detached HEAD' '
682 grandparent=$(git rev-parse HEAD~2) &&
683 git checkout $(git rev-parse HEAD) &&
687 FAKE_LINES="2 1" git rebase -i HEAD~2
689 test $grandparent = $(git rev-parse HEAD~2)
692 test_expect_success 'rebase a commit violating pre-commit' '
694 mkdir -p .git/hooks &&
695 write_script .git/hooks/pre-commit <<-\EOF &&
696 test -z "$(git diff --cached --check)"
698 echo "monde! " >> file1 &&
700 test_must_fail git commit -m doesnt-verify file1 &&
701 git commit -m doesnt-verify --no-verify file1 &&
705 FAKE_LINES=2 git rebase -i HEAD~2
709 test_expect_success 'rebase with a file named HEAD in worktree' '
713 git checkout -b branch3 A &&
716 GIT_AUTHOR_NAME="Squashed Away" &&
717 export GIT_AUTHOR_NAME &&
720 git commit -m "Add head" &&
723 git commit -m "Add body"
728 FAKE_LINES="1 squash 2" git rebase -i @{-1}
730 test "$(git show -s --pretty=format:%an)" = "Squashed Away"
734 test_expect_success 'do "noop" when there is nothing to cherry-pick' '
736 git checkout -b branch4 HEAD &&
737 GIT_EDITOR=: git commit --amend \
738 --author="Somebody else <somebody@else.com>" &&
739 test $(git rev-parse branch3) != $(git rev-parse branch4) &&
740 git rebase -i branch3 &&
741 test $(git rev-parse branch3) = $(git rev-parse branch4)
745 test_expect_success 'submodule rebase setup' '
749 cd sub && git init && >elif &&
750 git add elif && git commit -m "submodule initial"
755 git commit -m "One" &&
758 git commit -a -m "Two" &&
760 cd sub && echo 3 >elif &&
761 git commit -a -m "submodule second"
764 git commit -a -m "Three changes submodule"
767 test_expect_success 'submodule rebase -i' '
770 FAKE_LINES="1 squash 2 3" git rebase -i A
774 test_expect_success 'submodule conflict setup' '
775 git tag submodule-base &&
776 git checkout HEAD^ &&
778 cd sub && git checkout HEAD^ && echo 4 >elif &&
779 git add elif && git commit -m "submodule conflict"
783 git commit -m "Conflict in submodule" &&
784 git tag submodule-topic
787 test_expect_success 'rebase -i continue with only submodule staged' '
788 test_must_fail git rebase -i submodule-base &&
790 git rebase --continue &&
791 test $(git rev-parse submodule-base) != $(git rev-parse HEAD)
794 test_expect_success 'rebase -i continue with unstaged submodule' '
795 git checkout submodule-topic &&
797 test_must_fail git rebase -i submodule-base &&
799 git rebase --continue &&
800 test $(git rev-parse submodule-base) = $(git rev-parse HEAD)
803 test_expect_success 'avoid unnecessary reset' '
804 git checkout master &&
806 test-tool chmtime =123456789 file3 &&
807 git update-index --refresh &&
808 HEAD=$(git rev-parse HEAD) &&
809 git rebase -i HEAD~4 &&
810 test $HEAD = $(git rev-parse HEAD) &&
811 MTIME=$(test-tool chmtime --get file3) &&
812 test 123456789 = $MTIME
815 test_expect_success 'reword' '
816 git checkout -b reword-branch master &&
819 FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" \
821 git show HEAD | grep "E changed" &&
822 test $(git rev-parse master) != $(git rev-parse HEAD) &&
823 test $(git rev-parse master^) = $(git rev-parse HEAD^) &&
824 FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" \
826 git show HEAD^ | grep "D changed" &&
827 FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" \
829 git show HEAD~3 | grep "B changed" &&
830 FAKE_LINES="1 r 2 pick 3 p 4" FAKE_COMMIT_MESSAGE="C changed" \
833 git show HEAD~2 | grep "C changed"
836 test_expect_success 'rebase -i can copy notes' '
837 git config notes.rewrite.rebase true &&
838 git config notes.rewriteRef "refs/notes/*" &&
842 git notes add -m"a note" n3 &&
843 git rebase -i --onto n1 n2 &&
844 test "a note" = "$(git notes show HEAD)"
847 test_expect_success 'rebase -i can copy notes over a fixup' '
848 cat >expect <<-\EOF &&
853 git reset --hard n3 &&
854 git notes add -m"an earlier note" n2 &&
857 GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 f 2" \
860 git notes show > output &&
861 test_cmp expect output
864 test_expect_success 'rebase while detaching HEAD' '
865 git symbolic-ref HEAD &&
866 grandparent=$(git rev-parse HEAD~2) &&
870 FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0
872 test $grandparent = $(git rev-parse HEAD~2) &&
873 test_must_fail git symbolic-ref HEAD
876 test_tick # Ensure that the rebased commits get a different timestamp.
877 test_expect_success 'always cherry-pick with --no-ff' '
878 git checkout no-ff-branch &&
879 git tag original-no-ff-branch &&
880 git rebase -i --no-ff A &&
883 test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) &&
884 git diff HEAD~$p original-no-ff-branch~$p > out &&
885 test_must_be_empty out
887 test $(git rev-parse HEAD~3) = $(git rev-parse original-no-ff-branch~3) &&
888 git diff HEAD~3 original-no-ff-branch~3 > out &&
889 test_must_be_empty out
892 test_expect_success 'set up commits with funny messages' '
893 git checkout -b funny A &&
896 git commit -a -m "end with slash\\" &&
899 git commit -a -m "something (\000) that looks like octal" &&
902 git commit -a -m "something (\n) that looks like a newline" &&
905 git commit -a -m "another commit"
908 test_expect_success 'rebase-i history with funny messages' '
909 git rev-list A..funny >expect &&
913 FAKE_LINES="1 2 3 4" git rebase -i A
915 git rev-list A.. >actual &&
916 test_cmp expect actual
919 test_expect_success 'prepare for rebase -i --exec' '
920 git checkout master &&
921 git checkout -b execute &&
922 test_commit one_exec main.txt one_exec &&
923 test_commit two_exec main.txt two_exec &&
924 test_commit three_exec main.txt three_exec
927 test_expect_success 'running "git rebase -i --exec git show HEAD"' '
930 git rebase -i --exec "git show HEAD" HEAD~2 >actual &&
931 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
933 git rebase -i HEAD~2 >expect
935 sed -e "1,9d" expect >expected &&
936 test_cmp expected actual
939 test_expect_success 'running "git rebase --exec git show HEAD -i"' '
940 git reset --hard execute &&
943 git rebase --exec "git show HEAD" -i HEAD~2 >actual &&
944 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
946 git rebase -i HEAD~2 >expect
948 sed -e "1,9d" expect >expected &&
949 test_cmp expected actual
952 test_expect_success 'running "git rebase -ix git show HEAD"' '
953 git reset --hard execute &&
956 git rebase -ix "git show HEAD" HEAD~2 >actual &&
957 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
959 git rebase -i HEAD~2 >expect
961 sed -e "1,9d" expect >expected &&
962 test_cmp expected actual
966 test_expect_success 'rebase -ix with several <CMD>' '
967 git reset --hard execute &&
970 git rebase -ix "git show HEAD; pwd" HEAD~2 >actual &&
971 FAKE_LINES="1 exec_git_show_HEAD;_pwd 2 exec_git_show_HEAD;_pwd" &&
973 git rebase -i HEAD~2 >expect
975 sed -e "1,9d" expect >expected &&
976 test_cmp expected actual
979 test_expect_success 'rebase -ix with several instances of --exec' '
980 git reset --hard execute &&
983 git rebase -i --exec "git show HEAD" --exec "pwd" HEAD~2 >actual &&
984 FAKE_LINES="1 exec_git_show_HEAD exec_pwd 2
985 exec_git_show_HEAD exec_pwd" &&
987 git rebase -i HEAD~2 >expect
989 sed -e "1,11d" expect >expected &&
990 test_cmp expected actual
993 test_expect_success C_LOCALE_OUTPUT 'rebase -ix with --autosquash' '
994 git reset --hard execute &&
995 git checkout -b autosquash &&
996 echo second >second.txt &&
997 git add second.txt &&
998 git commit -m "fixup! two_exec" &&
1001 git commit -m "fixup! two_exec" &&
1002 git checkout -b autosquash_actual &&
1003 git rebase -i --exec "git show HEAD" --autosquash HEAD~4 >actual &&
1004 git checkout autosquash &&
1007 git checkout -b autosquash_expected &&
1008 FAKE_LINES="1 fixup 3 fixup 4 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
1009 export FAKE_LINES &&
1010 git rebase -i HEAD~4 >expect
1012 sed -e "1,13d" expect >expected &&
1013 test_cmp expected actual
1016 test_expect_success 'rebase --exec works without -i ' '
1017 git reset --hard execute &&
1018 rm -rf exec_output &&
1019 EDITOR="echo >invoked_editor" git rebase --exec "echo a line >>exec_output" HEAD~2 2>actual &&
1020 test_i18ngrep "Successfully rebased and updated" actual &&
1021 test_line_count = 2 exec_output &&
1022 test_path_is_missing invoked_editor
1025 test_expect_success 'rebase -i --exec without <CMD>' '
1026 git reset --hard execute &&
1027 test_must_fail git rebase -i --exec 2>actual &&
1028 test_i18ngrep "requires a value" actual &&
1032 test_expect_success 'rebase -i --root re-order and drop commits' '
1036 FAKE_LINES="3 1 2 5" git rebase -i --root
1038 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1039 test B = $(git cat-file commit HEAD^ | sed -ne \$p) &&
1040 test A = $(git cat-file commit HEAD^^ | sed -ne \$p) &&
1041 test C = $(git cat-file commit HEAD^^^ | sed -ne \$p) &&
1042 test 0 = $(git cat-file commit HEAD^^^ | grep -c ^parent\ )
1045 test_expect_success 'rebase -i --root retain root commit author and message' '
1049 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
1052 FAKE_LINES="2" git rebase -i --root
1054 git cat-file commit HEAD | grep -q "^author Twerp Snog" &&
1055 git cat-file commit HEAD | grep -q "^different author$"
1058 test_expect_success 'rebase -i --root temporary sentinel commit' '
1062 test_must_fail env FAKE_LINES="2" git rebase -i --root
1064 git cat-file commit HEAD | grep "^tree $EMPTY_TREE" &&
1068 test_expect_success 'rebase -i --root fixup root commit' '
1072 FAKE_LINES="1 fixup 2" git rebase -i --root
1074 test A = $(git cat-file commit HEAD | sed -ne \$p) &&
1075 test B = $(git show HEAD:file1) &&
1076 test 0 = $(git cat-file commit HEAD | grep -c ^parent\ )
1079 test_expect_success 'rebase -i --root reword original root commit' '
1080 test_when_finished "test_might_fail git rebase --abort" &&
1081 git checkout -b reword-original-root-branch master &&
1084 FAKE_LINES="reword 1 2" FAKE_COMMIT_MESSAGE="A changed" \
1085 git rebase -i --root
1087 git show HEAD^ | grep "A changed" &&
1088 test -z "$(git show -s --format=%p HEAD^)"
1091 test_expect_success 'rebase -i --root reword new root commit' '
1092 test_when_finished "test_might_fail git rebase --abort" &&
1093 git checkout -b reword-now-root-branch master &&
1096 FAKE_LINES="reword 3 1" FAKE_COMMIT_MESSAGE="C changed" \
1097 git rebase -i --root
1099 git show HEAD^ | grep "C changed" &&
1100 test -z "$(git show -s --format=%p HEAD^)"
1103 test_expect_success 'rebase -i --root when root has untracked file conflict' '
1104 test_when_finished "reset_rebase" &&
1105 git checkout -b failing-root-pick A &&
1108 git commit -m "remove file 1 add file 2" &&
1112 test_must_fail env FAKE_LINES="1 2" git rebase -i --root
1115 git rebase --continue &&
1116 test "$(git log -1 --format=%B)" = "remove file 1 add file 2" &&
1117 test "$(git rev-list --count HEAD)" = 2
1120 test_expect_success 'rebase -i --root reword root when root has untracked file conflict' '
1121 test_when_finished "reset_rebase" &&
1125 test_must_fail env FAKE_LINES="reword 1 2" \
1126 FAKE_COMMIT_MESSAGE="Modified A" git rebase -i --root &&
1128 FAKE_COMMIT_MESSAGE="Reworded A" git rebase --continue
1130 test "$(git log -1 --format=%B HEAD^)" = "Reworded A" &&
1131 test "$(git rev-list --count HEAD)" = 2
1134 test_expect_success C_LOCALE_OUTPUT 'rebase --edit-todo does not work on non-interactive rebase' '
1135 git checkout reword-original-root-branch &&
1137 git checkout conflict-branch &&
1140 test_must_fail git rebase -f --onto HEAD~2 HEAD~ &&
1141 test_must_fail git rebase --edit-todo
1146 test_expect_success 'rebase --edit-todo can be used to modify todo' '
1148 git checkout no-conflict-branch^0 &&
1151 FAKE_LINES="edit 1 2 3" git rebase -i HEAD~3 &&
1152 FAKE_LINES="2 1" git rebase --edit-todo &&
1153 git rebase --continue
1155 test M = $(git cat-file commit HEAD^ | sed -ne \$p) &&
1156 test L = $(git cat-file commit HEAD | sed -ne \$p)
1159 test_expect_success 'rebase -i produces readable reflog' '
1161 git branch -f branch-reflog-test H &&
1162 git rebase -i --onto I F branch-reflog-test &&
1163 cat >expect <<-\EOF &&
1164 rebase -i (finish): returning to refs/heads/branch-reflog-test
1167 rebase -i (start): checkout I
1169 git reflog -n4 HEAD |
1170 sed "s/[^:]*: //" >actual &&
1171 test_cmp expect actual
1174 test_expect_success 'rebase -i respects core.commentchar' '
1177 test_config core.commentchar "\\" &&
1178 write_script remove-all-but-first.sh <<-\EOF &&
1179 sed -e "2,\$s/^/\\\\/" "$1" >"$1.tmp" &&
1183 test_set_editor "$(pwd)/remove-all-but-first.sh" &&
1186 test B = $(git cat-file commit HEAD^ | sed -ne \$p)
1189 test_expect_success 'rebase -i respects core.commentchar=auto' '
1190 test_config core.commentchar auto &&
1191 write_script copy-edit-script.sh <<-\EOF &&
1194 test_when_finished "git rebase --abort || :" &&
1196 test_set_editor "$(pwd)/copy-edit-script.sh" &&
1199 test -z "$(grep -ve "^#" -e "^\$" -e "^pick" edit-script)"
1202 test_expect_success 'rebase -i, with <onto> and <upstream> specified as :/quuxery' '
1203 test_when_finished "git branch -D torebase" &&
1204 git checkout -b torebase branch1 &&
1205 upstream=$(git rev-parse ":/J") &&
1206 onto=$(git rev-parse ":/A") &&
1207 git rebase --onto $onto $upstream &&
1208 git reset --hard branch1 &&
1209 git rebase --onto ":/A" ":/J" &&
1210 git checkout branch1
1213 test_expect_success 'rebase -i with --strategy and -X' '
1214 git checkout -b conflict-merge-use-theirs conflict-branch &&
1215 git reset --hard HEAD^ &&
1216 echo five >conflict &&
1218 git commit -a -m "one file conflict" &&
1219 EDITOR=true git rebase -i --strategy=recursive -Xours conflict-branch &&
1220 test $(git show conflict-branch:conflict) = $(cat conflict) &&
1221 test $(cat file1) = Z
1224 test_expect_success 'interrupted rebase -i with --strategy and -X' '
1225 git checkout -b conflict-merge-use-theirs-interrupted conflict-branch &&
1226 git reset --hard HEAD^ &&
1228 git add breakpoint &&
1229 git commit -m "breakpoint for interactive mode" &&
1230 echo five >conflict &&
1232 git commit -a -m "one file conflict" &&
1235 FAKE_LINES="edit 1 2" git rebase -i --strategy=recursive \
1236 -Xours conflict-branch
1238 git rebase --continue &&
1239 test $(git show conflict-branch:conflict) = $(cat conflict) &&
1240 test $(cat file1) = Z
1243 test_expect_success 'rebase -i error on commits with \ in message' '
1244 current_head=$(git rev-parse HEAD) &&
1245 test_when_finished "git rebase --abort; git reset --hard $current_head; rm -f error" &&
1246 test_commit TO-REMOVE will-conflict old-content &&
1247 test_commit "\temp" will-conflict new-content dummy &&
1248 test_must_fail env EDITOR=true git rebase -i HEAD^ --onto HEAD^^ 2>error &&
1249 test_expect_code 1 grep " emp" error
1252 test_expect_success SHA1 'short SHA-1 setup' '
1253 test_when_finished "git checkout master" &&
1254 git checkout --orphan collide &&
1258 test_commit collide1 collide &&
1259 test_commit --notick collide2 collide &&
1260 test_commit --notick collide3 collide
1264 test_expect_success SHA1 'short SHA-1 collide' '
1265 test_when_finished "reset_rebase && git checkout master" &&
1266 git checkout collide &&
1267 colliding_sha1=6bcda37 &&
1268 test $colliding_sha1 = "$(git rev-parse HEAD | cut -c 1-7)" &&
1273 FAKE_COMMIT_MESSAGE="collide2 ac4f2ee" \
1274 FAKE_LINES="reword 1 break 2" git rebase -i HEAD~2 &&
1275 test $colliding_sha1 = "$(git rev-parse HEAD | cut -c 1-7)" &&
1276 grep "^pick $colliding_sha1 " \
1277 .git/rebase-merge/git-rebase-todo.tmp &&
1278 grep "^pick [0-9a-f]\{40\}" \
1279 .git/rebase-merge/git-rebase-todo &&
1280 grep "^pick [0-9a-f]\{40\}" \
1281 .git/rebase-merge/git-rebase-todo.backup &&
1282 git rebase --continue
1284 collide2="$(git rev-parse HEAD~1 | cut -c 1-4)" &&
1285 collide3="$(git rev-parse collide3 | cut -c 1-4)" &&
1286 test "$collide2" = "$collide3"
1289 test_expect_success 'respect core.abbrev' '
1290 git config core.abbrev 12 &&
1292 set_cat_todo_editor &&
1293 test_must_fail git rebase -i HEAD~4 >todo-list
1295 test 4 = $(grep -c "pick [0-9a-f]\{12,\}" todo-list)
1298 test_expect_success 'todo count' '
1299 write_script dump-raw.sh <<-\EOF &&
1303 test_set_editor "$(pwd)/dump-raw.sh" &&
1304 git rebase -i HEAD~4 >actual
1306 test_i18ngrep "^# Rebase ..* onto ..* ([0-9]" actual
1309 test_expect_success 'rebase -i commits that overwrite untracked files (pick)' '
1310 git checkout --force branch2 &&
1314 FAKE_LINES="edit 1 2" git rebase -i A
1316 test_cmp_rev HEAD F &&
1317 test_path_is_missing file6 &&
1319 test_must_fail git rebase --continue &&
1320 test_cmp_rev HEAD F &&
1322 git rebase --continue &&
1326 test_expect_success 'rebase -i commits that overwrite untracked files (squash)' '
1327 git checkout --force branch2 &&
1329 git tag original-branch2 &&
1332 FAKE_LINES="edit 1 squash 2" git rebase -i A
1334 test_cmp_rev HEAD F &&
1335 test_path_is_missing file6 &&
1337 test_must_fail git rebase --continue &&
1338 test_cmp_rev HEAD F &&
1340 git rebase --continue &&
1341 test $(git cat-file commit HEAD | sed -ne \$p) = I &&
1342 git reset --hard original-branch2
1345 test_expect_success 'rebase -i commits that overwrite untracked files (no ff)' '
1346 git checkout --force branch2 &&
1350 FAKE_LINES="edit 1 2" git rebase -i --no-ff A
1352 test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1353 test_path_is_missing file6 &&
1355 test_must_fail git rebase --continue &&
1356 test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1358 git rebase --continue &&
1359 test $(git cat-file commit HEAD | sed -ne \$p) = I
1362 test_expect_success 'rebase --continue removes CHERRY_PICK_HEAD' '
1363 git checkout -b commit-to-skip &&
1366 test_seq 5 | sed "s/$double/&&/" >seq &&
1369 git commit -m seq-$double
1372 git reset --hard HEAD~2 &&
1373 git cherry-pick seq-onto &&
1376 test_must_fail env FAKE_LINES= git rebase -i seq-onto
1378 test -d .git/rebase-merge &&
1379 git rebase --continue &&
1380 git diff --exit-code seq-onto &&
1381 test ! -d .git/rebase-merge &&
1382 test ! -f .git/CHERRY_PICK_HEAD
1385 rebase_setup_and_clean () {
1386 test_when_finished "
1387 git checkout master &&
1388 test_might_fail git branch -D $1 &&
1389 test_might_fail git rebase --abort
1391 git checkout -b $1 ${2:-master}
1394 test_expect_success 'drop' '
1395 rebase_setup_and_clean drop-test &&
1398 FAKE_LINES="1 drop 2 3 d 4 5" git rebase -i --root
1400 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1401 test C = $(git cat-file commit HEAD^ | sed -ne \$p) &&
1402 test A = $(git cat-file commit HEAD^^ | sed -ne \$p)
1405 test_expect_success 'rebase -i respects rebase.missingCommitsCheck = ignore' '
1406 test_config rebase.missingCommitsCheck ignore &&
1407 rebase_setup_and_clean missing-commit &&
1410 FAKE_LINES="1 2 3 4" git rebase -i --root 2>actual
1412 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1414 "Successfully rebased and updated refs/heads/missing-commit" \
1418 test_expect_success 'rebase -i respects rebase.missingCommitsCheck = warn' '
1419 cat >expect <<-EOF &&
1420 Warning: some commits may have been dropped accidentally.
1421 Dropped commits (newer to older):
1422 - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
1423 To avoid this message, use "drop" to explicitly remove a commit.
1425 test_config rebase.missingCommitsCheck warn &&
1426 rebase_setup_and_clean missing-commit &&
1429 FAKE_LINES="1 2 3 4" git rebase -i --root 2>actual.2
1431 head -n4 actual.2 >actual &&
1432 test_i18ncmp expect actual &&
1433 test D = $(git cat-file commit HEAD | sed -ne \$p)
1436 test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' '
1437 cat >expect <<-EOF &&
1438 Warning: some commits may have been dropped accidentally.
1439 Dropped commits (newer to older):
1440 - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
1441 - $(git rev-list --pretty=oneline --abbrev-commit -1 master~2)
1442 To avoid this message, use "drop" to explicitly remove a commit.
1444 Use '\''git config rebase.missingCommitsCheck'\'' to change the level of warnings.
1445 The possible behaviours are: ignore, warn, error.
1447 You can fix this with '\''git rebase --edit-todo'\'' and then run '\''git rebase --continue'\''.
1448 Or you can abort the rebase with '\''git rebase --abort'\''.
1450 test_config rebase.missingCommitsCheck error &&
1451 rebase_setup_and_clean missing-commit &&
1454 test_must_fail env FAKE_LINES="1 2 4" \
1455 git rebase -i --root 2>actual &&
1456 test_i18ncmp expect actual &&
1457 cp .git/rebase-merge/git-rebase-todo.backup \
1458 .git/rebase-merge/git-rebase-todo &&
1459 FAKE_LINES="1 2 drop 3 4 drop 5" git rebase --edit-todo
1461 git rebase --continue &&
1462 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1463 test B = $(git cat-file commit HEAD^ | sed -ne \$p)
1466 test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = ignore' '
1467 test_config rebase.missingCommitsCheck ignore &&
1468 rebase_setup_and_clean missing-commit &&
1471 FAKE_LINES="break 1 2 3 4 5" git rebase -i --root &&
1472 FAKE_LINES="1 2 3 4" git rebase --edit-todo &&
1473 git rebase --continue 2>actual
1475 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1477 "Successfully rebased and updated refs/heads/missing-commit" \
1481 test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = warn' '
1482 cat >expect <<-EOF &&
1483 error: invalid line 1: badcmd $(git rev-list --pretty=oneline --abbrev-commit -1 master~4)
1484 Warning: some commits may have been dropped accidentally.
1485 Dropped commits (newer to older):
1486 - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
1487 - $(git rev-list --pretty=oneline --abbrev-commit -1 master~4)
1488 To avoid this message, use "drop" to explicitly remove a commit.
1490 head -n4 expect >expect.2 &&
1491 tail -n1 expect >>expect.2 &&
1492 tail -n4 expect.2 >expect.3 &&
1493 test_config rebase.missingCommitsCheck warn &&
1494 rebase_setup_and_clean missing-commit &&
1497 test_must_fail env FAKE_LINES="bad 1 2 3 4 5" \
1498 git rebase -i --root &&
1499 cp .git/rebase-merge/git-rebase-todo.backup orig &&
1500 FAKE_LINES="2 3 4" git rebase --edit-todo 2>actual.2 &&
1501 head -n6 actual.2 >actual &&
1502 test_i18ncmp expect actual &&
1503 cp orig .git/rebase-merge/git-rebase-todo &&
1504 FAKE_LINES="1 2 3 4" git rebase --edit-todo 2>actual.2 &&
1505 head -n4 actual.2 >actual &&
1506 test_i18ncmp expect.3 actual &&
1507 git rebase --continue 2>actual
1509 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1511 "Successfully rebased and updated refs/heads/missing-commit" \
1515 test_expect_success 'rebase --edit-todo respects rebase.missingCommitsCheck = error' '
1516 cat >expect <<-EOF &&
1517 error: invalid line 1: badcmd $(git rev-list --pretty=oneline --abbrev-commit -1 master~4)
1518 Warning: some commits may have been dropped accidentally.
1519 Dropped commits (newer to older):
1520 - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
1521 - $(git rev-list --pretty=oneline --abbrev-commit -1 master~4)
1522 To avoid this message, use "drop" to explicitly remove a commit.
1524 Use '\''git config rebase.missingCommitsCheck'\'' to change the level of warnings.
1525 The possible behaviours are: ignore, warn, error.
1527 You can fix this with '\''git rebase --edit-todo'\'' and then run '\''git rebase --continue'\''.
1528 Or you can abort the rebase with '\''git rebase --abort'\''.
1530 tail -n11 expect >expect.2 &&
1531 head -n3 expect.2 >expect.3 &&
1532 tail -n7 expect.2 >>expect.3 &&
1533 test_config rebase.missingCommitsCheck error &&
1534 rebase_setup_and_clean missing-commit &&
1537 test_must_fail env FAKE_LINES="bad 1 2 3 4 5" \
1538 git rebase -i --root &&
1539 cp .git/rebase-merge/git-rebase-todo.backup orig &&
1540 test_must_fail env FAKE_LINES="2 3 4" \
1541 git rebase --edit-todo 2>actual &&
1542 test_i18ncmp expect actual &&
1543 test_must_fail git rebase --continue 2>actual &&
1544 test_i18ncmp expect.2 actual &&
1545 test_must_fail git rebase --edit-todo &&
1546 cp orig .git/rebase-merge/git-rebase-todo &&
1547 test_must_fail env FAKE_LINES="1 2 3 4" \
1548 git rebase --edit-todo 2>actual &&
1549 test_i18ncmp expect.3 actual &&
1550 test_must_fail git rebase --continue 2>actual &&
1551 test_i18ncmp expect.3 actual &&
1552 cp orig .git/rebase-merge/git-rebase-todo &&
1553 FAKE_LINES="1 2 3 4 drop 5" git rebase --edit-todo &&
1554 git rebase --continue 2>actual
1556 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1558 "Successfully rebased and updated refs/heads/missing-commit" \
1562 test_expect_success 'rebase.missingCommitsCheck = error after resolving conflicts' '
1563 test_config rebase.missingCommitsCheck error &&
1566 FAKE_LINES="drop 1 break 2 3 4" git rebase -i A E
1568 git rebase --edit-todo &&
1569 test_must_fail git rebase --continue &&
1572 git rebase --continue
1575 test_expect_success 'rebase.missingCommitsCheck = error when editing for a second time' '
1576 test_config rebase.missingCommitsCheck error &&
1579 FAKE_LINES="1 break 2 3" git rebase -i A D &&
1580 cp .git/rebase-merge/git-rebase-todo todo &&
1581 test_must_fail env FAKE_LINES=2 git rebase --edit-todo &&
1582 GIT_SEQUENCE_EDITOR="cp todo" git rebase --edit-todo &&
1583 git rebase --continue
1587 test_expect_success 'respects rebase.abbreviateCommands with fixup, squash and exec' '
1588 rebase_setup_and_clean abbrevcmd &&
1589 test_commit "first" file1.txt "first line" first &&
1590 test_commit "second" file1.txt "another line" second &&
1591 test_commit "fixup! first" file2.txt "first line again" first_fixup &&
1592 test_commit "squash! second" file1.txt "another line here" second_squash &&
1593 cat >expected <<-EOF &&
1594 p $(git rev-list --abbrev-commit -1 first) first
1595 f $(git rev-list --abbrev-commit -1 first_fixup) fixup! first
1597 p $(git rev-list --abbrev-commit -1 second) second
1598 s $(git rev-list --abbrev-commit -1 second_squash) squash! second
1601 git checkout abbrevcmd &&
1602 test_config rebase.abbreviateCommands true &&
1604 set_cat_todo_editor &&
1605 test_must_fail git rebase -i --exec "git show HEAD" \
1606 --autosquash master >actual
1608 test_cmp expected actual
1611 test_expect_success 'static check of bad command' '
1612 rebase_setup_and_clean bad-cmd &&
1615 test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \
1616 git rebase -i --root 2>actual &&
1617 test_i18ngrep "badcmd $(git rev-list --oneline -1 master~1)" \
1619 test_i18ngrep "You can fix this with .git rebase --edit-todo.." \
1621 FAKE_LINES="1 2 3 drop 4 5" git rebase --edit-todo
1623 git rebase --continue &&
1624 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1625 test C = $(git cat-file commit HEAD^ | sed -ne \$p)
1628 test_expect_success 'tabs and spaces are accepted in the todolist' '
1629 rebase_setup_and_clean indented-comment &&
1630 write_script add-indent.sh <<-\EOF &&
1632 # Turn single spaces into space/tab mix
1633 sed "1s/ / /g; 2s/ / /g; 3s/ / /g" "$1"
1634 printf "\n\t# comment\n #more\n\t # comment\n"
1639 test_set_editor "$(pwd)/add-indent.sh" &&
1640 git rebase -i HEAD^^^
1642 test E = $(git cat-file commit HEAD | sed -ne \$p)
1645 test_expect_success 'static check of bad SHA-1' '
1646 rebase_setup_and_clean bad-sha &&
1649 test_must_fail env FAKE_LINES="1 2 edit fakesha 3 4 5 #" \
1650 git rebase -i --root 2>actual &&
1651 test_i18ngrep "edit XXXXXXX False commit" actual &&
1652 test_i18ngrep "You can fix this with .git rebase --edit-todo.." \
1654 FAKE_LINES="1 2 4 5 6" git rebase --edit-todo
1656 git rebase --continue &&
1657 test E = $(git cat-file commit HEAD | sed -ne \$p)
1660 test_expect_success 'editor saves as CR/LF' '
1661 git checkout -b with-crlf &&
1662 write_script add-crs.sh <<-\EOF &&
1663 sed -e "s/\$/Q/" <"$1" | tr Q "\\015" >"$1".new &&
1667 test_set_editor "$(pwd)/add-crs.sh" &&
1672 test_expect_success 'rebase -i --gpg-sign=<key-id>' '
1673 test_when_finished "test_might_fail git rebase --abort" &&
1676 FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" \
1679 test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err
1682 test_expect_success 'rebase -i --gpg-sign=<key-id> overrides commit.gpgSign' '
1683 test_when_finished "test_might_fail git rebase --abort" &&
1684 test_config commit.gpgsign true &&
1687 FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" \
1690 test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err
1693 test_expect_success 'valid author header after --root swap' '
1694 rebase_setup_and_clean author-header no-conflict-branch &&
1695 git commit --amend --author="Au ${SQ}thor <author@example.com>" --no-edit &&
1696 git cat-file commit HEAD | grep ^author >expected &&
1699 FAKE_LINES="5 1" git rebase -i --root
1701 git cat-file commit HEAD^ | grep ^author >actual &&
1702 test_cmp expected actual
1705 test_expect_success 'valid author header when author contains single quote' '
1706 rebase_setup_and_clean author-header no-conflict-branch &&
1707 git commit --amend --author="Au ${SQ}thor <author@example.com>" --no-edit &&
1708 git cat-file commit HEAD | grep ^author >expected &&
1711 FAKE_LINES="2" git rebase -i HEAD~2
1713 git cat-file commit HEAD | grep ^author >actual &&
1714 test_cmp expected actual
1717 test_expect_success 'post-commit hook is called' '
1718 test_when_finished "rm -f .git/hooks/post-commit" &&
1720 mkdir -p .git/hooks &&
1721 write_script .git/hooks/post-commit <<-\EOS &&
1722 git rev-parse HEAD >>actual
1726 FAKE_LINES="edit 4 1 reword 2 fixup 3" git rebase -i A E &&
1729 FAKE_COMMIT_MESSAGE=edited git rebase --continue
1731 git rev-parse HEAD@{5} HEAD@{4} HEAD@{3} HEAD@{2} HEAD@{1} HEAD \
1733 test_cmp expect actual
1736 # This must be the last test in this file
1737 test_expect_success '$EDITOR and friends are unchanged' '
1738 test_editor_unchanged