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 # WARNING: Modifications to the initial repository can change the SHA ID used
33 # in the expect2 file for the 'stop on conflicting pick' test.
35 test_expect_success
'setup' '
36 test_commit A file1 &&
37 test_commit B file1 &&
38 test_commit C file2 &&
39 test_commit D file1 &&
40 test_commit E file3 &&
41 git checkout -b branch1 A &&
42 test_commit F file4 &&
43 test_commit G file1 &&
44 test_commit H file5 &&
45 git checkout -b branch2 F &&
46 test_commit I file6 &&
47 git checkout -b conflict-branch A &&
48 test_commit one conflict &&
49 test_commit two conflict &&
50 test_commit three conflict &&
51 test_commit four conflict &&
52 git checkout -b no-conflict-branch A &&
53 test_commit J fileJ &&
54 test_commit K fileK &&
55 test_commit L fileL &&
56 test_commit M fileM &&
57 git checkout -b no-ff-branch A &&
58 test_commit N fileN &&
59 test_commit O fileO &&
63 # "exec" commands are ran with the user shell by default, but this may
64 # be non-POSIX. For example, if SHELL=zsh then ">file" doesn't work
65 # to create a file. Unseting SHELL avoids such non-portable behavior
66 # in tests. It must be exported for it to take effect where needed.
70 test_expect_success
'rebase -i with the exec command' '
71 git checkout master &&
74 FAKE_LINES="1 exec_>touch-one
75 2 exec_>touch-two exec_false exec_>touch-three
76 3 4 exec_>\"touch-file__name_with_spaces\";_>touch-after-semicolon 5" &&
78 test_must_fail git rebase -i A
80 test_path_is_file touch-one &&
81 test_path_is_file touch-two &&
82 test_path_is_missing touch-three " (should have stopped before)" &&
83 test_cmp_rev C HEAD &&
84 git rebase --continue &&
85 test_path_is_file touch-three &&
86 test_path_is_file "touch-file name with spaces" &&
87 test_path_is_file touch-after-semicolon &&
88 test_cmp_rev master HEAD &&
92 test_expect_success
'rebase -i with the exec command runs from tree root' '
93 git checkout master &&
94 mkdir subdir && (cd subdir &&
96 FAKE_LINES="1 exec_>touch-subdir" \
99 test_path_is_file touch-subdir &&
103 test_expect_success
'rebase -i with the exec command checks tree cleanness' '
104 git checkout master &&
106 test_must_fail env FAKE_LINES="exec_echo_foo_>file1 1" git rebase -i HEAD^ &&
107 test_cmp_rev master^ HEAD &&
109 git rebase --continue
112 test_expect_success
'rebase -i with exec of inexistent command' '
113 git checkout master &&
114 test_when_finished "git rebase --abort" &&
116 test_must_fail env FAKE_LINES="exec_this-command-does-not-exist 1" \
117 git rebase -i HEAD^ >actual 2>&1 &&
118 ! grep "Maybe git-rebase is broken" actual
121 test_expect_success
'no changes are a nop' '
122 git checkout branch2 &&
125 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
126 test $(git rev-parse I) = $(git rev-parse HEAD)
129 test_expect_success
'test the [branch] option' '
130 git checkout -b dead-end &&
132 git commit -m "stop here" &&
134 git rebase -i F branch2 &&
135 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
136 test $(git rev-parse I) = $(git rev-parse branch2) &&
137 test $(git rev-parse I) = $(git rev-parse HEAD)
140 test_expect_success
'test --onto <branch>' '
141 git checkout -b test-onto branch2 &&
143 git rebase -i --onto branch1 F &&
144 test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" &&
145 test $(git rev-parse HEAD^) = $(git rev-parse branch1) &&
146 test $(git rev-parse I) = $(git rev-parse branch2)
149 test_expect_success
'rebase on top of a non-conflicting commit' '
150 git checkout branch1 &&
151 git tag original-branch1 &&
153 git rebase -i branch2 &&
154 test file6 = $(git diff --name-only original-branch1) &&
155 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
156 test $(git rev-parse I) = $(git rev-parse branch2) &&
157 test $(git rev-parse I) = $(git rev-parse HEAD~2)
160 test_expect_success
'reflog for the branch shows state before rebase' '
161 test $(git rev-parse branch1@{1}) = $(git rev-parse original-branch1)
164 test_expect_success
'exchange two commits' '
166 FAKE_LINES="2 1" git rebase -i HEAD~2 &&
167 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
168 test G = $(git cat-file commit HEAD | sed -ne \$p)
172 diff --git a/file1 b/file1
173 index f70f10e..fd79235 100644
189 test_expect_success
'stop on conflicting pick' '
190 git tag new-branch1 &&
192 test_must_fail git rebase -i master &&
193 test "$(git rev-parse HEAD~3)" = "$(git rev-parse master)" &&
194 test_cmp expect .git/rebase-merge/patch &&
195 test_cmp expect2 file1 &&
196 test "$(git diff --name-status |
197 sed -n -e "/^U/s/^U[^a-z]*//p")" = file1 &&
198 test 4 = $(grep -v "^#" < .git/rebase-merge/done | wc -l) &&
199 test 0 = $(grep -c "^[^#]" < .git/rebase-merge/git-rebase-todo)
202 test_expect_success
'abort' '
203 git rebase --abort &&
204 test $(git rev-parse new-branch1) = $(git rev-parse HEAD) &&
205 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
206 test_path_is_missing .git/rebase-merge
209 test_expect_success
'abort with error when new base cannot be checked out' '
210 git rm --cached file1 &&
211 git commit -m "remove file in base" &&
213 test_must_fail git rebase -i master > output 2>&1 &&
214 grep "The following untracked working tree files would be overwritten by checkout:" \
216 grep "file1" output &&
217 test_path_is_missing .git/rebase-merge &&
218 git reset --hard HEAD^
221 test_expect_success
'retain authorship' '
225 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
228 git rebase -i --onto master HEAD^ &&
229 git show HEAD | grep "^Author: Twerp Snog"
232 test_expect_success
'squash' '
233 git reset --hard twerp &&
236 GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 &&
237 echo "******************************" &&
239 FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \
240 git rebase -i --onto master HEAD~2 &&
241 test B = $(cat file7) &&
242 test $(git rev-parse HEAD^) = $(git rev-parse master)
245 test_expect_success
'retain authorship when squashing' '
246 git show HEAD | grep "^Author: Twerp Snog"
249 test_expect_success
'-p handles "no changes" gracefully' '
250 HEAD=$(git rev-parse HEAD) &&
252 git rebase -i -p HEAD^ &&
253 git update-index --refresh &&
254 git diff-files --quiet &&
255 git diff-index --quiet --cached HEAD -- &&
256 test $HEAD = $(git rev-parse HEAD)
259 test_expect_failure
'exchange two commits with -p' '
262 FAKE_LINES="2 1" git rebase -i -p HEAD~2 &&
263 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
264 test G = $(git cat-file commit HEAD | sed -ne \$p)
267 test_expect_success
'preserve merges with -p' '
268 git checkout -b to-be-preserved master^ &&
269 : > unrelated-file &&
270 git add unrelated-file &&
272 git commit -m "unrelated" &&
273 git checkout -b another-branch master &&
276 git commit -m J file1 &&
278 git merge to-be-preserved &&
281 git commit -m K file1 &&
284 git commit -m L1 file1 &&
285 git checkout HEAD^ &&
286 echo 1 > unrelated-file &&
288 git commit -m L2 unrelated-file &&
290 git merge another-branch &&
293 git commit -m M file1 &&
294 git checkout -b to-be-rebased &&
297 git rebase -i -p --onto branch1 master &&
298 git update-index --refresh &&
299 git diff-files --quiet &&
300 git diff-index --quiet --cached HEAD -- &&
301 test $(git rev-parse HEAD~6) = $(git rev-parse branch1) &&
302 test $(git rev-parse HEAD~4^2) = $(git rev-parse to-be-preserved) &&
303 test $(git rev-parse HEAD^^2^) = $(git rev-parse HEAD^^^) &&
304 test $(git show HEAD~5:file1) = B &&
305 test $(git show HEAD~3:file1) = C &&
306 test $(git show HEAD:file1) = E &&
307 test $(git show HEAD:unrelated-file) = 1
310 test_expect_success
'edit ancestor with -p' '
312 FAKE_LINES="1 2 edit 3 4" git rebase -i -p HEAD~3 &&
313 echo 2 > unrelated-file &&
315 git commit -m L2-modified --amend unrelated-file &&
316 git rebase --continue &&
317 git update-index --refresh &&
318 git diff-files --quiet &&
319 git diff-index --quiet --cached HEAD -- &&
320 test $(git show HEAD:unrelated-file) = 2
323 test_expect_success
'--continue tries to commit' '
326 test_must_fail git rebase -i --onto new-branch1 HEAD^ &&
327 echo resolved > file1 &&
329 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
330 test $(git rev-parse HEAD^) = $(git rev-parse new-branch1) &&
331 git show HEAD | grep chouette
334 test_expect_success
'verbose flag is heeded, even after --continue' '
335 git reset --hard master@{1} &&
338 test_must_fail git rebase -v -i --onto new-branch1 HEAD^ &&
339 echo resolved > file1 &&
341 git rebase --continue > output &&
342 grep "^ file1 | 2 +-$" output
345 test_expect_success
'multi-squash only fires up editor once' '
346 base=$(git rev-parse HEAD~4) &&
348 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 squash 2 squash 3 squash 4" \
349 EXPECT_HEADER_COUNT=4 \
350 git rebase -i $base &&
351 test $base = $(git rev-parse HEAD^) &&
352 test 1 = $(git show | grep ONCE | wc -l)
355 test_expect_success
'multi-fixup does not fire up editor' '
356 git checkout -b multi-fixup E &&
357 base=$(git rev-parse HEAD~4) &&
359 FAKE_COMMIT_AMEND="NEVER" FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \
360 git rebase -i $base &&
361 test $base = $(git rev-parse HEAD^) &&
362 test 0 = $(git show | grep NEVER | wc -l) &&
363 git checkout to-be-rebased &&
364 git branch -D multi-fixup
367 test_expect_success
'commit message used after conflict' '
368 git checkout -b conflict-fixup conflict-branch &&
369 base=$(git rev-parse HEAD~4) &&
371 test_must_fail env FAKE_LINES="1 fixup 3 fixup 4" git rebase -i $base &&
372 echo three > conflict &&
374 FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \
375 git rebase --continue &&
376 test $base = $(git rev-parse HEAD^) &&
377 test 1 = $(git show | grep ONCE | wc -l) &&
378 git checkout to-be-rebased &&
379 git branch -D conflict-fixup
382 test_expect_success
'commit message retained after conflict' '
383 git checkout -b conflict-squash conflict-branch &&
384 base=$(git rev-parse HEAD~4) &&
386 test_must_fail env FAKE_LINES="1 fixup 3 squash 4" git rebase -i $base &&
387 echo three > conflict &&
389 FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \
390 git rebase --continue &&
391 test $base = $(git rev-parse HEAD^) &&
392 test 2 = $(git show | grep TWICE | wc -l) &&
393 git checkout to-be-rebased &&
394 git branch -D conflict-squash
397 cat > expect-squash-fixup
<< EOF
405 test_expect_success
'squash and fixup generate correct log messages' '
406 git checkout -b squash-fixup E &&
407 base=$(git rev-parse HEAD~4) &&
409 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 fixup 2 squash 3 fixup 4" \
410 EXPECT_HEADER_COUNT=4 \
411 git rebase -i $base &&
412 git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup &&
413 test_cmp expect-squash-fixup actual-squash-fixup &&
414 git checkout to-be-rebased &&
415 git branch -D squash-fixup
418 test_expect_success
'squash ignores comments' '
419 git checkout -b skip-comments E &&
420 base=$(git rev-parse HEAD~4) &&
422 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \
423 EXPECT_HEADER_COUNT=4 \
424 git rebase -i $base &&
425 test $base = $(git rev-parse HEAD^) &&
426 test 1 = $(git show | grep ONCE | wc -l) &&
427 git checkout to-be-rebased &&
428 git branch -D skip-comments
431 test_expect_success
'squash ignores blank lines' '
432 git checkout -b skip-blank-lines E &&
433 base=$(git rev-parse HEAD~4) &&
435 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \
436 EXPECT_HEADER_COUNT=4 \
437 git rebase -i $base &&
438 test $base = $(git rev-parse HEAD^) &&
439 test 1 = $(git show | grep ONCE | wc -l) &&
440 git checkout to-be-rebased &&
441 git branch -D skip-blank-lines
444 test_expect_success
'squash works as expected' '
445 git checkout -b squash-works no-conflict-branch &&
446 one=$(git rev-parse HEAD~3) &&
448 FAKE_LINES="1 squash 3 2" EXPECT_HEADER_COUNT=2 \
449 git rebase -i HEAD~3 &&
450 test $one = $(git rev-parse HEAD~2)
453 test_expect_success
'interrupted squash works as expected' '
454 git checkout -b interrupted-squash conflict-branch &&
455 one=$(git rev-parse HEAD~3) &&
457 test_must_fail env FAKE_LINES="1 squash 3 2" git rebase -i HEAD~3 &&
458 (echo one; echo two; echo four) > conflict &&
460 test_must_fail git rebase --continue &&
461 echo resolved > conflict &&
463 git rebase --continue &&
464 test $one = $(git rev-parse HEAD~2)
467 test_expect_success
'interrupted squash works as expected (case 2)' '
468 git checkout -b interrupted-squash2 conflict-branch &&
469 one=$(git rev-parse HEAD~3) &&
471 test_must_fail env FAKE_LINES="3 squash 1 2" git rebase -i HEAD~3 &&
472 (echo one; echo four) > conflict &&
474 test_must_fail git rebase --continue &&
475 (echo one; echo two; echo four) > conflict &&
477 test_must_fail git rebase --continue &&
478 echo resolved > conflict &&
480 git rebase --continue &&
481 test $one = $(git rev-parse HEAD~2)
484 test_expect_success
'--continue tries to commit, even for "edit"' '
485 echo unrelated > file7 &&
488 git commit -m "unrelated change" &&
489 parent=$(git rev-parse HEAD^) &&
492 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
493 echo edited > file7 &&
495 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
496 test edited = $(git show HEAD:file7) &&
497 git show HEAD | grep chouette &&
498 test $parent = $(git rev-parse HEAD^)
501 test_expect_success
'aborted --continue does not squash commits after "edit"' '
502 old=$(git rev-parse HEAD) &&
505 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
506 echo "edited again" > file7 &&
508 test_must_fail env FAKE_COMMIT_MESSAGE=" " git rebase --continue &&
509 test $old = $(git rev-parse HEAD) &&
513 test_expect_success
'auto-amend only edited commits after "edit"' '
516 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
517 echo "edited again" > file7 &&
519 FAKE_COMMIT_MESSAGE="edited file7 again" git commit &&
520 echo "and again" > file7 &&
523 test_must_fail env FAKE_COMMIT_MESSAGE="and again" git rebase --continue &&
527 test_expect_success
'clean error after failed "exec"' '
529 test_when_finished "git rebase --abort || :" &&
531 test_must_fail env FAKE_LINES="1 exec_false" git rebase -i HEAD^ &&
532 echo "edited again" > file7 &&
534 test_must_fail git rebase --continue 2>error &&
535 grep "You have staged changes in your working tree." error
538 test_expect_success
'rebase a detached HEAD' '
539 grandparent=$(git rev-parse HEAD~2) &&
540 git checkout $(git rev-parse HEAD) &&
543 FAKE_LINES="2 1" git rebase -i HEAD~2 &&
544 test $grandparent = $(git rev-parse HEAD~2)
547 test_expect_success
'rebase a commit violating pre-commit' '
549 mkdir -p .git/hooks &&
550 PRE_COMMIT=.git/hooks/pre-commit &&
551 echo "#!/bin/sh" > $PRE_COMMIT &&
552 echo "test -z \"\$(git diff --cached --check)\"" >> $PRE_COMMIT &&
553 chmod a+x $PRE_COMMIT &&
554 echo "monde! " >> file1 &&
556 test_must_fail git commit -m doesnt-verify file1 &&
557 git commit -m doesnt-verify --no-verify file1 &&
560 FAKE_LINES=2 git rebase -i HEAD~2
564 test_expect_success
'rebase with a file named HEAD in worktree' '
568 git checkout -b branch3 A &&
571 GIT_AUTHOR_NAME="Squashed Away" &&
572 export GIT_AUTHOR_NAME &&
575 git commit -m "Add head" &&
578 git commit -m "Add body"
582 FAKE_LINES="1 squash 2" git rebase -i to-be-rebased &&
583 test "$(git show -s --pretty=format:%an)" = "Squashed Away"
587 test_expect_success
'do "noop" when there is nothing to cherry-pick' '
589 git checkout -b branch4 HEAD &&
590 GIT_EDITOR=: git commit --amend \
591 --author="Somebody else <somebody@else.com>" &&
592 test $(git rev-parse branch3) != $(git rev-parse branch4) &&
594 git rebase -i branch3 &&
595 test $(git rev-parse branch3) = $(git rev-parse branch4)
599 test_expect_success
'submodule rebase setup' '
603 cd sub && git init && >elif &&
604 git add elif && git commit -m "submodule initial"
609 git commit -m "One" &&
612 git commit -a -m "Two" &&
614 cd sub && echo 3 >elif &&
615 git commit -a -m "submodule second"
619 git commit -a -m "Three changes submodule"
622 test_expect_success
'submodule rebase -i' '
624 FAKE_LINES="1 squash 2 3" git rebase -i A
627 test_expect_success
'submodule conflict setup' '
628 git tag submodule-base &&
629 git checkout HEAD^ &&
631 cd sub && git checkout HEAD^ && echo 4 >elif &&
632 git add elif && git commit -m "submodule conflict"
636 git commit -m "Conflict in submodule" &&
637 git tag submodule-topic
640 test_expect_success
'rebase -i continue with only submodule staged' '
642 test_must_fail git rebase -i submodule-base &&
644 git rebase --continue &&
645 test $(git rev-parse submodule-base) != $(git rev-parse HEAD)
648 test_expect_success
'rebase -i continue with unstaged submodule' '
649 git checkout submodule-topic &&
652 test_must_fail git rebase -i submodule-base &&
654 git rebase --continue &&
655 test $(git rev-parse submodule-base) = $(git rev-parse HEAD)
658 test_expect_success
'avoid unnecessary reset' '
659 git checkout master &&
661 test-chmtime =123456789 file3 &&
662 git update-index --refresh &&
663 HEAD=$(git rev-parse HEAD) &&
665 git rebase -i HEAD~4 &&
666 test $HEAD = $(git rev-parse HEAD) &&
667 MTIME=$(test-chmtime -v +0 file3 | sed 's
/[^
0-9].
*$
//') &&
668 test 123456789 = $MTIME
671 test_expect_success
'reword' '
672 git checkout -b reword-branch master &&
674 FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" git rebase -i A &&
675 git show HEAD | grep "E changed" &&
676 test $(git rev-parse master) != $(git rev-parse HEAD) &&
677 test $(git rev-parse master^) = $(git rev-parse HEAD^) &&
678 FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" git rebase -i A &&
679 git show HEAD^ | grep "D changed" &&
680 FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" git rebase -i A &&
681 git show HEAD~3 | grep "B changed" &&
682 FAKE_LINES="1 reword 2 3 4" FAKE_COMMIT_MESSAGE="C changed" git rebase -i A &&
683 git show HEAD~2 | grep "C changed"
686 test_expect_success
'rebase -i can copy notes' '
687 git config notes.rewrite.rebase true &&
688 git config notes.rewriteRef "refs/notes/*" &&
692 git notes add -m"a note" n3 &&
694 git rebase -i --onto n1 n2 &&
695 test "a note" = "$(git notes show HEAD)"
704 test_expect_success
'rebase -i can copy notes over a fixup' '
705 git reset --hard n3 &&
706 git notes add -m"an earlier note" n2 &&
708 GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 fixup 2" git rebase -i n1 &&
709 git notes show > output &&
710 test_cmp expect output
713 test_expect_success
'rebase while detaching HEAD' '
714 git symbolic-ref HEAD &&
715 grandparent=$(git rev-parse HEAD~2) &&
718 FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0 &&
719 test $grandparent = $(git rev-parse HEAD~2) &&
720 test_must_fail git symbolic-ref HEAD
723 test_tick
# Ensure that the rebased commits get a different timestamp.
724 test_expect_success
'always cherry-pick with --no-ff' '
725 git checkout no-ff-branch &&
726 git tag original-no-ff-branch &&
728 git rebase -i --no-ff A &&
732 test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) &&
733 git diff HEAD~$p original-no-ff-branch~$p > out &&
736 test $(git rev-parse HEAD~3) = $(git rev-parse original-no-ff-branch~3) &&
737 git diff HEAD~3 original-no-ff-branch~3 > out &&
741 test_expect_success
'set up commits with funny messages' '
742 git checkout -b funny A &&
745 git commit -a -m "end with slash\\" &&
748 git commit -a -m "something (\000) that looks like octal" &&
751 git commit -a -m "something (\n) that looks like a newline" &&
754 git commit -a -m "another commit"
757 test_expect_success
'rebase-i history with funny messages' '
758 git rev-list A..funny >expect &&
761 FAKE_LINES="1 2 3 4" git rebase -i A &&
762 git rev-list A.. >actual &&
763 test_cmp expect actual
767 test_expect_success
'prepare for rebase -i --exec' '
768 git checkout master &&
769 git checkout -b execute &&
770 test_commit one_exec main.txt one_exec &&
771 test_commit two_exec main.txt two_exec &&
772 test_commit three_exec main.txt three_exec
776 test_expect_success
'running "git rebase -i --exec git show HEAD"' '
778 git rebase -i --exec "git show HEAD" HEAD~2 >actual &&
780 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
782 git rebase -i HEAD~2 >expect
784 sed -e "1,9d" expect >expected &&
785 test_cmp expected actual
789 test_expect_success
'running "git rebase --exec git show HEAD -i"' '
790 git reset --hard execute &&
792 git rebase --exec "git show HEAD" -i HEAD~2 >actual &&
794 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
796 git rebase -i HEAD~2 >expect
798 sed -e "1,9d" expect >expected &&
799 test_cmp expected actual
803 test_expect_success
'running "git rebase -ix git show HEAD"' '
804 git reset --hard execute &&
806 git rebase -ix "git show HEAD" HEAD~2 >actual &&
808 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
810 git rebase -i HEAD~2 >expect
812 sed -e "1,9d" expect >expected &&
813 test_cmp expected actual
817 test_expect_success
'rebase -ix with several <CMD>' '
818 git reset --hard execute &&
820 git rebase -ix "git show HEAD; pwd" HEAD~2 >actual &&
822 FAKE_LINES="1 exec_git_show_HEAD;_pwd 2 exec_git_show_HEAD;_pwd" &&
824 git rebase -i HEAD~2 >expect
826 sed -e "1,9d" expect >expected &&
827 test_cmp expected actual
831 test_expect_success
'rebase -ix with several instances of --exec' '
832 git reset --hard execute &&
834 git rebase -i --exec "git show HEAD" --exec "pwd" HEAD~2 >actual &&
836 FAKE_LINES="1 exec_git_show_HEAD exec_pwd 2
837 exec_git_show_HEAD exec_pwd" &&
839 git rebase -i HEAD~2 >expect
841 sed -e "1,11d" expect >expected &&
842 test_cmp expected actual
846 test_expect_success
'rebase -ix with --autosquash' '
847 git reset --hard execute &&
848 git checkout -b autosquash &&
849 echo second >second.txt &&
850 git add second.txt &&
851 git commit -m "fixup! two_exec" &&
854 git commit -m "fixup! two_exec" &&
857 git checkout -b autosquash_actual &&
858 git rebase -i --exec "git show HEAD" --autosquash HEAD~4 >actual
860 git checkout autosquash &&
862 git checkout -b autosquash_expected &&
863 FAKE_LINES="1 fixup 3 fixup 4 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
865 git rebase -i HEAD~4 >expect
867 sed -e "1,13d" expect >expected &&
868 test_cmp expected actual
872 test_expect_success
'rebase --exec without -i shows error message' '
873 git reset --hard execute &&
875 test_must_fail git rebase --exec "git show HEAD" HEAD~2 2>actual &&
876 echo "The --exec option must be used with the --interactive option" >expected &&
877 test_i18ncmp expected actual
881 test_expect_success
'rebase -i --exec without <CMD>' '
882 git reset --hard execute &&
884 test_must_fail git rebase -i --exec 2>tmp &&
885 sed -e "1d" tmp >actual &&
886 test_must_fail git rebase -h >expected &&
887 test_cmp expected actual &&
891 test_expect_success
'rebase -i --root re-order and drop commits' '
894 FAKE_LINES="3 1 2 5" git rebase -i --root &&
895 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
896 test B = $(git cat-file commit HEAD^ | sed -ne \$p) &&
897 test A = $(git cat-file commit HEAD^^ | sed -ne \$p) &&
898 test C = $(git cat-file commit HEAD^^^ | sed -ne \$p) &&
899 test 0 = $(git cat-file commit HEAD^^^ | grep -c ^parent\ )
902 test_expect_success
'rebase -i --root retain root commit author and message' '
906 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
908 FAKE_LINES="2" git rebase -i --root &&
909 git cat-file commit HEAD | grep -q "^author Twerp Snog" &&
910 git cat-file commit HEAD | grep -q "^different author$"
913 test_expect_success
'rebase -i --root temporary sentinel commit' '
916 test_must_fail env FAKE_LINES="2" git rebase -i --root &&
917 git cat-file commit HEAD | grep "^tree 4b825dc642cb" &&
921 test_expect_success
'rebase -i --root fixup root commit' '
924 FAKE_LINES="1 fixup 2" git rebase -i --root &&
925 test A = $(git cat-file commit HEAD | sed -ne \$p) &&
926 test B = $(git show HEAD:file1) &&
927 test 0 = $(git cat-file commit HEAD | grep -c ^parent\ )
930 test_expect_success
'rebase --edit-todo does not works on non-interactive rebase' '
932 git checkout conflict-branch &&
934 test_must_fail git rebase --onto HEAD~2 HEAD~ &&
935 test_must_fail git rebase --edit-todo &&
939 test_expect_success
'rebase --edit-todo can be used to modify todo' '
941 git checkout no-conflict-branch^0 &&
943 FAKE_LINES="edit 1 2 3" git rebase -i HEAD~3 &&
944 FAKE_LINES="2 1" git rebase --edit-todo &&
945 git rebase --continue
946 test M = $(git cat-file commit HEAD^ | sed -ne \$p) &&
947 test L = $(git cat-file commit HEAD | sed -ne \$p)
950 test_expect_success
'rebase -i produces readable reflog' '
952 git branch -f branch-reflog-test H &&
954 git rebase -i --onto I F branch-reflog-test &&
955 cat >expect <<-\EOF &&
956 rebase -i (start): checkout I
959 rebase -i (finish): returning to refs/heads/branch-reflog-test
961 tail -n 4 .git/logs/HEAD |
962 sed -e "s/.* //" >actual &&
963 test_cmp expect actual
966 test_expect_success
'rebase -i respects core.commentchar' '
969 test_config core.commentchar "\\" &&
970 write_script remove-all-but-first.sh <<-\EOF &&
971 sed -e "2,\$s/^/\\\\/" "$1" >"$1.tmp" &&
974 test_set_editor "$(pwd)/remove-all-but-first.sh" &&
976 test B = $(git cat-file commit HEAD^ | sed -ne \$p)
979 test_expect_success
'rebase -i, with <onto> and <upstream> specified as :/quuxery' '
980 test_when_finished "git branch -D torebase" &&
981 git checkout -b torebase branch1 &&
982 upstream=$(git rev-parse ":/J") &&
983 onto=$(git rev-parse ":/A") &&
984 git rebase --onto $onto $upstream &&
985 git reset --hard branch1 &&
986 git rebase --onto ":/A" ":/J" &&
990 test_expect_success
'rebase -i with --strategy and -X' '
991 git checkout -b conflict-merge-use-theirs conflict-branch &&
992 git reset --hard HEAD^ &&
993 echo five >conflict &&
995 git commit -a -m "one file conflict" &&
996 EDITOR=true git rebase -i --strategy=recursive -Xours conflict-branch &&
997 test $(git show conflict-branch:conflict) = $(cat conflict) &&
998 test $(cat file1) = Z
1001 test_expect_success
'rebase -i error on commits with \ in message' '
1002 current_head=$(git rev-parse HEAD)
1003 test_when_finished "git rebase --abort; git reset --hard $current_head; rm -f error" &&
1004 test_commit TO-REMOVE will-conflict old-content &&
1005 test_commit "\temp" will-conflict new-content dummy &&
1006 test_must_fail env EDITOR=true git rebase -i HEAD^ --onto HEAD^^ 2>error &&
1007 test_expect_code 1 grep " emp" error
1010 test_expect_success
'short SHA-1 setup' '
1011 test_when_finished "git checkout master" &&
1012 git checkout --orphan collide &&
1016 test_commit collide1 collide &&
1017 test_commit --notick collide2 collide &&
1018 test_commit --notick collide3 collide
1022 test_expect_success
'short SHA-1 collide' '
1023 test_when_finished "reset_rebase && git checkout master" &&
1024 git checkout collide &&
1029 FAKE_COMMIT_MESSAGE="collide2 ac4f2ee" \
1030 FAKE_LINES="reword 1 2" git rebase -i HEAD~2