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
34 # WARNING: Modifications to the initial repository can change the SHA ID used
35 # in the expect2 file for the 'stop on conflicting pick' test.
37 test_expect_success
'setup' '
38 test_commit A file1 &&
39 test_commit B file1 &&
40 test_commit C file2 &&
41 test_commit D file1 &&
42 test_commit E file3 &&
43 git checkout -b branch1 A &&
44 test_commit F file4 &&
45 test_commit G file1 &&
46 test_commit H file5 &&
47 git checkout -b branch2 F &&
48 test_commit I file6 &&
49 git checkout -b conflict-branch A &&
50 test_commit one conflict &&
51 test_commit two conflict &&
52 test_commit three conflict &&
53 test_commit four conflict &&
54 git checkout -b no-conflict-branch A &&
55 test_commit J fileJ &&
56 test_commit K fileK &&
57 test_commit L fileL &&
58 test_commit M fileM &&
59 git checkout -b no-ff-branch A &&
60 test_commit N fileN &&
61 test_commit O fileO &&
65 # "exec" commands are ran with the user shell by default, but this may
66 # be non-POSIX. For example, if SHELL=zsh then ">file" doesn't work
67 # to create a file. Unseting SHELL avoids such non-portable behavior
68 # in tests. It must be exported for it to take effect where needed.
72 test_expect_success
'rebase -i with the exec command' '
73 git checkout master &&
75 FAKE_LINES="1 exec_>touch-one
76 2 exec_>touch-two exec_false exec_>touch-three
77 3 4 exec_>\"touch-file__name_with_spaces\";_>touch-after-semicolon 5" &&
79 test_must_fail git rebase -i A
81 test_path_is_file touch-one &&
82 test_path_is_file touch-two &&
83 test_path_is_missing touch-three " (should have stopped before)" &&
84 test_cmp_rev C HEAD &&
85 git rebase --continue &&
86 test_path_is_file touch-three &&
87 test_path_is_file "touch-file name with spaces" &&
88 test_path_is_file touch-after-semicolon &&
89 test_cmp_rev master HEAD &&
93 test_expect_success
'rebase -i with the exec command runs from tree root' '
94 git checkout master &&
95 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 FAKE_LINES="exec_echo_foo_>file1 1" &&
108 test_must_fail git rebase -i HEAD^
110 test_cmp_rev master^ HEAD &&
112 git rebase --continue
115 test_expect_success
'rebase -i with exec of inexistent command' '
116 git checkout master &&
117 test_when_finished "git rebase --abort" &&
119 FAKE_LINES="exec_this-command-does-not-exist 1" &&
121 test_must_fail git rebase -i HEAD^ >actual 2>&1
123 ! grep "Maybe git-rebase is broken" actual
126 test_expect_success
'no changes are a nop' '
127 git checkout branch2 &&
129 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
130 test $(git rev-parse I) = $(git rev-parse HEAD)
133 test_expect_success
'test the [branch] option' '
134 git checkout -b dead-end &&
136 git commit -m "stop here" &&
137 git rebase -i F branch2 &&
138 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
139 test $(git rev-parse I) = $(git rev-parse branch2) &&
140 test $(git rev-parse I) = $(git rev-parse HEAD)
143 test_expect_success
'test --onto <branch>' '
144 git checkout -b test-onto branch2 &&
145 git rebase -i --onto branch1 F &&
146 test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" &&
147 test $(git rev-parse HEAD^) = $(git rev-parse branch1) &&
148 test $(git rev-parse I) = $(git rev-parse branch2)
151 test_expect_success
'rebase on top of a non-conflicting commit' '
152 git checkout branch1 &&
153 git tag original-branch1 &&
154 git rebase -i branch2 &&
155 test file6 = $(git diff --name-only original-branch1) &&
156 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
157 test $(git rev-parse I) = $(git rev-parse branch2) &&
158 test $(git rev-parse I) = $(git rev-parse HEAD~2)
161 test_expect_success
'reflog for the branch shows state before rebase' '
162 test $(git rev-parse branch1@{1}) = $(git rev-parse original-branch1)
165 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 &&
191 test_must_fail git rebase -i master &&
192 test "$(git rev-parse HEAD~3)" = "$(git rev-parse master)" &&
193 test_cmp expect .git/rebase-merge/patch &&
194 test_cmp expect2 file1 &&
195 test "$(git diff --name-status |
196 sed -n -e "/^U/s/^U[^a-z]*//p")" = file1 &&
197 test 4 = $(grep -v "^#" < .git/rebase-merge/done | wc -l) &&
198 test 0 = $(grep -c "^[^#]" < .git/rebase-merge/git-rebase-todo)
201 test_expect_success
'abort' '
202 git rebase --abort &&
203 test $(git rev-parse new-branch1) = $(git rev-parse HEAD) &&
204 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
205 test_path_is_missing .git/rebase-merge
208 test_expect_success
'abort with error when new base cannot be checked out' '
209 git rm --cached file1 &&
210 git commit -m "remove file in base" &&
211 test_must_fail git rebase -i master > output 2>&1 &&
212 grep "The following untracked working tree files would be overwritten by checkout:" \
214 grep "file1" output &&
215 test_path_is_missing .git/rebase-merge &&
216 git reset --hard HEAD^
219 test_expect_success
'retain authorship' '
223 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
225 git rebase -i --onto master HEAD^ &&
226 git show HEAD | grep "^Author: Twerp Snog"
229 test_expect_success
'squash' '
230 git reset --hard twerp &&
233 GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 &&
234 echo "******************************" &&
235 FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \
236 git rebase -i --onto master HEAD~2 &&
237 test B = $(cat file7) &&
238 test $(git rev-parse HEAD^) = $(git rev-parse master)
241 test_expect_success
'retain authorship when squashing' '
242 git show HEAD | grep "^Author: Twerp Snog"
245 test_expect_success
'-p handles "no changes" gracefully' '
246 HEAD=$(git rev-parse HEAD) &&
247 git rebase -i -p HEAD^ &&
248 git update-index --refresh &&
249 git diff-files --quiet &&
250 git diff-index --quiet --cached HEAD -- &&
251 test $HEAD = $(git rev-parse HEAD)
254 test_expect_failure
'exchange two commits with -p' '
256 FAKE_LINES="2 1" git rebase -i -p HEAD~2 &&
257 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
258 test G = $(git cat-file commit HEAD | sed -ne \$p)
261 test_expect_success
'preserve merges with -p' '
262 git checkout -b to-be-preserved master^ &&
263 : > unrelated-file &&
264 git add unrelated-file &&
266 git commit -m "unrelated" &&
267 git checkout -b another-branch master &&
270 git commit -m J file1 &&
272 git merge to-be-preserved &&
275 git commit -m K file1 &&
278 git commit -m L1 file1 &&
279 git checkout HEAD^ &&
280 echo 1 > unrelated-file &&
282 git commit -m L2 unrelated-file &&
284 git merge another-branch &&
287 git commit -m M file1 &&
288 git checkout -b to-be-rebased &&
290 git rebase -i -p --onto branch1 master &&
291 git update-index --refresh &&
292 git diff-files --quiet &&
293 git diff-index --quiet --cached HEAD -- &&
294 test $(git rev-parse HEAD~6) = $(git rev-parse branch1) &&
295 test $(git rev-parse HEAD~4^2) = $(git rev-parse to-be-preserved) &&
296 test $(git rev-parse HEAD^^2^) = $(git rev-parse HEAD^^^) &&
297 test $(git show HEAD~5:file1) = B &&
298 test $(git show HEAD~3:file1) = C &&
299 test $(git show HEAD:file1) = E &&
300 test $(git show HEAD:unrelated-file) = 1
303 test_expect_success
'edit ancestor with -p' '
304 FAKE_LINES="1 2 edit 3 4" git rebase -i -p HEAD~3 &&
305 echo 2 > unrelated-file &&
307 git commit -m L2-modified --amend unrelated-file &&
308 git rebase --continue &&
309 git update-index --refresh &&
310 git diff-files --quiet &&
311 git diff-index --quiet --cached HEAD -- &&
312 test $(git show HEAD:unrelated-file) = 2
315 test_expect_success
'--continue tries to commit' '
317 test_must_fail git rebase -i --onto new-branch1 HEAD^ &&
318 echo resolved > file1 &&
320 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
321 test $(git rev-parse HEAD^) = $(git rev-parse new-branch1) &&
322 git show HEAD | grep chouette
325 test_expect_success
'verbose flag is heeded, even after --continue' '
326 git reset --hard master@{1} &&
328 test_must_fail git rebase -v -i --onto new-branch1 HEAD^ &&
329 echo resolved > file1 &&
331 git rebase --continue > output &&
332 grep "^ file1 | 2 +-$" output
335 test_expect_success
'multi-squash only fires up editor once' '
336 base=$(git rev-parse HEAD~4) &&
337 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 squash 2 squash 3 squash 4" \
338 EXPECT_HEADER_COUNT=4 \
339 git rebase -i $base &&
340 test $base = $(git rev-parse HEAD^) &&
341 test 1 = $(git show | grep ONCE | wc -l)
344 test_expect_success
'multi-fixup does not fire up editor' '
345 git checkout -b multi-fixup E &&
346 base=$(git rev-parse HEAD~4) &&
347 FAKE_COMMIT_AMEND="NEVER" FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \
348 git rebase -i $base &&
349 test $base = $(git rev-parse HEAD^) &&
350 test 0 = $(git show | grep NEVER | wc -l) &&
351 git checkout to-be-rebased &&
352 git branch -D multi-fixup
355 test_expect_success
'commit message used after conflict' '
356 git checkout -b conflict-fixup conflict-branch &&
357 base=$(git rev-parse HEAD~4) &&
359 FAKE_LINES="1 fixup 3 fixup 4" &&
361 test_must_fail git rebase -i $base
363 echo three > conflict &&
365 FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \
366 git rebase --continue &&
367 test $base = $(git rev-parse HEAD^) &&
368 test 1 = $(git show | grep ONCE | wc -l) &&
369 git checkout to-be-rebased &&
370 git branch -D conflict-fixup
373 test_expect_success
'commit message retained after conflict' '
374 git checkout -b conflict-squash conflict-branch &&
375 base=$(git rev-parse HEAD~4) &&
377 FAKE_LINES="1 fixup 3 squash 4" &&
379 test_must_fail git rebase -i $base
381 echo three > conflict &&
383 FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \
384 git rebase --continue &&
385 test $base = $(git rev-parse HEAD^) &&
386 test 2 = $(git show | grep TWICE | wc -l) &&
387 git checkout to-be-rebased &&
388 git branch -D conflict-squash
391 cat > expect-squash-fixup
<< EOF
399 test_expect_success
'squash and fixup generate correct log messages' '
400 git checkout -b squash-fixup E &&
401 base=$(git rev-parse HEAD~4) &&
402 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 fixup 2 squash 3 fixup 4" \
403 EXPECT_HEADER_COUNT=4 \
404 git rebase -i $base &&
405 git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup &&
406 test_cmp expect-squash-fixup actual-squash-fixup &&
407 git checkout to-be-rebased &&
408 git branch -D squash-fixup
411 test_expect_success
'squash ignores comments' '
412 git checkout -b skip-comments E &&
413 base=$(git rev-parse HEAD~4) &&
414 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \
415 EXPECT_HEADER_COUNT=4 \
416 git rebase -i $base &&
417 test $base = $(git rev-parse HEAD^) &&
418 test 1 = $(git show | grep ONCE | wc -l) &&
419 git checkout to-be-rebased &&
420 git branch -D skip-comments
423 test_expect_success
'squash ignores blank lines' '
424 git checkout -b skip-blank-lines E &&
425 base=$(git rev-parse HEAD~4) &&
426 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \
427 EXPECT_HEADER_COUNT=4 \
428 git rebase -i $base &&
429 test $base = $(git rev-parse HEAD^) &&
430 test 1 = $(git show | grep ONCE | wc -l) &&
431 git checkout to-be-rebased &&
432 git branch -D skip-blank-lines
435 test_expect_success
'squash works as expected' '
436 git checkout -b squash-works no-conflict-branch &&
437 one=$(git rev-parse HEAD~3) &&
438 FAKE_LINES="1 squash 3 2" EXPECT_HEADER_COUNT=2 \
439 git rebase -i HEAD~3 &&
440 test $one = $(git rev-parse HEAD~2)
443 test_expect_success
'interrupted squash works as expected' '
444 git checkout -b interrupted-squash conflict-branch &&
445 one=$(git rev-parse HEAD~3) &&
447 FAKE_LINES="1 squash 3 2" &&
449 test_must_fail git rebase -i HEAD~3
451 (echo one; echo two; echo four) > conflict &&
453 test_must_fail git rebase --continue &&
454 echo resolved > conflict &&
456 git rebase --continue &&
457 test $one = $(git rev-parse HEAD~2)
460 test_expect_success
'interrupted squash works as expected (case 2)' '
461 git checkout -b interrupted-squash2 conflict-branch &&
462 one=$(git rev-parse HEAD~3) &&
464 FAKE_LINES="3 squash 1 2" &&
466 test_must_fail git rebase -i HEAD~3
468 (echo one; echo four) > conflict &&
470 test_must_fail git rebase --continue &&
471 (echo one; echo two; echo four) > conflict &&
473 test_must_fail git rebase --continue &&
474 echo resolved > conflict &&
476 git rebase --continue &&
477 test $one = $(git rev-parse HEAD~2)
480 test_expect_success
'--continue tries to commit, even for "edit"' '
481 echo unrelated > file7 &&
484 git commit -m "unrelated change" &&
485 parent=$(git rev-parse HEAD^) &&
487 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
488 echo edited > file7 &&
490 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
491 test edited = $(git show HEAD:file7) &&
492 git show HEAD | grep chouette &&
493 test $parent = $(git rev-parse HEAD^)
496 test_expect_success
'aborted --continue does not squash commits after "edit"' '
497 old=$(git rev-parse HEAD) &&
499 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
500 echo "edited again" > file7 &&
503 FAKE_COMMIT_MESSAGE=" " &&
504 export FAKE_COMMIT_MESSAGE &&
505 test_must_fail git rebase --continue
507 test $old = $(git rev-parse HEAD) &&
511 test_expect_success
'auto-amend only edited commits after "edit"' '
513 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
514 echo "edited again" > file7 &&
516 FAKE_COMMIT_MESSAGE="edited file7 again" git commit &&
517 echo "and again" > file7 &&
521 FAKE_COMMIT_MESSAGE="and again" &&
522 export FAKE_COMMIT_MESSAGE &&
523 test_must_fail git rebase --continue
528 test_expect_success
'clean error after failed "exec"' '
530 test_when_finished "git rebase --abort || :" &&
532 FAKE_LINES="1 exec_false" &&
534 test_must_fail git rebase -i HEAD^
536 echo "edited again" > file7 &&
538 test_must_fail git rebase --continue 2>error &&
539 grep "You have staged changes in your working tree." error
542 test_expect_success
'rebase a detached HEAD' '
543 grandparent=$(git rev-parse HEAD~2) &&
544 git checkout $(git rev-parse HEAD) &&
546 FAKE_LINES="2 1" git rebase -i HEAD~2 &&
547 test $grandparent = $(git rev-parse HEAD~2)
550 test_expect_success
'rebase a commit violating pre-commit' '
552 mkdir -p .git/hooks &&
553 PRE_COMMIT=.git/hooks/pre-commit &&
554 echo "#!/bin/sh" > $PRE_COMMIT &&
555 echo "test -z \"\$(git diff --cached --check)\"" >> $PRE_COMMIT &&
556 chmod a+x $PRE_COMMIT &&
557 echo "monde! " >> file1 &&
559 test_must_fail git commit -m doesnt-verify file1 &&
560 git commit -m doesnt-verify --no-verify file1 &&
562 FAKE_LINES=2 git rebase -i HEAD~2
566 test_expect_success
'rebase with a file named HEAD in worktree' '
570 git checkout -b branch3 A &&
573 GIT_AUTHOR_NAME="Squashed Away" &&
574 export GIT_AUTHOR_NAME &&
577 git commit -m "Add head" &&
580 git commit -m "Add body"
583 FAKE_LINES="1 squash 2" git rebase -i to-be-rebased &&
584 test "$(git show -s --pretty=format:%an)" = "Squashed Away"
588 test_expect_success
'do "noop" when there is nothing to cherry-pick' '
590 git checkout -b branch4 HEAD &&
591 GIT_EDITOR=: git commit --amend \
592 --author="Somebody else <somebody@else.com>" &&
593 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"
618 git commit -a -m "Three changes submodule"
621 test_expect_success
'submodule rebase -i' '
622 FAKE_LINES="1 squash 2 3" git rebase -i A
625 test_expect_success
'submodule conflict setup' '
626 git tag submodule-base &&
627 git checkout HEAD^ &&
629 cd sub && git checkout HEAD^ && echo 4 >elif &&
630 git add elif && git commit -m "submodule conflict"
634 git commit -m "Conflict in submodule" &&
635 git tag submodule-topic
638 test_expect_success
'rebase -i continue with only submodule staged' '
639 test_must_fail git rebase -i submodule-base &&
641 git rebase --continue &&
642 test $(git rev-parse submodule-base) != $(git rev-parse HEAD)
645 test_expect_success
'rebase -i continue with unstaged submodule' '
646 git checkout submodule-topic &&
648 test_must_fail git rebase -i submodule-base &&
650 git rebase --continue &&
651 test $(git rev-parse submodule-base) = $(git rev-parse HEAD)
654 test_expect_success
'avoid unnecessary reset' '
655 git checkout master &&
657 test-chmtime =123456789 file3 &&
658 git update-index --refresh &&
659 HEAD=$(git rev-parse HEAD) &&
660 git rebase -i HEAD~4 &&
661 test $HEAD = $(git rev-parse HEAD) &&
662 MTIME=$(test-chmtime -v +0 file3 | sed 's
/[^
0-9].
*$
//') &&
663 test 123456789 = $MTIME
666 test_expect_success
'reword' '
667 git checkout -b reword-branch master &&
668 FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" git rebase -i A &&
669 git show HEAD | grep "E changed" &&
670 test $(git rev-parse master) != $(git rev-parse HEAD) &&
671 test $(git rev-parse master^) = $(git rev-parse HEAD^) &&
672 FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" git rebase -i A &&
673 git show HEAD^ | grep "D changed" &&
674 FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" git rebase -i A &&
675 git show HEAD~3 | grep "B changed" &&
676 FAKE_LINES="1 reword 2 3 4" FAKE_COMMIT_MESSAGE="C changed" git rebase -i A &&
677 git show HEAD~2 | grep "C changed"
680 test_expect_success
'rebase -i can copy notes' '
681 git config notes.rewrite.rebase true &&
682 git config notes.rewriteRef "refs/notes/*" &&
686 git notes add -m"a note" n3 &&
687 git rebase -i --onto n1 n2 &&
688 test "a note" = "$(git notes show HEAD)"
697 test_expect_success
'rebase -i can copy notes over a fixup' '
698 git reset --hard n3 &&
699 git notes add -m"an earlier note" n2 &&
700 GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 fixup 2" git rebase -i n1 &&
701 git notes show > output &&
702 test_cmp expect output
705 test_expect_success
'rebase while detaching HEAD' '
706 git symbolic-ref HEAD &&
707 grandparent=$(git rev-parse HEAD~2) &&
709 FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0 &&
710 test $grandparent = $(git rev-parse HEAD~2) &&
711 test_must_fail git symbolic-ref HEAD
714 test_tick
# Ensure that the rebased commits get a different timestamp.
715 test_expect_success
'always cherry-pick with --no-ff' '
716 git checkout no-ff-branch &&
717 git tag original-no-ff-branch &&
718 git rebase -i --no-ff A &&
722 test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) &&
723 git diff HEAD~$p original-no-ff-branch~$p > out &&
726 test $(git rev-parse HEAD~3) = $(git rev-parse original-no-ff-branch~3) &&
727 git diff HEAD~3 original-no-ff-branch~3 > out &&
731 test_expect_success
'set up commits with funny messages' '
732 git checkout -b funny A &&
735 git commit -a -m "end with slash\\" &&
738 git commit -a -m "something (\000) that looks like octal" &&
741 git commit -a -m "something (\n) that looks like a newline" &&
744 git commit -a -m "another commit"
747 test_expect_success
'rebase-i history with funny messages' '
748 git rev-list A..funny >expect &&
750 FAKE_LINES="1 2 3 4" git rebase -i A &&
751 git rev-list A.. >actual &&
752 test_cmp expect actual
756 test_expect_success
'prepare for rebase -i --exec' '
757 git checkout master &&
758 git checkout -b execute &&
759 test_commit one_exec main.txt one_exec &&
760 test_commit two_exec main.txt two_exec &&
761 test_commit three_exec main.txt three_exec
765 test_expect_success
'running "git rebase -i --exec git show HEAD"' '
766 git rebase -i --exec "git show HEAD" HEAD~2 >actual &&
768 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
770 git rebase -i HEAD~2 >expect
772 sed -e "1,9d" expect >expected &&
773 test_cmp expected actual
777 test_expect_success
'running "git rebase --exec git show HEAD -i"' '
778 git reset --hard execute &&
779 git rebase --exec "git show HEAD" -i HEAD~2 >actual &&
781 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
783 git rebase -i HEAD~2 >expect
785 sed -e "1,9d" expect >expected &&
786 test_cmp expected actual
790 test_expect_success
'running "git rebase -ix git show HEAD"' '
791 git reset --hard execute &&
792 git rebase -ix "git show HEAD" 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
'rebase -ix with several <CMD>' '
804 git reset --hard execute &&
805 git rebase -ix "git show HEAD; pwd" HEAD~2 >actual &&
807 FAKE_LINES="1 exec_git_show_HEAD;_pwd 2 exec_git_show_HEAD;_pwd" &&
809 git rebase -i HEAD~2 >expect
811 sed -e "1,9d" expect >expected &&
812 test_cmp expected actual
816 test_expect_success
'rebase -ix with several instances of --exec' '
817 git reset --hard execute &&
818 git rebase -i --exec "git show HEAD" --exec "pwd" HEAD~2 >actual &&
820 FAKE_LINES="1 exec_git_show_HEAD exec_pwd 2
821 exec_git_show_HEAD exec_pwd" &&
823 git rebase -i HEAD~2 >expect
825 sed -e "1,11d" expect >expected &&
826 test_cmp expected actual
830 test_expect_success
'rebase -ix with --autosquash' '
831 git reset --hard execute &&
832 git checkout -b autosquash &&
833 echo second >second.txt &&
834 git add second.txt &&
835 git commit -m "fixup! two_exec" &&
838 git commit -m "fixup! two_exec" &&
840 git checkout -b autosquash_actual &&
841 git rebase -i --exec "git show HEAD" --autosquash HEAD~4 >actual
843 git checkout autosquash &&
845 git checkout -b autosquash_expected &&
846 FAKE_LINES="1 fixup 3 fixup 4 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
848 git rebase -i HEAD~4 >expect
850 sed -e "1,13d" expect >expected &&
851 test_cmp expected actual
855 test_expect_success
'rebase --exec without -i shows error message' '
856 git reset --hard execute &&
857 test_must_fail git rebase --exec "git show HEAD" HEAD~2 2>actual &&
858 echo "The --exec option must be used with the --interactive option" >expected &&
859 test_i18ncmp expected actual
863 test_expect_success
'rebase -i --exec without <CMD>' '
864 git reset --hard execute &&
865 test_must_fail git rebase -i --exec 2>tmp &&
866 sed -e "1d" tmp >actual &&
867 test_must_fail git rebase -h >expected &&
868 test_cmp expected actual &&
872 test_expect_success
'rebase -i --root re-order and drop commits' '
874 FAKE_LINES="3 1 2 5" git rebase -i --root &&
875 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
876 test B = $(git cat-file commit HEAD^ | sed -ne \$p) &&
877 test A = $(git cat-file commit HEAD^^ | sed -ne \$p) &&
878 test C = $(git cat-file commit HEAD^^^ | sed -ne \$p) &&
879 test 0 = $(git cat-file commit HEAD^^^ | grep -c ^parent\ )
882 test_expect_success
'rebase -i --root retain root commit author and message' '
886 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
887 FAKE_LINES="2" git rebase -i --root &&
888 git cat-file commit HEAD | grep -q "^author Twerp Snog" &&
889 git cat-file commit HEAD | grep -q "^different author$"
892 test_expect_success
'rebase -i --root temporary sentinel commit' '
897 test_must_fail git rebase -i --root
899 git cat-file commit HEAD | grep "^tree 4b825dc642cb" &&
903 test_expect_success
'rebase -i --root fixup root commit' '
905 FAKE_LINES="1 fixup 2" git rebase -i --root &&
906 test A = $(git cat-file commit HEAD | sed -ne \$p) &&
907 test B = $(git show HEAD:file1) &&
908 test 0 = $(git cat-file commit HEAD | grep -c ^parent\ )
911 test_expect_success
'rebase --edit-todo does not works on non-interactive rebase' '
913 git checkout conflict-branch &&
914 test_must_fail git rebase --onto HEAD~2 HEAD~ &&
915 test_must_fail git rebase --edit-todo &&
919 test_expect_success
'rebase --edit-todo can be used to modify todo' '
921 git checkout no-conflict-branch^0 &&
922 FAKE_LINES="edit 1 2 3" git rebase -i HEAD~3 &&
923 FAKE_LINES="2 1" git rebase --edit-todo &&
924 git rebase --continue
925 test M = $(git cat-file commit HEAD^ | sed -ne \$p) &&
926 test L = $(git cat-file commit HEAD | sed -ne \$p)
929 test_expect_success
'rebase -i respects core.commentchar' '
932 test_config core.commentchar "\\" &&
933 write_script remove-all-but-first.sh <<-\EOF &&
934 sed -e "2,\$s/^/\\\\/" "$1" >"$1.tmp" &&
937 test_set_editor "$(pwd)/remove-all-but-first.sh" &&
939 test B = $(git cat-file commit HEAD^ | sed -ne \$p)
942 test_expect_success
'rebase -i, with <onto> and <upstream> specified as :/quuxery' '
943 test_when_finished "git branch -D torebase" &&
944 git checkout -b torebase branch1 &&
945 upstream=$(git rev-parse ":/J") &&
946 onto=$(git rev-parse ":/A") &&
947 git rebase --onto $onto $upstream &&
948 git reset --hard branch1 &&
949 git rebase --onto ":/A" ":/J" &&