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 run 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. Unsetting 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 exec allows git commands in subdirs' '
112 test_when_finished "rm -rf subdir" &&
113 test_when_finished "git rebase --abort ||:" &&
114 git checkout master &&
115 mkdir subdir && (cd subdir &&
117 FAKE_LINES="1 exec_cd_subdir_&&_git_rev-parse_--is-inside-work-tree" \
122 test_expect_success
'rebase -i sets work tree properly' '
123 test_when_finished "rm -rf subdir" &&
124 test_when_finished "test_might_fail git rebase --abort" &&
126 git rebase -x "(cd subdir && git rev-parse --show-toplevel)" HEAD^ \
128 ! grep "/subdir$" actual
131 test_expect_success
'rebase -i with the exec command checks tree cleanness' '
132 git checkout master &&
134 test_must_fail env FAKE_LINES="exec_echo_foo_>file1 1" git rebase -i HEAD^ &&
135 test_cmp_rev master^ HEAD &&
137 git rebase --continue
140 test_expect_success
'rebase -i with exec of inexistent command' '
141 git checkout master &&
142 test_when_finished "git rebase --abort" &&
144 test_must_fail env FAKE_LINES="exec_this-command-does-not-exist 1" \
145 git rebase -i HEAD^ >actual 2>&1 &&
146 ! grep "Maybe git-rebase is broken" actual
149 test_expect_success
'no changes are a nop' '
150 git checkout branch2 &&
153 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
154 test $(git rev-parse I) = $(git rev-parse HEAD)
157 test_expect_success
'test the [branch] option' '
158 git checkout -b dead-end &&
160 git commit -m "stop here" &&
162 git rebase -i F branch2 &&
163 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
164 test $(git rev-parse I) = $(git rev-parse branch2) &&
165 test $(git rev-parse I) = $(git rev-parse HEAD)
168 test_expect_success
'test --onto <branch>' '
169 git checkout -b test-onto branch2 &&
171 git rebase -i --onto branch1 F &&
172 test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" &&
173 test $(git rev-parse HEAD^) = $(git rev-parse branch1) &&
174 test $(git rev-parse I) = $(git rev-parse branch2)
177 test_expect_success
'rebase on top of a non-conflicting commit' '
178 git checkout branch1 &&
179 git tag original-branch1 &&
181 git rebase -i branch2 &&
182 test file6 = $(git diff --name-only original-branch1) &&
183 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
184 test $(git rev-parse I) = $(git rev-parse branch2) &&
185 test $(git rev-parse I) = $(git rev-parse HEAD~2)
188 test_expect_success
'reflog for the branch shows state before rebase' '
189 test $(git rev-parse branch1@{1}) = $(git rev-parse original-branch1)
192 test_expect_success
'reflog for the branch shows correct finish message' '
193 printf "rebase -i (finish): refs/heads/branch1 onto %s\n" \
194 "$(git rev-parse branch2)" >expected &&
195 git log -g --pretty=%gs -1 refs/heads/branch1 >actual &&
196 test_cmp expected actual
199 test_expect_success
'exchange two commits' '
201 FAKE_LINES="2 1" git rebase -i HEAD~2 &&
202 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
203 test G = $(git cat-file commit HEAD | sed -ne \$p)
207 diff --git a/file1 b/file1
208 index f70f10e..fd79235 100644
224 test_expect_success
'stop on conflicting pick' '
225 git tag new-branch1 &&
227 test_must_fail git rebase -i master &&
228 test "$(git rev-parse HEAD~3)" = "$(git rev-parse master)" &&
229 test_cmp expect .git/rebase-merge/patch &&
230 test_cmp expect2 file1 &&
231 test "$(git diff --name-status |
232 sed -n -e "/^U/s/^U[^a-z]*//p")" = file1 &&
233 test 4 = $(grep -v "^#" < .git/rebase-merge/done | wc -l) &&
234 test 0 = $(grep -c "^[^#]" < .git/rebase-merge/git-rebase-todo)
237 test_expect_success
'abort' '
238 git rebase --abort &&
239 test $(git rev-parse new-branch1) = $(git rev-parse HEAD) &&
240 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
241 test_path_is_missing .git/rebase-merge
244 test_expect_success
'abort with error when new base cannot be checked out' '
245 git rm --cached file1 &&
246 git commit -m "remove file in base" &&
248 test_must_fail git rebase -i master > output 2>&1 &&
249 test_i18ngrep "The following untracked working tree files would be overwritten by checkout:" \
251 test_i18ngrep "file1" output &&
252 test_path_is_missing .git/rebase-merge &&
253 git reset --hard HEAD^
256 test_expect_success
'retain authorship' '
260 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
263 git rebase -i --onto master HEAD^ &&
264 git show HEAD | grep "^Author: Twerp Snog"
267 test_expect_success
'retain authorship w/ conflicts' '
268 git reset --hard twerp &&
269 test_commit a conflict a conflict-a &&
270 git reset --hard twerp &&
271 GIT_AUTHOR_NAME=AttributeMe \
272 test_commit b conflict b conflict-b &&
274 test_must_fail git rebase -i conflict-a &&
275 echo resolved >conflict &&
277 git rebase --continue &&
278 test $(git rev-parse conflict-a^0) = $(git rev-parse HEAD^) &&
283 test_expect_success
'squash' '
284 git reset --hard twerp &&
287 GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 &&
288 echo "******************************" &&
290 FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \
291 git rebase -i --onto master HEAD~2 &&
292 test B = $(cat file7) &&
293 test $(git rev-parse HEAD^) = $(git rev-parse master)
296 test_expect_success
'retain authorship when squashing' '
297 git show HEAD | grep "^Author: Twerp Snog"
300 test_expect_success
'-p handles "no changes" gracefully' '
301 HEAD=$(git rev-parse HEAD) &&
303 git rebase -i -p HEAD^ &&
304 git update-index --refresh &&
305 git diff-files --quiet &&
306 git diff-index --quiet --cached HEAD -- &&
307 test $HEAD = $(git rev-parse HEAD)
310 test_expect_failure
'exchange two commits with -p' '
313 FAKE_LINES="2 1" git rebase -i -p HEAD~2 &&
314 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
315 test G = $(git cat-file commit HEAD | sed -ne \$p)
318 test_expect_success
'preserve merges with -p' '
319 git checkout -b to-be-preserved master^ &&
320 : > unrelated-file &&
321 git add unrelated-file &&
323 git commit -m "unrelated" &&
324 git checkout -b another-branch master &&
327 git commit -m J file1 &&
329 git merge to-be-preserved &&
332 git commit -m K file1 &&
335 git commit -m L1 file1 &&
336 git checkout HEAD^ &&
337 echo 1 > unrelated-file &&
339 git commit -m L2 unrelated-file &&
341 git merge another-branch &&
344 git commit -m M file1 &&
345 git checkout -b to-be-rebased &&
348 git rebase -i -p --onto branch1 master &&
349 git update-index --refresh &&
350 git diff-files --quiet &&
351 git diff-index --quiet --cached HEAD -- &&
352 test $(git rev-parse HEAD~6) = $(git rev-parse branch1) &&
353 test $(git rev-parse HEAD~4^2) = $(git rev-parse to-be-preserved) &&
354 test $(git rev-parse HEAD^^2^) = $(git rev-parse HEAD^^^) &&
355 test $(git show HEAD~5:file1) = B &&
356 test $(git show HEAD~3:file1) = C &&
357 test $(git show HEAD:file1) = E &&
358 test $(git show HEAD:unrelated-file) = 1
361 test_expect_success
'edit ancestor with -p' '
363 FAKE_LINES="1 2 edit 3 4" git rebase -i -p HEAD~3 &&
364 echo 2 > unrelated-file &&
366 git commit -m L2-modified --amend unrelated-file &&
367 git rebase --continue &&
368 git update-index --refresh &&
369 git diff-files --quiet &&
370 git diff-index --quiet --cached HEAD -- &&
371 test $(git show HEAD:unrelated-file) = 2
374 test_expect_success
'--continue tries to commit' '
377 test_must_fail git rebase -i --onto new-branch1 HEAD^ &&
378 echo resolved > file1 &&
380 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
381 test $(git rev-parse HEAD^) = $(git rev-parse new-branch1) &&
382 git show HEAD | grep chouette
385 test_expect_success
'verbose flag is heeded, even after --continue' '
386 git reset --hard master@{1} &&
389 test_must_fail git rebase -v -i --onto new-branch1 HEAD^ &&
390 echo resolved > file1 &&
392 git rebase --continue > output &&
393 grep "^ file1 | 2 +-$" output
396 test_expect_success C_LOCALE_OUTPUT
'multi-squash only fires up editor once' '
397 base=$(git rev-parse HEAD~4) &&
399 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 squash 2 squash 3 squash 4" \
400 EXPECT_HEADER_COUNT=4 \
401 git rebase -i $base &&
402 test $base = $(git rev-parse HEAD^) &&
403 test 1 = $(git show | grep ONCE | wc -l)
406 test_expect_success C_LOCALE_OUTPUT
'multi-fixup does not fire up editor' '
407 git checkout -b multi-fixup E &&
408 base=$(git rev-parse HEAD~4) &&
410 FAKE_COMMIT_AMEND="NEVER" FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \
411 git rebase -i $base &&
412 test $base = $(git rev-parse HEAD^) &&
413 test 0 = $(git show | grep NEVER | wc -l) &&
414 git checkout to-be-rebased &&
415 git branch -D multi-fixup
418 test_expect_success
'commit message used after conflict' '
419 git checkout -b conflict-fixup conflict-branch &&
420 base=$(git rev-parse HEAD~4) &&
422 test_must_fail env FAKE_LINES="1 fixup 3 fixup 4" git rebase -i $base &&
423 echo three > conflict &&
425 FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \
426 git rebase --continue &&
427 test $base = $(git rev-parse HEAD^) &&
428 test 1 = $(git show | grep ONCE | wc -l) &&
429 git checkout to-be-rebased &&
430 git branch -D conflict-fixup
433 test_expect_success
'commit message retained after conflict' '
434 git checkout -b conflict-squash conflict-branch &&
435 base=$(git rev-parse HEAD~4) &&
437 test_must_fail env FAKE_LINES="1 fixup 3 squash 4" git rebase -i $base &&
438 echo three > conflict &&
440 FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \
441 git rebase --continue &&
442 test $base = $(git rev-parse HEAD^) &&
443 test 2 = $(git show | grep TWICE | wc -l) &&
444 git checkout to-be-rebased &&
445 git branch -D conflict-squash
448 cat > expect-squash-fixup
<< EOF
456 test_expect_success C_LOCALE_OUTPUT
'squash and fixup generate correct log messages' '
457 git checkout -b squash-fixup E &&
458 base=$(git rev-parse HEAD~4) &&
460 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 fixup 2 squash 3 fixup 4" \
461 EXPECT_HEADER_COUNT=4 \
462 git rebase -i $base &&
463 git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup &&
464 test_cmp expect-squash-fixup actual-squash-fixup &&
465 git checkout to-be-rebased &&
466 git branch -D squash-fixup
469 test_expect_success C_LOCALE_OUTPUT
'squash ignores comments' '
470 git checkout -b skip-comments E &&
471 base=$(git rev-parse HEAD~4) &&
473 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \
474 EXPECT_HEADER_COUNT=4 \
475 git rebase -i $base &&
476 test $base = $(git rev-parse HEAD^) &&
477 test 1 = $(git show | grep ONCE | wc -l) &&
478 git checkout to-be-rebased &&
479 git branch -D skip-comments
482 test_expect_success C_LOCALE_OUTPUT
'squash ignores blank lines' '
483 git checkout -b skip-blank-lines E &&
484 base=$(git rev-parse HEAD~4) &&
486 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \
487 EXPECT_HEADER_COUNT=4 \
488 git rebase -i $base &&
489 test $base = $(git rev-parse HEAD^) &&
490 test 1 = $(git show | grep ONCE | wc -l) &&
491 git checkout to-be-rebased &&
492 git branch -D skip-blank-lines
495 test_expect_success
'squash works as expected' '
496 git checkout -b squash-works no-conflict-branch &&
497 one=$(git rev-parse HEAD~3) &&
499 FAKE_LINES="1 squash 3 2" EXPECT_HEADER_COUNT=2 \
500 git rebase -i HEAD~3 &&
501 test $one = $(git rev-parse HEAD~2)
504 test_expect_success
'interrupted squash works as expected' '
505 git checkout -b interrupted-squash conflict-branch &&
506 one=$(git rev-parse HEAD~3) &&
508 test_must_fail env FAKE_LINES="1 squash 3 2" git rebase -i HEAD~3 &&
509 (echo one; echo two; echo four) > conflict &&
511 test_must_fail git rebase --continue &&
512 echo resolved > conflict &&
514 git rebase --continue &&
515 test $one = $(git rev-parse HEAD~2)
518 test_expect_success
'interrupted squash works as expected (case 2)' '
519 git checkout -b interrupted-squash2 conflict-branch &&
520 one=$(git rev-parse HEAD~3) &&
522 test_must_fail env FAKE_LINES="3 squash 1 2" git rebase -i HEAD~3 &&
523 (echo one; echo four) > conflict &&
525 test_must_fail git rebase --continue &&
526 (echo one; echo two; echo four) > conflict &&
528 test_must_fail git rebase --continue &&
529 echo resolved > conflict &&
531 git rebase --continue &&
532 test $one = $(git rev-parse HEAD~2)
535 test_expect_success
'--continue tries to commit, even for "edit"' '
536 echo unrelated > file7 &&
539 git commit -m "unrelated change" &&
540 parent=$(git rev-parse HEAD^) &&
543 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
544 echo edited > file7 &&
546 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
547 test edited = $(git show HEAD:file7) &&
548 git show HEAD | grep chouette &&
549 test $parent = $(git rev-parse HEAD^)
552 test_expect_success
'aborted --continue does not squash commits after "edit"' '
553 old=$(git rev-parse HEAD) &&
556 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
557 echo "edited again" > file7 &&
559 test_must_fail env FAKE_COMMIT_MESSAGE=" " git rebase --continue &&
560 test $old = $(git rev-parse HEAD) &&
564 test_expect_success
'auto-amend only edited commits after "edit"' '
567 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
568 echo "edited again" > file7 &&
570 FAKE_COMMIT_MESSAGE="edited file7 again" git commit &&
571 echo "and again" > file7 &&
574 test_must_fail env FAKE_COMMIT_MESSAGE="and again" git rebase --continue &&
578 test_expect_success
'clean error after failed "exec"' '
580 test_when_finished "git rebase --abort || :" &&
582 test_must_fail env FAKE_LINES="1 exec_false" git rebase -i HEAD^ &&
583 echo "edited again" > file7 &&
585 test_must_fail git rebase --continue 2>error &&
586 test_i18ngrep "you have staged changes in your working tree" error
589 test_expect_success
'rebase a detached HEAD' '
590 grandparent=$(git rev-parse HEAD~2) &&
591 git checkout $(git rev-parse HEAD) &&
594 FAKE_LINES="2 1" git rebase -i HEAD~2 &&
595 test $grandparent = $(git rev-parse HEAD~2)
598 test_expect_success
'rebase a commit violating pre-commit' '
600 mkdir -p .git/hooks &&
601 write_script .git/hooks/pre-commit <<-\EOF &&
602 test -z "$(git diff --cached --check)"
604 echo "monde! " >> file1 &&
606 test_must_fail git commit -m doesnt-verify file1 &&
607 git commit -m doesnt-verify --no-verify file1 &&
610 FAKE_LINES=2 git rebase -i HEAD~2
614 test_expect_success
'rebase with a file named HEAD in worktree' '
618 git checkout -b branch3 A &&
621 GIT_AUTHOR_NAME="Squashed Away" &&
622 export GIT_AUTHOR_NAME &&
625 git commit -m "Add head" &&
628 git commit -m "Add body"
632 FAKE_LINES="1 squash 2" git rebase -i to-be-rebased &&
633 test "$(git show -s --pretty=format:%an)" = "Squashed Away"
637 test_expect_success
'do "noop" when there is nothing to cherry-pick' '
639 git checkout -b branch4 HEAD &&
640 GIT_EDITOR=: git commit --amend \
641 --author="Somebody else <somebody@else.com>" &&
642 test $(git rev-parse branch3) != $(git rev-parse branch4) &&
644 git rebase -i branch3 &&
645 test $(git rev-parse branch3) = $(git rev-parse branch4)
649 test_expect_success
'submodule rebase setup' '
653 cd sub && git init && >elif &&
654 git add elif && git commit -m "submodule initial"
659 git commit -m "One" &&
662 git commit -a -m "Two" &&
664 cd sub && echo 3 >elif &&
665 git commit -a -m "submodule second"
669 git commit -a -m "Three changes submodule"
672 test_expect_success
'submodule rebase -i' '
674 FAKE_LINES="1 squash 2 3" git rebase -i A
677 test_expect_success
'submodule conflict setup' '
678 git tag submodule-base &&
679 git checkout HEAD^ &&
681 cd sub && git checkout HEAD^ && echo 4 >elif &&
682 git add elif && git commit -m "submodule conflict"
686 git commit -m "Conflict in submodule" &&
687 git tag submodule-topic
690 test_expect_success
'rebase -i continue with only submodule staged' '
692 test_must_fail git rebase -i submodule-base &&
694 git rebase --continue &&
695 test $(git rev-parse submodule-base) != $(git rev-parse HEAD)
698 test_expect_success
'rebase -i continue with unstaged submodule' '
699 git checkout submodule-topic &&
702 test_must_fail git rebase -i submodule-base &&
704 git rebase --continue &&
705 test $(git rev-parse submodule-base) = $(git rev-parse HEAD)
708 test_expect_success
'avoid unnecessary reset' '
709 git checkout master &&
711 test-chmtime =123456789 file3 &&
712 git update-index --refresh &&
713 HEAD=$(git rev-parse HEAD) &&
715 git rebase -i HEAD~4 &&
716 test $HEAD = $(git rev-parse HEAD) &&
717 MTIME=$(test-chmtime -v +0 file3 | sed 's
/[^
0-9].
*$
//') &&
718 test 123456789 = $MTIME
721 test_expect_success
'reword' '
722 git checkout -b reword-branch master &&
724 FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" git rebase -i A &&
725 git show HEAD | grep "E changed" &&
726 test $(git rev-parse master) != $(git rev-parse HEAD) &&
727 test $(git rev-parse master^) = $(git rev-parse HEAD^) &&
728 FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" git rebase -i A &&
729 git show HEAD^ | grep "D changed" &&
730 FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" git rebase -i A &&
731 git show HEAD~3 | grep "B changed" &&
732 FAKE_LINES="1 reword 2 3 4" FAKE_COMMIT_MESSAGE="C changed" git rebase -i A &&
733 git show HEAD~2 | grep "C changed"
736 test_expect_success
'rebase -i can copy notes' '
737 git config notes.rewrite.rebase true &&
738 git config notes.rewriteRef "refs/notes/*" &&
742 git notes add -m"a note" n3 &&
744 git rebase -i --onto n1 n2 &&
745 test "a note" = "$(git notes show HEAD)"
754 test_expect_success
'rebase -i can copy notes over a fixup' '
755 git reset --hard n3 &&
756 git notes add -m"an earlier note" n2 &&
758 GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 fixup 2" git rebase -i n1 &&
759 git notes show > output &&
760 test_cmp expect output
763 test_expect_success
'rebase while detaching HEAD' '
764 git symbolic-ref HEAD &&
765 grandparent=$(git rev-parse HEAD~2) &&
768 FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0 &&
769 test $grandparent = $(git rev-parse HEAD~2) &&
770 test_must_fail git symbolic-ref HEAD
773 test_tick
# Ensure that the rebased commits get a different timestamp.
774 test_expect_success
'always cherry-pick with --no-ff' '
775 git checkout no-ff-branch &&
776 git tag original-no-ff-branch &&
778 git rebase -i --no-ff A &&
782 test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) &&
783 git diff HEAD~$p original-no-ff-branch~$p > out &&
786 test $(git rev-parse HEAD~3) = $(git rev-parse original-no-ff-branch~3) &&
787 git diff HEAD~3 original-no-ff-branch~3 > out &&
791 test_expect_success
'set up commits with funny messages' '
792 git checkout -b funny A &&
795 git commit -a -m "end with slash\\" &&
798 git commit -a -m "something (\000) that looks like octal" &&
801 git commit -a -m "something (\n) that looks like a newline" &&
804 git commit -a -m "another commit"
807 test_expect_success
'rebase-i history with funny messages' '
808 git rev-list A..funny >expect &&
811 FAKE_LINES="1 2 3 4" git rebase -i A &&
812 git rev-list A.. >actual &&
813 test_cmp expect actual
816 test_expect_success
'prepare for rebase -i --exec' '
817 git checkout master &&
818 git checkout -b execute &&
819 test_commit one_exec main.txt one_exec &&
820 test_commit two_exec main.txt two_exec &&
821 test_commit three_exec main.txt three_exec
824 test_expect_success
'running "git rebase -i --exec git show HEAD"' '
826 git rebase -i --exec "git show HEAD" HEAD~2 >actual &&
828 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
830 git rebase -i HEAD~2 >expect
832 sed -e "1,9d" expect >expected &&
833 test_cmp expected actual
836 test_expect_success
'running "git rebase --exec git show HEAD -i"' '
837 git reset --hard execute &&
839 git rebase --exec "git show HEAD" -i HEAD~2 >actual &&
841 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
843 git rebase -i HEAD~2 >expect
845 sed -e "1,9d" expect >expected &&
846 test_cmp expected actual
849 test_expect_success
'running "git rebase -ix git show HEAD"' '
850 git reset --hard execute &&
852 git rebase -ix "git show HEAD" HEAD~2 >actual &&
854 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
856 git rebase -i HEAD~2 >expect
858 sed -e "1,9d" expect >expected &&
859 test_cmp expected actual
863 test_expect_success
'rebase -ix with several <CMD>' '
864 git reset --hard execute &&
866 git rebase -ix "git show HEAD; pwd" HEAD~2 >actual &&
868 FAKE_LINES="1 exec_git_show_HEAD;_pwd 2 exec_git_show_HEAD;_pwd" &&
870 git rebase -i HEAD~2 >expect
872 sed -e "1,9d" expect >expected &&
873 test_cmp expected actual
876 test_expect_success
'rebase -ix with several instances of --exec' '
877 git reset --hard execute &&
879 git rebase -i --exec "git show HEAD" --exec "pwd" HEAD~2 >actual &&
881 FAKE_LINES="1 exec_git_show_HEAD exec_pwd 2
882 exec_git_show_HEAD exec_pwd" &&
884 git rebase -i HEAD~2 >expect
886 sed -e "1,11d" expect >expected &&
887 test_cmp expected actual
890 test_expect_success C_LOCALE_OUTPUT
'rebase -ix with --autosquash' '
891 git reset --hard execute &&
892 git checkout -b autosquash &&
893 echo second >second.txt &&
894 git add second.txt &&
895 git commit -m "fixup! two_exec" &&
898 git commit -m "fixup! two_exec" &&
901 git checkout -b autosquash_actual &&
902 git rebase -i --exec "git show HEAD" --autosquash HEAD~4 >actual
904 git checkout autosquash &&
906 git checkout -b autosquash_expected &&
907 FAKE_LINES="1 fixup 3 fixup 4 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
909 git rebase -i HEAD~4 >expect
911 sed -e "1,13d" expect >expected &&
912 test_cmp expected actual
915 test_expect_success
'rebase --exec works without -i ' '
916 git reset --hard execute &&
917 rm -rf exec_output &&
918 EDITOR="echo >invoked_editor" git rebase --exec "echo a line >>exec_output" HEAD~2 2>actual &&
919 test_i18ngrep "Successfully rebased and updated" actual &&
920 test_line_count = 2 exec_output &&
921 test_path_is_missing invoked_editor
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' '
959 test_must_fail env FAKE_LINES="2" git rebase -i --root &&
960 git cat-file commit HEAD | grep "^tree 4b825dc642cb" &&
964 test_expect_success
'rebase -i --root fixup root commit' '
967 FAKE_LINES="1 fixup 2" git rebase -i --root &&
968 test A = $(git cat-file commit HEAD | sed -ne \$p) &&
969 test B = $(git show HEAD:file1) &&
970 test 0 = $(git cat-file commit HEAD | grep -c ^parent\ )
973 test_expect_success C_LOCALE_OUTPUT
'rebase --edit-todo does not work on non-interactive rebase' '
975 git checkout conflict-branch &&
977 test_must_fail git rebase --onto HEAD~2 HEAD~ &&
978 test_must_fail git rebase --edit-todo &&
982 test_expect_success
'rebase --edit-todo can be used to modify todo' '
984 git checkout no-conflict-branch^0 &&
986 FAKE_LINES="edit 1 2 3" git rebase -i HEAD~3 &&
987 FAKE_LINES="2 1" git rebase --edit-todo &&
988 git rebase --continue &&
989 test M = $(git cat-file commit HEAD^ | sed -ne \$p) &&
990 test L = $(git cat-file commit HEAD | sed -ne \$p)
993 test_expect_success
'rebase -i produces readable reflog' '
995 git branch -f branch-reflog-test H &&
997 git rebase -i --onto I F branch-reflog-test &&
998 cat >expect <<-\EOF &&
999 rebase -i (finish): returning to refs/heads/branch-reflog-test
1002 rebase -i (start): checkout I
1004 git reflog -n4 HEAD |
1005 sed "s/[^:]*: //" >actual &&
1006 test_cmp expect actual
1009 test_expect_success
'rebase -i respects core.commentchar' '
1012 test_config core.commentchar "\\" &&
1013 write_script remove-all-but-first.sh <<-\EOF &&
1014 sed -e "2,\$s/^/\\\\/" "$1" >"$1.tmp" &&
1017 test_set_editor "$(pwd)/remove-all-but-first.sh" &&
1019 test B = $(git cat-file commit HEAD^ | sed -ne \$p)
1022 test_expect_success
'rebase -i respects core.commentchar=auto' '
1023 test_config core.commentchar auto &&
1024 write_script copy-edit-script.sh <<-\EOF &&
1027 test_set_editor "$(pwd)/copy-edit-script.sh" &&
1028 test_when_finished "git rebase --abort || :" &&
1029 git rebase -i HEAD^ &&
1030 test -z "$(grep -ve "^#" -e "^\$" -e "^pick" edit-script)"
1033 test_expect_success
'rebase -i, with <onto> and <upstream> specified as :/quuxery' '
1034 test_when_finished "git branch -D torebase" &&
1035 git checkout -b torebase branch1 &&
1036 upstream=$(git rev-parse ":/J") &&
1037 onto=$(git rev-parse ":/A") &&
1038 git rebase --onto $onto $upstream &&
1039 git reset --hard branch1 &&
1040 git rebase --onto ":/A" ":/J" &&
1041 git checkout branch1
1044 test_expect_success
'rebase -i with --strategy and -X' '
1045 git checkout -b conflict-merge-use-theirs conflict-branch &&
1046 git reset --hard HEAD^ &&
1047 echo five >conflict &&
1049 git commit -a -m "one file conflict" &&
1050 EDITOR=true git rebase -i --strategy=recursive -Xours conflict-branch &&
1051 test $(git show conflict-branch:conflict) = $(cat conflict) &&
1052 test $(cat file1) = Z
1055 test_expect_success
'interrupted rebase -i with --strategy and -X' '
1056 git checkout -b conflict-merge-use-theirs-interrupted conflict-branch &&
1057 git reset --hard HEAD^ &&
1059 git add breakpoint &&
1060 git commit -m "breakpoint for interactive mode" &&
1061 echo five >conflict &&
1063 git commit -a -m "one file conflict" &&
1065 FAKE_LINES="edit 1 2" git rebase -i --strategy=recursive -Xours conflict-branch &&
1066 git rebase --continue &&
1067 test $(git show conflict-branch:conflict) = $(cat conflict) &&
1068 test $(cat file1) = Z
1071 test_expect_success
'rebase -i error on commits with \ in message' '
1072 current_head=$(git rev-parse HEAD) &&
1073 test_when_finished "git rebase --abort; git reset --hard $current_head; rm -f error" &&
1074 test_commit TO-REMOVE will-conflict old-content &&
1075 test_commit "\temp" will-conflict new-content dummy &&
1076 test_must_fail env EDITOR=true git rebase -i HEAD^ --onto HEAD^^ 2>error &&
1077 test_expect_code 1 grep " emp" error
1080 test_expect_success
'short SHA-1 setup' '
1081 test_when_finished "git checkout master" &&
1082 git checkout --orphan collide &&
1086 test_commit collide1 collide &&
1087 test_commit --notick collide2 collide &&
1088 test_commit --notick collide3 collide
1092 test_expect_success
'short SHA-1 collide' '
1093 test_when_finished "reset_rebase && git checkout master" &&
1094 git checkout collide &&
1099 FAKE_COMMIT_MESSAGE="collide2 ac4f2ee" \
1100 FAKE_LINES="reword 1 2" git rebase -i HEAD~2
1104 test_expect_success
'respect core.abbrev' '
1105 git config core.abbrev 12 &&
1106 set_cat_todo_editor &&
1107 test_must_fail git rebase -i HEAD~4 >todo-list &&
1108 test 4 = $(grep -c "pick [0-9a-f]\{12,\}" todo-list)
1111 test_expect_success
'todo count' '
1112 write_script dump-raw.sh <<-\EOF &&
1115 test_set_editor "$(pwd)/dump-raw.sh" &&
1116 git rebase -i HEAD~4 >actual &&
1117 test_i18ngrep "^# Rebase ..* onto ..* ([0-9]" actual
1120 test_expect_success
'rebase -i commits that overwrite untracked files (pick)' '
1121 git checkout --force branch2 &&
1124 FAKE_LINES="edit 1 2" git rebase -i A &&
1125 test_cmp_rev HEAD F &&
1126 test_path_is_missing file6 &&
1128 test_must_fail git rebase --continue &&
1129 test_cmp_rev HEAD F &&
1131 git rebase --continue &&
1135 test_expect_success
'rebase -i commits that overwrite untracked files (squash)' '
1136 git checkout --force branch2 &&
1138 git tag original-branch2 &&
1140 FAKE_LINES="edit 1 squash 2" git rebase -i A &&
1141 test_cmp_rev HEAD F &&
1142 test_path_is_missing file6 &&
1144 test_must_fail git rebase --continue &&
1145 test_cmp_rev HEAD F &&
1147 git rebase --continue &&
1148 test $(git cat-file commit HEAD | sed -ne \$p) = I &&
1149 git reset --hard original-branch2
1152 test_expect_success
'rebase -i commits that overwrite untracked files (no ff)' '
1153 git checkout --force branch2 &&
1156 FAKE_LINES="edit 1 2" git rebase -i --no-ff A &&
1157 test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1158 test_path_is_missing file6 &&
1160 test_must_fail git rebase --continue &&
1161 test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1163 git rebase --continue &&
1164 test $(git cat-file commit HEAD | sed -ne \$p) = I
1167 test_expect_success
'rebase --continue removes CHERRY_PICK_HEAD' '
1168 git checkout -b commit-to-skip &&
1171 test_seq 5 | sed "s/$double/&&/" >seq &&
1174 git commit -m seq-$double
1177 git reset --hard HEAD~2 &&
1178 git cherry-pick seq-onto &&
1180 test_must_fail env FAKE_LINES= git rebase -i seq-onto &&
1181 test -d .git/rebase-merge &&
1182 git rebase --continue &&
1183 git diff --exit-code seq-onto &&
1184 test ! -d .git/rebase-merge &&
1185 test ! -f .git/CHERRY_PICK_HEAD
1188 rebase_setup_and_clean
() {
1189 test_when_finished
"
1190 git checkout master &&
1191 test_might_fail git branch -D $1 &&
1192 test_might_fail git rebase --abort
1194 git checkout
-b $1 master
1197 test_expect_success
'drop' '
1198 rebase_setup_and_clean drop-test &&
1200 FAKE_LINES="1 drop 2 3 drop 4 5" git rebase -i --root &&
1201 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1202 test C = $(git cat-file commit HEAD^ | sed -ne \$p) &&
1203 test A = $(git cat-file commit HEAD^^ | sed -ne \$p)
1207 Successfully rebased and updated refs/heads/missing-commit.
1210 test_expect_success
'rebase -i respects rebase.missingCommitsCheck = ignore' '
1211 test_config rebase.missingCommitsCheck ignore &&
1212 rebase_setup_and_clean missing-commit &&
1214 FAKE_LINES="1 2 3 4" \
1215 git rebase -i --root 2>actual &&
1216 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1217 test_i18ncmp expect actual
1221 Warning: some commits may have been dropped accidentally.
1222 Dropped commits (newer to older):
1223 - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
1224 To avoid this message, use "drop" to explicitly remove a commit.
1226 Use 'git config rebase.missingCommitsCheck' to change the level of warnings.
1227 The possible behaviours are: ignore, warn, error.
1229 Successfully rebased and updated refs/heads/missing-commit.
1232 test_expect_success
'rebase -i respects rebase.missingCommitsCheck = warn' '
1233 test_config rebase.missingCommitsCheck warn &&
1234 rebase_setup_and_clean missing-commit &&
1236 FAKE_LINES="1 2 3 4" \
1237 git rebase -i --root 2>actual &&
1238 test_i18ncmp expect actual &&
1239 test D = $(git cat-file commit HEAD | sed -ne \$p)
1243 Warning: some commits may have been dropped accidentally.
1244 Dropped commits (newer to older):
1245 - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
1246 - $(git rev-list --pretty=oneline --abbrev-commit -1 master~2)
1247 To avoid this message, use "drop" to explicitly remove a commit.
1249 Use 'git config rebase.missingCommitsCheck' to change the level of warnings.
1250 The possible behaviours are: ignore, warn, error.
1252 You can fix this with 'git rebase --edit-todo' and then run 'git rebase --continue'.
1253 Or you can abort the rebase with 'git rebase --abort'.
1256 test_expect_success
'rebase -i respects rebase.missingCommitsCheck = error' '
1257 test_config rebase.missingCommitsCheck error &&
1258 rebase_setup_and_clean missing-commit &&
1260 test_must_fail env FAKE_LINES="1 2 4" \
1261 git rebase -i --root 2>actual &&
1262 test_i18ncmp expect actual &&
1263 cp .git/rebase-merge/git-rebase-todo.backup \
1264 .git/rebase-merge/git-rebase-todo &&
1265 FAKE_LINES="1 2 drop 3 4 drop 5" \
1266 git rebase --edit-todo &&
1267 git rebase --continue &&
1268 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1269 test B = $(git cat-file commit HEAD^ | sed -ne \$p)
1272 test_expect_success
'respects rebase.abbreviateCommands with fixup, squash and exec' '
1273 rebase_setup_and_clean abbrevcmd &&
1274 test_commit "first" file1.txt "first line" first &&
1275 test_commit "second" file1.txt "another line" second &&
1276 test_commit "fixup! first" file2.txt "first line again" first_fixup &&
1277 test_commit "squash! second" file1.txt "another line here" second_squash &&
1278 cat >expected <<-EOF &&
1279 p $(git rev-list --abbrev-commit -1 first) first
1280 f $(git rev-list --abbrev-commit -1 first_fixup) fixup! first
1282 p $(git rev-list --abbrev-commit -1 second) second
1283 s $(git rev-list --abbrev-commit -1 second_squash) squash! second
1286 git checkout abbrevcmd &&
1287 set_cat_todo_editor &&
1288 test_config rebase.abbreviateCommands true &&
1289 test_must_fail git rebase -i --exec "git show HEAD" \
1290 --autosquash master >actual &&
1291 test_cmp expected actual
1294 test_expect_success
'static check of bad command' '
1295 rebase_setup_and_clean bad-cmd &&
1297 test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \
1298 git rebase -i --root 2>actual &&
1299 test_i18ngrep "badcmd $(git rev-list --oneline -1 master~1)" actual &&
1300 test_i18ngrep "You can fix this with .git rebase --edit-todo.." actual &&
1301 FAKE_LINES="1 2 3 drop 4 5" git rebase --edit-todo &&
1302 git rebase --continue &&
1303 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1304 test C = $(git cat-file commit HEAD^ | sed -ne \$p)
1307 test_expect_success
'tabs and spaces are accepted in the todolist' '
1308 rebase_setup_and_clean indented-comment &&
1309 write_script add-indent.sh <<-\EOF &&
1311 # Turn single spaces into space/tab mix
1312 sed "1s/ / /g; 2s/ / /g; 3s/ / /g" "$1"
1313 printf "\n\t# comment\n #more\n\t # comment\n"
1317 test_set_editor "$(pwd)/add-indent.sh" &&
1318 git rebase -i HEAD^^^ &&
1319 test E = $(git cat-file commit HEAD | sed -ne \$p)
1322 test_expect_success
'static check of bad SHA-1' '
1323 rebase_setup_and_clean bad-sha &&
1325 test_must_fail env FAKE_LINES="1 2 edit fakesha 3 4 5 #" \
1326 git rebase -i --root 2>actual &&
1327 test_i18ngrep "edit XXXXXXX False commit" actual &&
1328 test_i18ngrep "You can fix this with .git rebase --edit-todo.." actual &&
1329 FAKE_LINES="1 2 4 5 6" git rebase --edit-todo &&
1330 git rebase --continue &&
1331 test E = $(git cat-file commit HEAD | sed -ne \$p)
1334 test_expect_success
'editor saves as CR/LF' '
1335 git checkout -b with-crlf &&
1336 write_script add-crs.sh <<-\EOF &&
1337 sed -e "s/\$/Q/" <"$1" | tr Q "\\015" >"$1".new &&
1341 test_set_editor "$(pwd)/add-crs.sh" &&
1347 test_expect_success
'rebase -i --gpg-sign=<key-id>' '
1349 FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" HEAD^ \
1351 test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err