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 --keep-empty' '
71 git checkout -b emptybranch master &&
72 git commit --allow-empty -m "empty" &&
73 git rebase --keep-empty -i HEAD~2 &&
74 git log --oneline >actual &&
75 test_line_count = 6 actual
78 test_expect_success
'rebase -i with the exec command' '
79 git checkout master &&
82 FAKE_LINES="1 exec_>touch-one
83 2 exec_>touch-two exec_false exec_>touch-three
84 3 4 exec_>\"touch-file__name_with_spaces\";_>touch-after-semicolon 5" &&
86 test_must_fail git rebase -i A
88 test_path_is_file touch-one &&
89 test_path_is_file touch-two &&
90 test_path_is_missing touch-three " (should have stopped before)" &&
91 test_cmp_rev C HEAD &&
92 git rebase --continue &&
93 test_path_is_file touch-three &&
94 test_path_is_file "touch-file name with spaces" &&
95 test_path_is_file touch-after-semicolon &&
96 test_cmp_rev master HEAD &&
100 test_expect_success
'rebase -i with the exec command runs from tree root' '
101 git checkout master &&
102 mkdir subdir && (cd subdir &&
104 FAKE_LINES="1 exec_>touch-subdir" \
107 test_path_is_file touch-subdir &&
111 test_expect_success
'rebase -i with the exec command checks tree cleanness' '
112 git checkout master &&
115 FAKE_LINES="exec_echo_foo_>file1 1" &&
117 test_must_fail git rebase -i HEAD^
119 test_cmp_rev master^ HEAD &&
121 git rebase --continue
124 test_expect_success
'rebase -i with exec of inexistent command' '
125 git checkout master &&
126 test_when_finished "git rebase --abort" &&
129 FAKE_LINES="exec_this-command-does-not-exist 1" &&
131 test_must_fail git rebase -i HEAD^ >actual 2>&1
133 ! grep "Maybe git-rebase is broken" actual
136 test_expect_success
'no changes are a nop' '
137 git checkout branch2 &&
140 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
141 test $(git rev-parse I) = $(git rev-parse HEAD)
144 test_expect_success
'test the [branch] option' '
145 git checkout -b dead-end &&
147 git commit -m "stop here" &&
149 git rebase -i F branch2 &&
150 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
151 test $(git rev-parse I) = $(git rev-parse branch2) &&
152 test $(git rev-parse I) = $(git rev-parse HEAD)
155 test_expect_success
'test --onto <branch>' '
156 git checkout -b test-onto branch2 &&
158 git rebase -i --onto branch1 F &&
159 test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" &&
160 test $(git rev-parse HEAD^) = $(git rev-parse branch1) &&
161 test $(git rev-parse I) = $(git rev-parse branch2)
164 test_expect_success
'rebase on top of a non-conflicting commit' '
165 git checkout branch1 &&
166 git tag original-branch1 &&
168 git rebase -i branch2 &&
169 test file6 = $(git diff --name-only original-branch1) &&
170 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
171 test $(git rev-parse I) = $(git rev-parse branch2) &&
172 test $(git rev-parse I) = $(git rev-parse HEAD~2)
175 test_expect_success
'reflog for the branch shows state before rebase' '
176 test $(git rev-parse branch1@{1}) = $(git rev-parse original-branch1)
179 test_expect_success
'exchange two commits' '
181 FAKE_LINES="2 1" git rebase -i HEAD~2 &&
182 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
183 test G = $(git cat-file commit HEAD | sed -ne \$p)
187 diff --git a/file1 b/file1
188 index f70f10e..fd79235 100644
204 test_expect_success
'stop on conflicting pick' '
205 git tag new-branch1 &&
207 test_must_fail git rebase -i master &&
208 test "$(git rev-parse HEAD~3)" = "$(git rev-parse master)" &&
209 test_cmp expect .git/rebase-merge/patch &&
210 test_cmp expect2 file1 &&
211 test "$(git diff --name-status |
212 sed -n -e "/^U/s/^U[^a-z]*//p")" = file1 &&
213 test 4 = $(grep -v "^#" < .git/rebase-merge/done | wc -l) &&
214 test 0 = $(grep -c "^[^#]" < .git/rebase-merge/git-rebase-todo)
217 test_expect_success
'abort' '
218 git rebase --abort &&
219 test $(git rev-parse new-branch1) = $(git rev-parse HEAD) &&
220 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
221 test_path_is_missing .git/rebase-merge
224 test_expect_success
'abort with error when new base cannot be checked out' '
225 git rm --cached file1 &&
226 git commit -m "remove file in base" &&
228 test_must_fail git rebase -i master > output 2>&1 &&
229 grep "The following untracked working tree files would be overwritten by checkout:" \
231 grep "file1" output &&
232 test_path_is_missing .git/rebase-merge &&
233 git reset --hard HEAD^
236 test_expect_success
'retain authorship' '
240 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
243 git rebase -i --onto master HEAD^ &&
244 git show HEAD | grep "^Author: Twerp Snog"
247 test_expect_success
'squash' '
248 git reset --hard twerp &&
251 GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 &&
252 echo "******************************" &&
254 FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \
255 git rebase -i --onto master HEAD~2 &&
256 test B = $(cat file7) &&
257 test $(git rev-parse HEAD^) = $(git rev-parse master)
260 test_expect_success
'retain authorship when squashing' '
261 git show HEAD | grep "^Author: Twerp Snog"
264 test_expect_success
'-p handles "no changes" gracefully' '
265 HEAD=$(git rev-parse HEAD) &&
267 git rebase -i -p HEAD^ &&
268 git update-index --refresh &&
269 git diff-files --quiet &&
270 git diff-index --quiet --cached HEAD -- &&
271 test $HEAD = $(git rev-parse HEAD)
274 test_expect_failure
'exchange two commits with -p' '
277 FAKE_LINES="2 1" git rebase -i -p HEAD~2 &&
278 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
279 test G = $(git cat-file commit HEAD | sed -ne \$p)
282 test_expect_success
'preserve merges with -p' '
283 git checkout -b to-be-preserved master^ &&
284 : > unrelated-file &&
285 git add unrelated-file &&
287 git commit -m "unrelated" &&
288 git checkout -b another-branch master &&
291 git commit -m J file1 &&
293 git merge to-be-preserved &&
296 git commit -m K file1 &&
299 git commit -m L1 file1 &&
300 git checkout HEAD^ &&
301 echo 1 > unrelated-file &&
303 git commit -m L2 unrelated-file &&
305 git merge another-branch &&
308 git commit -m M file1 &&
309 git checkout -b to-be-rebased &&
312 git rebase -i -p --onto branch1 master &&
313 git update-index --refresh &&
314 git diff-files --quiet &&
315 git diff-index --quiet --cached HEAD -- &&
316 test $(git rev-parse HEAD~6) = $(git rev-parse branch1) &&
317 test $(git rev-parse HEAD~4^2) = $(git rev-parse to-be-preserved) &&
318 test $(git rev-parse HEAD^^2^) = $(git rev-parse HEAD^^^) &&
319 test $(git show HEAD~5:file1) = B &&
320 test $(git show HEAD~3:file1) = C &&
321 test $(git show HEAD:file1) = E &&
322 test $(git show HEAD:unrelated-file) = 1
325 test_expect_success
'edit ancestor with -p' '
327 FAKE_LINES="1 2 edit 3 4" git rebase -i -p HEAD~3 &&
328 echo 2 > unrelated-file &&
330 git commit -m L2-modified --amend unrelated-file &&
331 git rebase --continue &&
332 git update-index --refresh &&
333 git diff-files --quiet &&
334 git diff-index --quiet --cached HEAD -- &&
335 test $(git show HEAD:unrelated-file) = 2
338 test_expect_success
'--continue tries to commit' '
341 test_must_fail git rebase -i --onto new-branch1 HEAD^ &&
342 echo resolved > file1 &&
344 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
345 test $(git rev-parse HEAD^) = $(git rev-parse new-branch1) &&
346 git show HEAD | grep chouette
349 test_expect_success
'verbose flag is heeded, even after --continue' '
350 git reset --hard master@{1} &&
353 test_must_fail git rebase -v -i --onto new-branch1 HEAD^ &&
354 echo resolved > file1 &&
356 git rebase --continue > output &&
357 grep "^ file1 | 2 +-$" output
360 test_expect_success
'multi-squash only fires up editor once' '
361 base=$(git rev-parse HEAD~4) &&
363 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 squash 2 squash 3 squash 4" \
364 EXPECT_HEADER_COUNT=4 \
365 git rebase -i $base &&
366 test $base = $(git rev-parse HEAD^) &&
367 test 1 = $(git show | grep ONCE | wc -l)
370 test_expect_success
'multi-fixup does not fire up editor' '
371 git checkout -b multi-fixup E &&
372 base=$(git rev-parse HEAD~4) &&
374 FAKE_COMMIT_AMEND="NEVER" FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \
375 git rebase -i $base &&
376 test $base = $(git rev-parse HEAD^) &&
377 test 0 = $(git show | grep NEVER | wc -l) &&
378 git checkout to-be-rebased &&
379 git branch -D multi-fixup
382 test_expect_success
'commit message used after conflict' '
383 git checkout -b conflict-fixup conflict-branch &&
384 base=$(git rev-parse HEAD~4) &&
387 FAKE_LINES="1 fixup 3 fixup 4" &&
389 test_must_fail git rebase -i $base
391 echo three > conflict &&
393 FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \
394 git rebase --continue &&
395 test $base = $(git rev-parse HEAD^) &&
396 test 1 = $(git show | grep ONCE | wc -l) &&
397 git checkout to-be-rebased &&
398 git branch -D conflict-fixup
401 test_expect_success
'commit message retained after conflict' '
402 git checkout -b conflict-squash conflict-branch &&
403 base=$(git rev-parse HEAD~4) &&
406 FAKE_LINES="1 fixup 3 squash 4" &&
408 test_must_fail git rebase -i $base
410 echo three > conflict &&
412 FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \
413 git rebase --continue &&
414 test $base = $(git rev-parse HEAD^) &&
415 test 2 = $(git show | grep TWICE | wc -l) &&
416 git checkout to-be-rebased &&
417 git branch -D conflict-squash
420 cat > expect-squash-fixup
<< EOF
428 test_expect_success
'squash and fixup generate correct log messages' '
429 git checkout -b squash-fixup E &&
430 base=$(git rev-parse HEAD~4) &&
432 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 fixup 2 squash 3 fixup 4" \
433 EXPECT_HEADER_COUNT=4 \
434 git rebase -i $base &&
435 git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup &&
436 test_cmp expect-squash-fixup actual-squash-fixup &&
437 git checkout to-be-rebased &&
438 git branch -D squash-fixup
441 test_expect_success
'squash ignores comments' '
442 git checkout -b skip-comments E &&
443 base=$(git rev-parse HEAD~4) &&
445 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \
446 EXPECT_HEADER_COUNT=4 \
447 git rebase -i $base &&
448 test $base = $(git rev-parse HEAD^) &&
449 test 1 = $(git show | grep ONCE | wc -l) &&
450 git checkout to-be-rebased &&
451 git branch -D skip-comments
454 test_expect_success
'squash ignores blank lines' '
455 git checkout -b skip-blank-lines E &&
456 base=$(git rev-parse HEAD~4) &&
458 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \
459 EXPECT_HEADER_COUNT=4 \
460 git rebase -i $base &&
461 test $base = $(git rev-parse HEAD^) &&
462 test 1 = $(git show | grep ONCE | wc -l) &&
463 git checkout to-be-rebased &&
464 git branch -D skip-blank-lines
467 test_expect_success
'squash works as expected' '
468 git checkout -b squash-works no-conflict-branch &&
469 one=$(git rev-parse HEAD~3) &&
471 FAKE_LINES="1 squash 3 2" EXPECT_HEADER_COUNT=2 \
472 git rebase -i HEAD~3 &&
473 test $one = $(git rev-parse HEAD~2)
476 test_expect_success
'interrupted squash works as expected' '
477 git checkout -b interrupted-squash conflict-branch &&
478 one=$(git rev-parse HEAD~3) &&
481 FAKE_LINES="1 squash 3 2" &&
483 test_must_fail git rebase -i HEAD~3
485 (echo one; echo two; echo four) > conflict &&
487 test_must_fail git rebase --continue &&
488 echo resolved > conflict &&
490 git rebase --continue &&
491 test $one = $(git rev-parse HEAD~2)
494 test_expect_success
'interrupted squash works as expected (case 2)' '
495 git checkout -b interrupted-squash2 conflict-branch &&
496 one=$(git rev-parse HEAD~3) &&
499 FAKE_LINES="3 squash 1 2" &&
501 test_must_fail git rebase -i HEAD~3
503 (echo one; echo four) > conflict &&
505 test_must_fail git rebase --continue &&
506 (echo one; echo two; echo four) > conflict &&
508 test_must_fail git rebase --continue &&
509 echo resolved > conflict &&
511 git rebase --continue &&
512 test $one = $(git rev-parse HEAD~2)
515 test_expect_success
'--continue tries to commit, even for "edit"' '
516 echo unrelated > file7 &&
519 git commit -m "unrelated change" &&
520 parent=$(git rev-parse HEAD^) &&
523 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
524 echo edited > file7 &&
526 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
527 test edited = $(git show HEAD:file7) &&
528 git show HEAD | grep chouette &&
529 test $parent = $(git rev-parse HEAD^)
532 test_expect_success
'aborted --continue does not squash commits after "edit"' '
533 old=$(git rev-parse HEAD) &&
536 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
537 echo "edited again" > file7 &&
540 FAKE_COMMIT_MESSAGE=" " &&
541 export FAKE_COMMIT_MESSAGE &&
542 test_must_fail git rebase --continue
544 test $old = $(git rev-parse HEAD) &&
548 test_expect_success
'auto-amend only edited commits after "edit"' '
551 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
552 echo "edited again" > file7 &&
554 FAKE_COMMIT_MESSAGE="edited file7 again" git commit &&
555 echo "and again" > file7 &&
559 FAKE_COMMIT_MESSAGE="and again" &&
560 export FAKE_COMMIT_MESSAGE &&
561 test_must_fail git rebase --continue
566 test_expect_success
'clean error after failed "exec"' '
568 test_when_finished "git rebase --abort || :" &&
571 FAKE_LINES="1 exec_false" &&
573 test_must_fail git rebase -i HEAD^
575 echo "edited again" > file7 &&
577 test_must_fail git rebase --continue 2>error &&
578 grep "You have staged changes in your working tree." error
581 test_expect_success
'rebase a detached HEAD' '
582 grandparent=$(git rev-parse HEAD~2) &&
583 git checkout $(git rev-parse HEAD) &&
586 FAKE_LINES="2 1" git rebase -i HEAD~2 &&
587 test $grandparent = $(git rev-parse HEAD~2)
590 test_expect_success
'rebase a commit violating pre-commit' '
592 mkdir -p .git/hooks &&
593 PRE_COMMIT=.git/hooks/pre-commit &&
594 echo "#!/bin/sh" > $PRE_COMMIT &&
595 echo "test -z \"\$(git diff --cached --check)\"" >> $PRE_COMMIT &&
596 chmod a+x $PRE_COMMIT &&
597 echo "monde! " >> file1 &&
599 test_must_fail git commit -m doesnt-verify file1 &&
600 git commit -m doesnt-verify --no-verify file1 &&
603 FAKE_LINES=2 git rebase -i HEAD~2
607 test_expect_success
'rebase with a file named HEAD in worktree' '
611 git checkout -b branch3 A &&
614 GIT_AUTHOR_NAME="Squashed Away" &&
615 export GIT_AUTHOR_NAME &&
618 git commit -m "Add head" &&
621 git commit -m "Add body"
625 FAKE_LINES="1 squash 2" git rebase -i to-be-rebased &&
626 test "$(git show -s --pretty=format:%an)" = "Squashed Away"
630 test_expect_success
'do "noop" when there is nothing to cherry-pick' '
632 git checkout -b branch4 HEAD &&
633 GIT_EDITOR=: git commit --amend \
634 --author="Somebody else <somebody@else.com>" &&
635 test $(git rev-parse branch3) != $(git rev-parse branch4) &&
637 git rebase -i branch3 &&
638 test $(git rev-parse branch3) = $(git rev-parse branch4)
642 test_expect_success
'submodule rebase setup' '
646 cd sub && git init && >elif &&
647 git add elif && git commit -m "submodule initial"
652 git commit -m "One" &&
655 git commit -a -m "Two" &&
657 cd sub && echo 3 >elif &&
658 git commit -a -m "submodule second"
662 git commit -a -m "Three changes submodule"
665 test_expect_success
'submodule rebase -i' '
667 FAKE_LINES="1 squash 2 3" git rebase -i A
670 test_expect_success
'submodule conflict setup' '
671 git tag submodule-base &&
672 git checkout HEAD^ &&
674 cd sub && git checkout HEAD^ && echo 4 >elif &&
675 git add elif && git commit -m "submodule conflict"
679 git commit -m "Conflict in submodule" &&
680 git tag submodule-topic
683 test_expect_success
'rebase -i continue with only submodule staged' '
685 test_must_fail git rebase -i submodule-base &&
687 git rebase --continue &&
688 test $(git rev-parse submodule-base) != $(git rev-parse HEAD)
691 test_expect_success
'rebase -i continue with unstaged submodule' '
692 git checkout submodule-topic &&
695 test_must_fail git rebase -i submodule-base &&
697 git rebase --continue &&
698 test $(git rev-parse submodule-base) = $(git rev-parse HEAD)
701 test_expect_success
'avoid unnecessary reset' '
702 git checkout master &&
704 test-chmtime =123456789 file3 &&
705 git update-index --refresh &&
706 HEAD=$(git rev-parse HEAD) &&
708 git rebase -i HEAD~4 &&
709 test $HEAD = $(git rev-parse HEAD) &&
710 MTIME=$(test-chmtime -v +0 file3 | sed 's
/[^
0-9].
*$
//') &&
711 test 123456789 = $MTIME
714 test_expect_success
'reword' '
715 git checkout -b reword-branch master &&
717 FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" git rebase -i A &&
718 git show HEAD | grep "E changed" &&
719 test $(git rev-parse master) != $(git rev-parse HEAD) &&
720 test $(git rev-parse master^) = $(git rev-parse HEAD^) &&
721 FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" git rebase -i A &&
722 git show HEAD^ | grep "D changed" &&
723 FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" git rebase -i A &&
724 git show HEAD~3 | grep "B changed" &&
725 FAKE_LINES="1 reword 2 3 4" FAKE_COMMIT_MESSAGE="C changed" git rebase -i A &&
726 git show HEAD~2 | grep "C changed"
729 test_expect_success
'rebase -i can copy notes' '
730 git config notes.rewrite.rebase true &&
731 git config notes.rewriteRef "refs/notes/*" &&
735 git notes add -m"a note" n3 &&
737 git rebase -i --onto n1 n2 &&
738 test "a note" = "$(git notes show HEAD)"
747 test_expect_success
'rebase -i can copy notes over a fixup' '
748 git reset --hard n3 &&
749 git notes add -m"an earlier note" n2 &&
751 GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 fixup 2" git rebase -i n1 &&
752 git notes show > output &&
753 test_cmp expect output
756 test_expect_success
'rebase while detaching HEAD' '
757 git symbolic-ref HEAD &&
758 grandparent=$(git rev-parse HEAD~2) &&
761 FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0 &&
762 test $grandparent = $(git rev-parse HEAD~2) &&
763 test_must_fail git symbolic-ref HEAD
766 test_tick
# Ensure that the rebased commits get a different timestamp.
767 test_expect_success
'always cherry-pick with --no-ff' '
768 git checkout no-ff-branch &&
769 git tag original-no-ff-branch &&
771 git rebase -i --no-ff A &&
775 test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) &&
776 git diff HEAD~$p original-no-ff-branch~$p > out &&
779 test $(git rev-parse HEAD~3) = $(git rev-parse original-no-ff-branch~3) &&
780 git diff HEAD~3 original-no-ff-branch~3 > out &&
784 test_expect_success
'set up commits with funny messages' '
785 git checkout -b funny A &&
788 git commit -a -m "end with slash\\" &&
791 git commit -a -m "something (\000) that looks like octal" &&
794 git commit -a -m "something (\n) that looks like a newline" &&
797 git commit -a -m "another commit"
800 test_expect_success
'rebase-i history with funny messages' '
801 git rev-list A..funny >expect &&
804 FAKE_LINES="1 2 3 4" git rebase -i A &&
805 git rev-list A.. >actual &&
806 test_cmp expect actual
810 test_expect_success
'prepare for rebase -i --exec' '
811 git checkout master &&
812 git checkout -b execute &&
813 test_commit one_exec main.txt one_exec &&
814 test_commit two_exec main.txt two_exec &&
815 test_commit three_exec main.txt three_exec
819 test_expect_success
'running "git rebase -i --exec git show HEAD"' '
821 git rebase -i --exec "git show HEAD" HEAD~2 >actual &&
823 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
825 git rebase -i HEAD~2 >expect
827 sed -e "1,9d" expect >expected &&
828 test_cmp expected actual
832 test_expect_success
'running "git rebase --exec git show HEAD -i"' '
833 git reset --hard execute &&
835 git rebase --exec "git show HEAD" -i HEAD~2 >actual &&
837 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
839 git rebase -i HEAD~2 >expect
841 sed -e "1,9d" expect >expected &&
842 test_cmp expected actual
846 test_expect_success
'running "git rebase -ix git show HEAD"' '
847 git reset --hard execute &&
849 git rebase -ix "git show HEAD" HEAD~2 >actual &&
851 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
853 git rebase -i HEAD~2 >expect
855 sed -e "1,9d" expect >expected &&
856 test_cmp expected actual
860 test_expect_success
'rebase -ix with several <CMD>' '
861 git reset --hard execute &&
863 git rebase -ix "git show HEAD; pwd" HEAD~2 >actual &&
865 FAKE_LINES="1 exec_git_show_HEAD;_pwd 2 exec_git_show_HEAD;_pwd" &&
867 git rebase -i HEAD~2 >expect
869 sed -e "1,9d" expect >expected &&
870 test_cmp expected actual
874 test_expect_success
'rebase -ix with several instances of --exec' '
875 git reset --hard execute &&
877 git rebase -i --exec "git show HEAD" --exec "pwd" HEAD~2 >actual &&
879 FAKE_LINES="1 exec_git_show_HEAD exec_pwd 2
880 exec_git_show_HEAD exec_pwd" &&
882 git rebase -i HEAD~2 >expect
884 sed -e "1,11d" expect >expected &&
885 test_cmp expected actual
889 test_expect_success
'rebase -ix with --autosquash' '
890 git reset --hard execute &&
891 git checkout -b autosquash &&
892 echo second >second.txt &&
893 git add second.txt &&
894 git commit -m "fixup! two_exec" &&
897 git commit -m "fixup! two_exec" &&
900 git checkout -b autosquash_actual &&
901 git rebase -i --exec "git show HEAD" --autosquash HEAD~4 >actual
903 git checkout autosquash &&
905 git checkout -b autosquash_expected &&
906 FAKE_LINES="1 fixup 3 fixup 4 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
908 git rebase -i HEAD~4 >expect
910 sed -e "1,13d" expect >expected &&
911 test_cmp expected actual
915 test_expect_success
'rebase --exec without -i shows error message' '
916 git reset --hard execute &&
918 test_must_fail git rebase --exec "git show HEAD" HEAD~2 2>actual &&
919 echo "The --exec option must be used with the --interactive option" >expected &&
920 test_i18ncmp expected actual
924 test_expect_success
'rebase -i --exec without <CMD>' '
925 git reset --hard execute &&
927 test_must_fail git rebase -i --exec 2>tmp &&
928 sed -e "1d" tmp >actual &&
929 test_must_fail git rebase -h >expected &&
930 test_cmp expected actual &&
934 test_expect_success
'rebase -i --root re-order and drop commits' '
937 FAKE_LINES="3 1 2 5" git rebase -i --root &&
938 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
939 test B = $(git cat-file commit HEAD^ | sed -ne \$p) &&
940 test A = $(git cat-file commit HEAD^^ | sed -ne \$p) &&
941 test C = $(git cat-file commit HEAD^^^ | sed -ne \$p) &&
942 test 0 = $(git cat-file commit HEAD^^^ | grep -c ^parent\ )
945 test_expect_success
'rebase -i --root retain root commit author and message' '
949 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
951 FAKE_LINES="2" git rebase -i --root &&
952 git cat-file commit HEAD | grep -q "^author Twerp Snog" &&
953 git cat-file commit HEAD | grep -q "^different author$"
956 test_expect_success
'rebase -i --root temporary sentinel commit' '
962 test_must_fail git rebase -i --root
964 git cat-file commit HEAD | grep "^tree 4b825dc642cb" &&
968 test_expect_success
'rebase -i --root fixup root commit' '
971 FAKE_LINES="1 fixup 2" git rebase -i --root &&
972 test A = $(git cat-file commit HEAD | sed -ne \$p) &&
973 test B = $(git show HEAD:file1) &&
974 test 0 = $(git cat-file commit HEAD | grep -c ^parent\ )
977 test_expect_success
'rebase --edit-todo does not works on non-interactive rebase' '
979 git checkout conflict-branch &&
981 test_must_fail git rebase --onto HEAD~2 HEAD~ &&
982 test_must_fail git rebase --edit-todo &&
986 test_expect_success
'rebase --edit-todo can be used to modify todo' '
988 git checkout no-conflict-branch^0 &&
990 FAKE_LINES="edit 1 2 3" git rebase -i HEAD~3 &&
991 FAKE_LINES="2 1" git rebase --edit-todo &&
992 git rebase --continue
993 test M = $(git cat-file commit HEAD^ | sed -ne \$p) &&
994 test L = $(git cat-file commit HEAD | sed -ne \$p)
997 test_expect_success
'rebase -i produces readable reflog' '
999 git branch -f branch-reflog-test H &&
1001 git rebase -i --onto I F branch-reflog-test &&
1002 cat >expect <<-\EOF &&
1003 rebase -i (start): checkout I
1006 rebase -i (finish): returning to refs/heads/branch-reflog-test
1008 tail -n 4 .git/logs/HEAD |
1009 sed -e "s/.* //" >actual &&
1010 test_cmp expect actual
1013 test_expect_success
'rebase -i respects core.commentchar' '
1016 test_config core.commentchar "\\" &&
1017 write_script remove-all-but-first.sh <<-\EOF &&
1018 sed -e "2,\$s/^/\\\\/" "$1" >"$1.tmp" &&
1021 test_set_editor "$(pwd)/remove-all-but-first.sh" &&
1023 test B = $(git cat-file commit HEAD^ | sed -ne \$p)
1026 test_expect_success
'rebase -i, with <onto> and <upstream> specified as :/quuxery' '
1027 test_when_finished "git branch -D torebase" &&
1028 git checkout -b torebase branch1 &&
1029 upstream=$(git rev-parse ":/J") &&
1030 onto=$(git rev-parse ":/A") &&
1031 git rebase --onto $onto $upstream &&
1032 git reset --hard branch1 &&
1033 git rebase --onto ":/A" ":/J" &&
1034 git checkout branch1
1037 test_expect_success
'rebase -i with --strategy and -X' '
1038 git checkout -b conflict-merge-use-theirs conflict-branch &&
1039 git reset --hard HEAD^ &&
1040 echo five >conflict &&
1042 git commit -a -m "one file conflict" &&
1043 EDITOR=true git rebase -i --strategy=recursive -Xours conflict-branch &&
1044 test $(git show conflict-branch:conflict) = $(cat conflict) &&
1045 test $(cat file1) = Z
1048 test_expect_success
'rebase -i error on commits with \ in message' '
1049 current_head=$(git rev-parse HEAD)
1050 test_when_finished "git rebase --abort; git reset --hard $current_head; rm -f error" &&
1051 test_commit TO-REMOVE will-conflict old-content &&
1052 test_commit "\temp" will-conflict new-content dummy &&
1056 test_must_fail git rebase -i HEAD^ --onto HEAD^^ 2>error
1058 test_expect_code 1 grep " emp" error
1061 test_expect_success
'short SHA-1 setup' '
1062 test_when_finished "git checkout master" &&
1063 git checkout --orphan collide &&
1067 test_commit collide1 collide &&
1068 test_commit --notick collide2 collide &&
1069 test_commit --notick collide3 collide
1073 test_expect_success
'short SHA-1 collide' '
1074 test_when_finished "reset_rebase && git checkout master" &&
1075 git checkout collide &&
1080 FAKE_COMMIT_MESSAGE="collide2 ac4f2ee" \
1081 FAKE_LINES="reword 1 2" git rebase -i HEAD~2