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" &&
190 test $(git rev-parse I) = $(git rev-parse HEAD)
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 $(git rev-parse I) = $(git rev-parse branch2) &&
200 test $(git rev-parse I) = $(git rev-parse HEAD)
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 $(git rev-parse HEAD^) = $(git rev-parse branch1) &&
208 test $(git rev-parse I) = $(git rev-parse 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 $(git rev-parse I) = $(git rev-parse branch2) &&
218 test $(git rev-parse I) = $(git rev-parse HEAD~2)
221 test_expect_success
'reflog for the branch shows state before rebase' '
222 test $(git rev-parse branch1@{1}) = $(git rev-parse 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 $(git rev-parse new-branch1) = $(git rev-parse 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 $(git rev-parse conflict-a^0) = $(git rev-parse 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 $(git rev-parse HEAD^) = $(git rev-parse 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 $(git rev-parse HEAD~6) = $(git rev-parse branch1) &&
402 test $(git rev-parse HEAD~4^2) = $(git rev-parse to-be-preserved) &&
403 test $(git rev-parse HEAD^^2^) = $(git rev-parse 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 $(git rev-parse HEAD^) = $(git rev-parse 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 $(git rev-parse branch3) = $(git rev-parse 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 $(git rev-parse submodule-base) = $(git rev-parse 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 $(git rev-parse master^) = $(git rev-parse 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 $(git rev-parse HEAD~3) = $(git rev-parse 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 SHA1
'short SHA-1 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 test_expect_success SHA1
'short SHA-1 collide' '
1266 test_when_finished "reset_rebase && git checkout master" &&
1267 git checkout collide &&
1272 FAKE_COMMIT_MESSAGE="collide2 ac4f2ee" \
1273 FAKE_LINES="reword 1 2" git rebase -i HEAD~2
1277 test_expect_success
'respect core.abbrev' '
1278 git config core.abbrev 12 &&
1280 set_cat_todo_editor &&
1281 test_must_fail git rebase -i HEAD~4 >todo-list
1283 test 4 = $(grep -c "pick [0-9a-f]\{12,\}" todo-list)
1286 test_expect_success
'todo count' '
1287 write_script dump-raw.sh <<-\EOF &&
1291 test_set_editor "$(pwd)/dump-raw.sh" &&
1292 git rebase -i HEAD~4 >actual
1294 test_i18ngrep "^# Rebase ..* onto ..* ([0-9]" actual
1297 test_expect_success
'rebase -i commits that overwrite untracked files (pick)' '
1298 git checkout --force branch2 &&
1302 FAKE_LINES="edit 1 2" git rebase -i A
1304 test_cmp_rev HEAD F &&
1305 test_path_is_missing file6 &&
1307 test_must_fail git rebase --continue &&
1308 test_cmp_rev HEAD F &&
1310 git rebase --continue &&
1314 test_expect_success
'rebase -i commits that overwrite untracked files (squash)' '
1315 git checkout --force branch2 &&
1317 git tag original-branch2 &&
1320 FAKE_LINES="edit 1 squash 2" git rebase -i A
1322 test_cmp_rev HEAD F &&
1323 test_path_is_missing file6 &&
1325 test_must_fail git rebase --continue &&
1326 test_cmp_rev HEAD F &&
1328 git rebase --continue &&
1329 test $(git cat-file commit HEAD | sed -ne \$p) = I &&
1330 git reset --hard original-branch2
1333 test_expect_success
'rebase -i commits that overwrite untracked files (no ff)' '
1334 git checkout --force branch2 &&
1338 FAKE_LINES="edit 1 2" git rebase -i --no-ff A
1340 test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1341 test_path_is_missing file6 &&
1343 test_must_fail git rebase --continue &&
1344 test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1346 git rebase --continue &&
1347 test $(git cat-file commit HEAD | sed -ne \$p) = I
1350 test_expect_success
'rebase --continue removes CHERRY_PICK_HEAD' '
1351 git checkout -b commit-to-skip &&
1354 test_seq 5 | sed "s/$double/&&/" >seq &&
1357 git commit -m seq-$double
1360 git reset --hard HEAD~2 &&
1361 git cherry-pick seq-onto &&
1364 test_must_fail env FAKE_LINES= git rebase -i seq-onto
1366 test -d .git/rebase-merge &&
1367 git rebase --continue &&
1368 git diff --exit-code seq-onto &&
1369 test ! -d .git/rebase-merge &&
1370 test ! -f .git/CHERRY_PICK_HEAD
1373 rebase_setup_and_clean
() {
1374 test_when_finished
"
1375 git checkout master &&
1376 test_might_fail git branch -D $1 &&
1377 test_might_fail git rebase --abort
1379 git checkout
-b $1 ${2:-master}
1382 test_expect_success
'drop' '
1383 rebase_setup_and_clean drop-test &&
1386 FAKE_LINES="1 drop 2 3 d 4 5" git rebase -i --root
1388 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1389 test C = $(git cat-file commit HEAD^ | sed -ne \$p) &&
1390 test A = $(git cat-file commit HEAD^^ | sed -ne \$p)
1393 test_expect_success
'rebase -i respects rebase.missingCommitsCheck = ignore' '
1394 test_config rebase.missingCommitsCheck ignore &&
1395 rebase_setup_and_clean missing-commit &&
1398 FAKE_LINES="1 2 3 4" git rebase -i --root 2>actual
1400 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1402 "Successfully rebased and updated refs/heads/missing-commit" \
1406 test_expect_success
'rebase -i respects rebase.missingCommitsCheck = warn' '
1407 cat >expect <<-EOF &&
1408 Warning: some commits may have been dropped accidentally.
1409 Dropped commits (newer to older):
1410 - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
1411 To avoid this message, use "drop" to explicitly remove a commit.
1413 test_config rebase.missingCommitsCheck warn &&
1414 rebase_setup_and_clean missing-commit &&
1417 FAKE_LINES="1 2 3 4" git rebase -i --root 2>actual.2
1419 head -n4 actual.2 >actual &&
1420 test_i18ncmp expect actual &&
1421 test D = $(git cat-file commit HEAD | sed -ne \$p)
1424 test_expect_success
'rebase -i respects rebase.missingCommitsCheck = error' '
1425 cat >expect <<-EOF &&
1426 Warning: some commits may have been dropped accidentally.
1427 Dropped commits (newer to older):
1428 - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
1429 - $(git rev-list --pretty=oneline --abbrev-commit -1 master~2)
1430 To avoid this message, use "drop" to explicitly remove a commit.
1432 Use '\''git config rebase.missingCommitsCheck'\'' to change the level of warnings.
1433 The possible behaviours are: ignore, warn, error.
1435 You can fix this with '\''git rebase --edit-todo'\'' and then run '\''git rebase --continue'\''.
1436 Or you can abort the rebase with '\''git rebase --abort'\''.
1438 test_config rebase.missingCommitsCheck error &&
1439 rebase_setup_and_clean missing-commit &&
1442 test_must_fail env FAKE_LINES="1 2 4" \
1443 git rebase -i --root 2>actual &&
1444 test_i18ncmp expect actual &&
1445 cp .git/rebase-merge/git-rebase-todo.backup \
1446 .git/rebase-merge/git-rebase-todo &&
1447 FAKE_LINES="1 2 drop 3 4 drop 5" git rebase --edit-todo
1449 git rebase --continue &&
1450 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1451 test B = $(git cat-file commit HEAD^ | sed -ne \$p)
1454 test_expect_success
'respects rebase.abbreviateCommands with fixup, squash and exec' '
1455 rebase_setup_and_clean abbrevcmd &&
1456 test_commit "first" file1.txt "first line" first &&
1457 test_commit "second" file1.txt "another line" second &&
1458 test_commit "fixup! first" file2.txt "first line again" first_fixup &&
1459 test_commit "squash! second" file1.txt "another line here" second_squash &&
1460 cat >expected <<-EOF &&
1461 p $(git rev-list --abbrev-commit -1 first) first
1462 f $(git rev-list --abbrev-commit -1 first_fixup) fixup! first
1464 p $(git rev-list --abbrev-commit -1 second) second
1465 s $(git rev-list --abbrev-commit -1 second_squash) squash! second
1468 git checkout abbrevcmd &&
1469 test_config rebase.abbreviateCommands true &&
1471 set_cat_todo_editor &&
1472 test_must_fail git rebase -i --exec "git show HEAD" \
1473 --autosquash master >actual
1475 test_cmp expected actual
1478 test_expect_success
'static check of bad command' '
1479 rebase_setup_and_clean bad-cmd &&
1482 test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \
1483 git rebase -i --root 2>actual &&
1484 test_i18ngrep "badcmd $(git rev-list --oneline -1 master~1)" \
1486 test_i18ngrep "You can fix this with .git rebase --edit-todo.." \
1488 FAKE_LINES="1 2 3 drop 4 5" git rebase --edit-todo
1490 git rebase --continue &&
1491 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1492 test C = $(git cat-file commit HEAD^ | sed -ne \$p)
1495 test_expect_success
'tabs and spaces are accepted in the todolist' '
1496 rebase_setup_and_clean indented-comment &&
1497 write_script add-indent.sh <<-\EOF &&
1499 # Turn single spaces into space/tab mix
1500 sed "1s/ / /g; 2s/ / /g; 3s/ / /g" "$1"
1501 printf "\n\t# comment\n #more\n\t # comment\n"
1506 test_set_editor "$(pwd)/add-indent.sh" &&
1507 git rebase -i HEAD^^^
1509 test E = $(git cat-file commit HEAD | sed -ne \$p)
1512 test_expect_success
'static check of bad SHA-1' '
1513 rebase_setup_and_clean bad-sha &&
1516 test_must_fail env FAKE_LINES="1 2 edit fakesha 3 4 5 #" \
1517 git rebase -i --root 2>actual &&
1518 test_i18ngrep "edit XXXXXXX False commit" actual &&
1519 test_i18ngrep "You can fix this with .git rebase --edit-todo.." \
1521 FAKE_LINES="1 2 4 5 6" git rebase --edit-todo
1523 git rebase --continue &&
1524 test E = $(git cat-file commit HEAD | sed -ne \$p)
1527 test_expect_success
'editor saves as CR/LF' '
1528 git checkout -b with-crlf &&
1529 write_script add-crs.sh <<-\EOF &&
1530 sed -e "s/\$/Q/" <"$1" | tr Q "\\015" >"$1".new &&
1534 test_set_editor "$(pwd)/add-crs.sh" &&
1539 test_expect_success
'rebase -i --gpg-sign=<key-id>' '
1540 test_when_finished "test_might_fail git rebase --abort" &&
1543 FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" \
1546 test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err
1549 test_expect_success
'rebase -i --gpg-sign=<key-id> overrides commit.gpgSign' '
1550 test_when_finished "test_might_fail git rebase --abort" &&
1551 test_config commit.gpgsign true &&
1554 FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" \
1557 test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err
1560 test_expect_success
'valid author header after --root swap' '
1561 rebase_setup_and_clean author-header no-conflict-branch &&
1562 git commit --amend --author="Au ${SQ}thor <author@example.com>" --no-edit &&
1563 git cat-file commit HEAD | grep ^author >expected &&
1566 FAKE_LINES="5 1" git rebase -i --root
1568 git cat-file commit HEAD^ | grep ^author >actual &&
1569 test_cmp expected actual
1572 test_expect_success
'valid author header when author contains single quote' '
1573 rebase_setup_and_clean author-header no-conflict-branch &&
1574 git commit --amend --author="Au ${SQ}thor <author@example.com>" --no-edit &&
1575 git cat-file commit HEAD | grep ^author >expected &&
1578 FAKE_LINES="2" git rebase -i HEAD~2
1580 git cat-file commit HEAD | grep ^author >actual &&
1581 test_cmp expected actual
1584 test_expect_success
'post-commit hook is called' '
1585 test_when_finished "rm -f .git/hooks/post-commit" &&
1587 mkdir -p .git/hooks &&
1588 write_script .git/hooks/post-commit <<-\EOS &&
1589 git rev-parse HEAD >>actual
1593 FAKE_LINES="edit 4 1 reword 2 fixup 3" git rebase -i A E &&
1596 FAKE_COMMIT_MESSAGE=edited git rebase --continue
1598 git rev-parse HEAD@{5} HEAD@{4} HEAD@{3} HEAD@{2} HEAD@{1} HEAD \
1600 test_cmp expect actual
1603 # This must be the last test in this file
1604 test_expect_success
'$EDITOR and friends are unchanged' '
1605 test_editor_unchanged