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 the exec command checks tree cleanness' '
112 git checkout master &&
114 test_must_fail env FAKE_LINES="exec_echo_foo_>file1 1" git rebase -i HEAD^ &&
115 test_cmp_rev master^ HEAD &&
117 git rebase --continue
120 test_expect_success
'rebase -i with exec of inexistent command' '
121 git checkout master &&
122 test_when_finished "git rebase --abort" &&
124 test_must_fail env FAKE_LINES="exec_this-command-does-not-exist 1" \
125 git rebase -i HEAD^ >actual 2>&1 &&
126 ! grep "Maybe git-rebase is broken" actual
129 test_expect_success
'no changes are a nop' '
130 git checkout branch2 &&
133 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
134 test $(git rev-parse I) = $(git rev-parse HEAD)
137 test_expect_success
'test the [branch] option' '
138 git checkout -b dead-end &&
140 git commit -m "stop here" &&
142 git rebase -i F branch2 &&
143 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
144 test $(git rev-parse I) = $(git rev-parse branch2) &&
145 test $(git rev-parse I) = $(git rev-parse HEAD)
148 test_expect_success
'test --onto <branch>' '
149 git checkout -b test-onto branch2 &&
151 git rebase -i --onto branch1 F &&
152 test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" &&
153 test $(git rev-parse HEAD^) = $(git rev-parse branch1) &&
154 test $(git rev-parse I) = $(git rev-parse branch2)
157 test_expect_success
'rebase on top of a non-conflicting commit' '
158 git checkout branch1 &&
159 git tag original-branch1 &&
161 git rebase -i branch2 &&
162 test file6 = $(git diff --name-only original-branch1) &&
163 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
164 test $(git rev-parse I) = $(git rev-parse branch2) &&
165 test $(git rev-parse I) = $(git rev-parse HEAD~2)
168 test_expect_success
'reflog for the branch shows state before rebase' '
169 test $(git rev-parse branch1@{1}) = $(git rev-parse original-branch1)
172 test_expect_success
'reflog for the branch shows correct finish message' '
173 printf "rebase -i (finish): refs/heads/branch1 onto %s\n" \
174 "$(git rev-parse branch2)" >expected &&
175 git log -g --pretty=%gs -1 refs/heads/branch1 >actual &&
176 test_cmp expected actual
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 test_i18ngrep "The following untracked working tree files would be overwritten by checkout:" \
231 test_i18ngrep "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
'retain authorship w/ conflicts' '
248 git reset --hard twerp &&
249 test_commit a conflict a conflict-a &&
250 git reset --hard twerp &&
251 GIT_AUTHOR_NAME=AttributeMe \
252 test_commit b conflict b conflict-b &&
254 test_must_fail git rebase -i conflict-a &&
255 echo resolved >conflict &&
257 git rebase --continue &&
258 test $(git rev-parse conflict-a^0) = $(git rev-parse HEAD^) &&
263 test_expect_success
'squash' '
264 git reset --hard twerp &&
267 GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 &&
268 echo "******************************" &&
270 FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \
271 git rebase -i --onto master HEAD~2 &&
272 test B = $(cat file7) &&
273 test $(git rev-parse HEAD^) = $(git rev-parse master)
276 test_expect_success
'retain authorship when squashing' '
277 git show HEAD | grep "^Author: Twerp Snog"
280 test_expect_success
'-p handles "no changes" gracefully' '
281 HEAD=$(git rev-parse HEAD) &&
283 git rebase -i -p HEAD^ &&
284 git update-index --refresh &&
285 git diff-files --quiet &&
286 git diff-index --quiet --cached HEAD -- &&
287 test $HEAD = $(git rev-parse HEAD)
290 test_expect_failure
'exchange two commits with -p' '
293 FAKE_LINES="2 1" git rebase -i -p HEAD~2 &&
294 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
295 test G = $(git cat-file commit HEAD | sed -ne \$p)
298 test_expect_success
'preserve merges with -p' '
299 git checkout -b to-be-preserved master^ &&
300 : > unrelated-file &&
301 git add unrelated-file &&
303 git commit -m "unrelated" &&
304 git checkout -b another-branch master &&
307 git commit -m J file1 &&
309 git merge to-be-preserved &&
312 git commit -m K file1 &&
315 git commit -m L1 file1 &&
316 git checkout HEAD^ &&
317 echo 1 > unrelated-file &&
319 git commit -m L2 unrelated-file &&
321 git merge another-branch &&
324 git commit -m M file1 &&
325 git checkout -b to-be-rebased &&
328 git rebase -i -p --onto branch1 master &&
329 git update-index --refresh &&
330 git diff-files --quiet &&
331 git diff-index --quiet --cached HEAD -- &&
332 test $(git rev-parse HEAD~6) = $(git rev-parse branch1) &&
333 test $(git rev-parse HEAD~4^2) = $(git rev-parse to-be-preserved) &&
334 test $(git rev-parse HEAD^^2^) = $(git rev-parse HEAD^^^) &&
335 test $(git show HEAD~5:file1) = B &&
336 test $(git show HEAD~3:file1) = C &&
337 test $(git show HEAD:file1) = E &&
338 test $(git show HEAD:unrelated-file) = 1
341 test_expect_success
'edit ancestor with -p' '
343 FAKE_LINES="1 2 edit 3 4" git rebase -i -p HEAD~3 &&
344 echo 2 > unrelated-file &&
346 git commit -m L2-modified --amend unrelated-file &&
347 git rebase --continue &&
348 git update-index --refresh &&
349 git diff-files --quiet &&
350 git diff-index --quiet --cached HEAD -- &&
351 test $(git show HEAD:unrelated-file) = 2
354 test_expect_success
'--continue tries to commit' '
357 test_must_fail git rebase -i --onto new-branch1 HEAD^ &&
358 echo resolved > file1 &&
360 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
361 test $(git rev-parse HEAD^) = $(git rev-parse new-branch1) &&
362 git show HEAD | grep chouette
365 test_expect_success
'verbose flag is heeded, even after --continue' '
366 git reset --hard master@{1} &&
369 test_must_fail git rebase -v -i --onto new-branch1 HEAD^ &&
370 echo resolved > file1 &&
372 git rebase --continue > output &&
373 grep "^ file1 | 2 +-$" output
376 test_expect_success C_LOCALE_OUTPUT
'multi-squash only fires up editor once' '
377 base=$(git rev-parse HEAD~4) &&
379 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 squash 2 squash 3 squash 4" \
380 EXPECT_HEADER_COUNT=4 \
381 git rebase -i $base &&
382 test $base = $(git rev-parse HEAD^) &&
383 test 1 = $(git show | grep ONCE | wc -l)
386 test_expect_success C_LOCALE_OUTPUT
'multi-fixup does not fire up editor' '
387 git checkout -b multi-fixup E &&
388 base=$(git rev-parse HEAD~4) &&
390 FAKE_COMMIT_AMEND="NEVER" FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \
391 git rebase -i $base &&
392 test $base = $(git rev-parse HEAD^) &&
393 test 0 = $(git show | grep NEVER | wc -l) &&
394 git checkout to-be-rebased &&
395 git branch -D multi-fixup
398 test_expect_success
'commit message used after conflict' '
399 git checkout -b conflict-fixup conflict-branch &&
400 base=$(git rev-parse HEAD~4) &&
402 test_must_fail env FAKE_LINES="1 fixup 3 fixup 4" git rebase -i $base &&
403 echo three > conflict &&
405 FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \
406 git rebase --continue &&
407 test $base = $(git rev-parse HEAD^) &&
408 test 1 = $(git show | grep ONCE | wc -l) &&
409 git checkout to-be-rebased &&
410 git branch -D conflict-fixup
413 test_expect_success
'commit message retained after conflict' '
414 git checkout -b conflict-squash conflict-branch &&
415 base=$(git rev-parse HEAD~4) &&
417 test_must_fail env FAKE_LINES="1 fixup 3 squash 4" git rebase -i $base &&
418 echo three > conflict &&
420 FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \
421 git rebase --continue &&
422 test $base = $(git rev-parse HEAD^) &&
423 test 2 = $(git show | grep TWICE | wc -l) &&
424 git checkout to-be-rebased &&
425 git branch -D conflict-squash
428 cat > expect-squash-fixup
<< EOF
436 test_expect_success C_LOCALE_OUTPUT
'squash and fixup generate correct log messages' '
437 git checkout -b squash-fixup E &&
438 base=$(git rev-parse HEAD~4) &&
440 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 fixup 2 squash 3 fixup 4" \
441 EXPECT_HEADER_COUNT=4 \
442 git rebase -i $base &&
443 git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup &&
444 test_cmp expect-squash-fixup actual-squash-fixup &&
445 git checkout to-be-rebased &&
446 git branch -D squash-fixup
449 test_expect_success C_LOCALE_OUTPUT
'squash ignores comments' '
450 git checkout -b skip-comments E &&
451 base=$(git rev-parse HEAD~4) &&
453 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \
454 EXPECT_HEADER_COUNT=4 \
455 git rebase -i $base &&
456 test $base = $(git rev-parse HEAD^) &&
457 test 1 = $(git show | grep ONCE | wc -l) &&
458 git checkout to-be-rebased &&
459 git branch -D skip-comments
462 test_expect_success C_LOCALE_OUTPUT
'squash ignores blank lines' '
463 git checkout -b skip-blank-lines E &&
464 base=$(git rev-parse HEAD~4) &&
466 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \
467 EXPECT_HEADER_COUNT=4 \
468 git rebase -i $base &&
469 test $base = $(git rev-parse HEAD^) &&
470 test 1 = $(git show | grep ONCE | wc -l) &&
471 git checkout to-be-rebased &&
472 git branch -D skip-blank-lines
475 test_expect_success
'squash works as expected' '
476 git checkout -b squash-works no-conflict-branch &&
477 one=$(git rev-parse HEAD~3) &&
479 FAKE_LINES="1 squash 3 2" EXPECT_HEADER_COUNT=2 \
480 git rebase -i HEAD~3 &&
481 test $one = $(git rev-parse HEAD~2)
484 test_expect_success
'interrupted squash works as expected' '
485 git checkout -b interrupted-squash conflict-branch &&
486 one=$(git rev-parse HEAD~3) &&
488 test_must_fail env FAKE_LINES="1 squash 3 2" git rebase -i HEAD~3 &&
489 (echo one; echo two; echo four) > conflict &&
491 test_must_fail git rebase --continue &&
492 echo resolved > conflict &&
494 git rebase --continue &&
495 test $one = $(git rev-parse HEAD~2)
498 test_expect_success
'interrupted squash works as expected (case 2)' '
499 git checkout -b interrupted-squash2 conflict-branch &&
500 one=$(git rev-parse HEAD~3) &&
502 test_must_fail env FAKE_LINES="3 squash 1 2" 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 &&
539 test_must_fail env FAKE_COMMIT_MESSAGE=" " git rebase --continue &&
540 test $old = $(git rev-parse HEAD) &&
544 test_expect_success
'auto-amend only edited commits after "edit"' '
547 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
548 echo "edited again" > file7 &&
550 FAKE_COMMIT_MESSAGE="edited file7 again" git commit &&
551 echo "and again" > file7 &&
554 test_must_fail env FAKE_COMMIT_MESSAGE="and again" git rebase --continue &&
558 test_expect_success
'clean error after failed "exec"' '
560 test_when_finished "git rebase --abort || :" &&
562 test_must_fail env FAKE_LINES="1 exec_false" git rebase -i HEAD^ &&
563 echo "edited again" > file7 &&
565 test_must_fail git rebase --continue 2>error &&
566 test_i18ngrep "you have staged changes in your working tree" error
569 test_expect_success
'rebase a detached HEAD' '
570 grandparent=$(git rev-parse HEAD~2) &&
571 git checkout $(git rev-parse HEAD) &&
574 FAKE_LINES="2 1" git rebase -i HEAD~2 &&
575 test $grandparent = $(git rev-parse HEAD~2)
578 test_expect_success
'rebase a commit violating pre-commit' '
580 mkdir -p .git/hooks &&
581 write_script .git/hooks/pre-commit <<-\EOF &&
582 test -z "$(git diff --cached --check)"
584 echo "monde! " >> file1 &&
586 test_must_fail git commit -m doesnt-verify file1 &&
587 git commit -m doesnt-verify --no-verify file1 &&
590 FAKE_LINES=2 git rebase -i HEAD~2
594 test_expect_success
'rebase with a file named HEAD in worktree' '
598 git checkout -b branch3 A &&
601 GIT_AUTHOR_NAME="Squashed Away" &&
602 export GIT_AUTHOR_NAME &&
605 git commit -m "Add head" &&
608 git commit -m "Add body"
612 FAKE_LINES="1 squash 2" git rebase -i to-be-rebased &&
613 test "$(git show -s --pretty=format:%an)" = "Squashed Away"
617 test_expect_success
'do "noop" when there is nothing to cherry-pick' '
619 git checkout -b branch4 HEAD &&
620 GIT_EDITOR=: git commit --amend \
621 --author="Somebody else <somebody@else.com>" &&
622 test $(git rev-parse branch3) != $(git rev-parse branch4) &&
624 git rebase -i branch3 &&
625 test $(git rev-parse branch3) = $(git rev-parse branch4)
629 test_expect_success
'submodule rebase setup' '
633 cd sub && git init && >elif &&
634 git add elif && git commit -m "submodule initial"
639 git commit -m "One" &&
642 git commit -a -m "Two" &&
644 cd sub && echo 3 >elif &&
645 git commit -a -m "submodule second"
649 git commit -a -m "Three changes submodule"
652 test_expect_success
'submodule rebase -i' '
654 FAKE_LINES="1 squash 2 3" git rebase -i A
657 test_expect_success
'submodule conflict setup' '
658 git tag submodule-base &&
659 git checkout HEAD^ &&
661 cd sub && git checkout HEAD^ && echo 4 >elif &&
662 git add elif && git commit -m "submodule conflict"
666 git commit -m "Conflict in submodule" &&
667 git tag submodule-topic
670 test_expect_success
'rebase -i continue with only submodule staged' '
672 test_must_fail git rebase -i submodule-base &&
674 git rebase --continue &&
675 test $(git rev-parse submodule-base) != $(git rev-parse HEAD)
678 test_expect_success
'rebase -i continue with unstaged submodule' '
679 git checkout submodule-topic &&
682 test_must_fail git rebase -i submodule-base &&
684 git rebase --continue &&
685 test $(git rev-parse submodule-base) = $(git rev-parse HEAD)
688 test_expect_success
'avoid unnecessary reset' '
689 git checkout master &&
691 test-chmtime =123456789 file3 &&
692 git update-index --refresh &&
693 HEAD=$(git rev-parse HEAD) &&
695 git rebase -i HEAD~4 &&
696 test $HEAD = $(git rev-parse HEAD) &&
697 MTIME=$(test-chmtime -v +0 file3 | sed 's
/[^
0-9].
*$
//') &&
698 test 123456789 = $MTIME
701 test_expect_success
'reword' '
702 git checkout -b reword-branch master &&
704 FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" git rebase -i A &&
705 git show HEAD | grep "E changed" &&
706 test $(git rev-parse master) != $(git rev-parse HEAD) &&
707 test $(git rev-parse master^) = $(git rev-parse HEAD^) &&
708 FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" git rebase -i A &&
709 git show HEAD^ | grep "D changed" &&
710 FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" git rebase -i A &&
711 git show HEAD~3 | grep "B changed" &&
712 FAKE_LINES="1 reword 2 3 4" FAKE_COMMIT_MESSAGE="C changed" git rebase -i A &&
713 git show HEAD~2 | grep "C changed"
716 test_expect_success
'rebase -i can copy notes' '
717 git config notes.rewrite.rebase true &&
718 git config notes.rewriteRef "refs/notes/*" &&
722 git notes add -m"a note" n3 &&
724 git rebase -i --onto n1 n2 &&
725 test "a note" = "$(git notes show HEAD)"
734 test_expect_success
'rebase -i can copy notes over a fixup' '
735 git reset --hard n3 &&
736 git notes add -m"an earlier note" n2 &&
738 GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 fixup 2" git rebase -i n1 &&
739 git notes show > output &&
740 test_cmp expect output
743 test_expect_success
'rebase while detaching HEAD' '
744 git symbolic-ref HEAD &&
745 grandparent=$(git rev-parse HEAD~2) &&
748 FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0 &&
749 test $grandparent = $(git rev-parse HEAD~2) &&
750 test_must_fail git symbolic-ref HEAD
753 test_tick
# Ensure that the rebased commits get a different timestamp.
754 test_expect_success
'always cherry-pick with --no-ff' '
755 git checkout no-ff-branch &&
756 git tag original-no-ff-branch &&
758 git rebase -i --no-ff A &&
762 test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) &&
763 git diff HEAD~$p original-no-ff-branch~$p > out &&
766 test $(git rev-parse HEAD~3) = $(git rev-parse original-no-ff-branch~3) &&
767 git diff HEAD~3 original-no-ff-branch~3 > out &&
771 test_expect_success
'set up commits with funny messages' '
772 git checkout -b funny A &&
775 git commit -a -m "end with slash\\" &&
778 git commit -a -m "something (\000) that looks like octal" &&
781 git commit -a -m "something (\n) that looks like a newline" &&
784 git commit -a -m "another commit"
787 test_expect_success
'rebase-i history with funny messages' '
788 git rev-list A..funny >expect &&
791 FAKE_LINES="1 2 3 4" git rebase -i A &&
792 git rev-list A.. >actual &&
793 test_cmp expect actual
796 test_expect_success
'prepare for rebase -i --exec' '
797 git checkout master &&
798 git checkout -b execute &&
799 test_commit one_exec main.txt one_exec &&
800 test_commit two_exec main.txt two_exec &&
801 test_commit three_exec main.txt three_exec
804 test_expect_success
'running "git rebase -i --exec git show HEAD"' '
806 git rebase -i --exec "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
816 test_expect_success
'running "git rebase --exec git show HEAD -i"' '
817 git reset --hard execute &&
819 git rebase --exec "git show HEAD" -i HEAD~2 >actual &&
821 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
823 git rebase -i HEAD~2 >expect
825 sed -e "1,9d" expect >expected &&
826 test_cmp expected actual
829 test_expect_success
'running "git rebase -ix git show HEAD"' '
830 git reset --hard execute &&
832 git rebase -ix "git show HEAD" HEAD~2 >actual &&
834 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
836 git rebase -i HEAD~2 >expect
838 sed -e "1,9d" expect >expected &&
839 test_cmp expected actual
843 test_expect_success
'rebase -ix with several <CMD>' '
844 git reset --hard execute &&
846 git rebase -ix "git show HEAD; pwd" HEAD~2 >actual &&
848 FAKE_LINES="1 exec_git_show_HEAD;_pwd 2 exec_git_show_HEAD;_pwd" &&
850 git rebase -i HEAD~2 >expect
852 sed -e "1,9d" expect >expected &&
853 test_cmp expected actual
856 test_expect_success
'rebase -ix with several instances of --exec' '
857 git reset --hard execute &&
859 git rebase -i --exec "git show HEAD" --exec "pwd" HEAD~2 >actual &&
861 FAKE_LINES="1 exec_git_show_HEAD exec_pwd 2
862 exec_git_show_HEAD exec_pwd" &&
864 git rebase -i HEAD~2 >expect
866 sed -e "1,11d" expect >expected &&
867 test_cmp expected actual
870 test_expect_success C_LOCALE_OUTPUT
'rebase -ix with --autosquash' '
871 git reset --hard execute &&
872 git checkout -b autosquash &&
873 echo second >second.txt &&
874 git add second.txt &&
875 git commit -m "fixup! two_exec" &&
878 git commit -m "fixup! two_exec" &&
881 git checkout -b autosquash_actual &&
882 git rebase -i --exec "git show HEAD" --autosquash HEAD~4 >actual
884 git checkout autosquash &&
886 git checkout -b autosquash_expected &&
887 FAKE_LINES="1 fixup 3 fixup 4 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
889 git rebase -i HEAD~4 >expect
891 sed -e "1,13d" expect >expected &&
892 test_cmp expected actual
895 test_expect_success
'rebase --exec works without -i ' '
896 git reset --hard execute &&
897 rm -rf exec_output &&
898 EDITOR="echo >invoked_editor" git rebase --exec "echo a line >>exec_output" HEAD~2 2>actual &&
899 test_i18ngrep "Successfully rebased and updated" actual &&
900 test_line_count = 2 exec_output &&
901 test_path_is_missing invoked_editor
904 test_expect_success
'rebase -i --exec without <CMD>' '
905 git reset --hard execute &&
907 test_must_fail git rebase -i --exec 2>tmp &&
908 sed -e "1d" tmp >actual &&
909 test_must_fail git rebase -h >expected &&
910 test_cmp expected actual &&
914 test_expect_success
'rebase -i --root re-order and drop commits' '
917 FAKE_LINES="3 1 2 5" git rebase -i --root &&
918 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
919 test B = $(git cat-file commit HEAD^ | sed -ne \$p) &&
920 test A = $(git cat-file commit HEAD^^ | sed -ne \$p) &&
921 test C = $(git cat-file commit HEAD^^^ | sed -ne \$p) &&
922 test 0 = $(git cat-file commit HEAD^^^ | grep -c ^parent\ )
925 test_expect_success
'rebase -i --root retain root commit author and message' '
929 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
931 FAKE_LINES="2" git rebase -i --root &&
932 git cat-file commit HEAD | grep -q "^author Twerp Snog" &&
933 git cat-file commit HEAD | grep -q "^different author$"
936 test_expect_success
'rebase -i --root temporary sentinel commit' '
939 test_must_fail env FAKE_LINES="2" git rebase -i --root &&
940 git cat-file commit HEAD | grep "^tree 4b825dc642cb" &&
944 test_expect_success
'rebase -i --root fixup root commit' '
947 FAKE_LINES="1 fixup 2" git rebase -i --root &&
948 test A = $(git cat-file commit HEAD | sed -ne \$p) &&
949 test B = $(git show HEAD:file1) &&
950 test 0 = $(git cat-file commit HEAD | grep -c ^parent\ )
953 test_expect_success C_LOCALE_OUTPUT
'rebase --edit-todo does not work on non-interactive rebase' '
955 git checkout conflict-branch &&
957 test_must_fail git rebase --onto HEAD~2 HEAD~ &&
958 test_must_fail git rebase --edit-todo &&
962 test_expect_success
'rebase --edit-todo can be used to modify todo' '
964 git checkout no-conflict-branch^0 &&
966 FAKE_LINES="edit 1 2 3" git rebase -i HEAD~3 &&
967 FAKE_LINES="2 1" git rebase --edit-todo &&
968 git rebase --continue &&
969 test M = $(git cat-file commit HEAD^ | sed -ne \$p) &&
970 test L = $(git cat-file commit HEAD | sed -ne \$p)
973 test_expect_success
'rebase -i produces readable reflog' '
975 git branch -f branch-reflog-test H &&
977 git rebase -i --onto I F branch-reflog-test &&
978 cat >expect <<-\EOF &&
979 rebase -i (finish): returning to refs/heads/branch-reflog-test
982 rebase -i (start): checkout I
984 git reflog -n4 HEAD |
985 sed "s/[^:]*: //" >actual &&
986 test_cmp expect actual
989 test_expect_success
'rebase -i respects core.commentchar' '
992 test_config core.commentchar "\\" &&
993 write_script remove-all-but-first.sh <<-\EOF &&
994 sed -e "2,\$s/^/\\\\/" "$1" >"$1.tmp" &&
997 test_set_editor "$(pwd)/remove-all-but-first.sh" &&
999 test B = $(git cat-file commit HEAD^ | sed -ne \$p)
1002 test_expect_success
'rebase -i respects core.commentchar=auto' '
1003 test_config core.commentchar auto &&
1004 write_script copy-edit-script.sh <<-\EOF &&
1007 test_set_editor "$(pwd)/copy-edit-script.sh" &&
1008 test_when_finished "git rebase --abort || :" &&
1009 git rebase -i HEAD^ &&
1010 test -z "$(grep -ve "^#" -e "^\$" -e "^pick" edit-script)"
1013 test_expect_success
'rebase -i, with <onto> and <upstream> specified as :/quuxery' '
1014 test_when_finished "git branch -D torebase" &&
1015 git checkout -b torebase branch1 &&
1016 upstream=$(git rev-parse ":/J") &&
1017 onto=$(git rev-parse ":/A") &&
1018 git rebase --onto $onto $upstream &&
1019 git reset --hard branch1 &&
1020 git rebase --onto ":/A" ":/J" &&
1021 git checkout branch1
1024 test_expect_success
'rebase -i with --strategy and -X' '
1025 git checkout -b conflict-merge-use-theirs conflict-branch &&
1026 git reset --hard HEAD^ &&
1027 echo five >conflict &&
1029 git commit -a -m "one file conflict" &&
1030 EDITOR=true git rebase -i --strategy=recursive -Xours conflict-branch &&
1031 test $(git show conflict-branch:conflict) = $(cat conflict) &&
1032 test $(cat file1) = Z
1035 test_expect_success
'interrupted rebase -i with --strategy and -X' '
1036 git checkout -b conflict-merge-use-theirs-interrupted conflict-branch &&
1037 git reset --hard HEAD^ &&
1039 git add breakpoint &&
1040 git commit -m "breakpoint for interactive mode" &&
1041 echo five >conflict &&
1043 git commit -a -m "one file conflict" &&
1045 FAKE_LINES="edit 1 2" git rebase -i --strategy=recursive -Xours conflict-branch &&
1046 git rebase --continue &&
1047 test $(git show conflict-branch:conflict) = $(cat conflict) &&
1048 test $(cat file1) = Z
1051 test_expect_success
'rebase -i error on commits with \ in message' '
1052 current_head=$(git rev-parse HEAD) &&
1053 test_when_finished "git rebase --abort; git reset --hard $current_head; rm -f error" &&
1054 test_commit TO-REMOVE will-conflict old-content &&
1055 test_commit "\temp" will-conflict new-content dummy &&
1056 test_must_fail env EDITOR=true git rebase -i HEAD^ --onto HEAD^^ 2>error &&
1057 test_expect_code 1 grep " emp" error
1060 test_expect_success
'short SHA-1 setup' '
1061 test_when_finished "git checkout master" &&
1062 git checkout --orphan collide &&
1066 test_commit collide1 collide &&
1067 test_commit --notick collide2 collide &&
1068 test_commit --notick collide3 collide
1072 test_expect_success
'short SHA-1 collide' '
1073 test_when_finished "reset_rebase && git checkout master" &&
1074 git checkout collide &&
1079 FAKE_COMMIT_MESSAGE="collide2 ac4f2ee" \
1080 FAKE_LINES="reword 1 2" git rebase -i HEAD~2
1084 test_expect_success
'respect core.abbrev' '
1085 git config core.abbrev 12 &&
1086 set_cat_todo_editor &&
1087 test_must_fail git rebase -i HEAD~4 >todo-list &&
1088 test 4 = $(grep -c "pick [0-9a-f]\{12,\}" todo-list)
1091 test_expect_success
'todo count' '
1092 write_script dump-raw.sh <<-\EOF &&
1095 test_set_editor "$(pwd)/dump-raw.sh" &&
1096 git rebase -i HEAD~4 >actual &&
1097 test_i18ngrep "^# Rebase ..* onto ..* ([0-9]" actual
1100 test_expect_success
'rebase -i commits that overwrite untracked files (pick)' '
1101 git checkout --force branch2 &&
1104 FAKE_LINES="edit 1 2" git rebase -i A &&
1105 test_cmp_rev HEAD F &&
1106 test_path_is_missing file6 &&
1108 test_must_fail git rebase --continue &&
1109 test_cmp_rev HEAD F &&
1111 git rebase --continue &&
1115 test_expect_success
'rebase -i commits that overwrite untracked files (squash)' '
1116 git checkout --force branch2 &&
1118 git tag original-branch2 &&
1120 FAKE_LINES="edit 1 squash 2" git rebase -i A &&
1121 test_cmp_rev HEAD F &&
1122 test_path_is_missing file6 &&
1124 test_must_fail git rebase --continue &&
1125 test_cmp_rev HEAD F &&
1127 git rebase --continue &&
1128 test $(git cat-file commit HEAD | sed -ne \$p) = I &&
1129 git reset --hard original-branch2
1132 test_expect_success
'rebase -i commits that overwrite untracked files (no ff)' '
1133 git checkout --force branch2 &&
1136 FAKE_LINES="edit 1 2" git rebase -i --no-ff A &&
1137 test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1138 test_path_is_missing file6 &&
1140 test_must_fail git rebase --continue &&
1141 test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1143 git rebase --continue &&
1144 test $(git cat-file commit HEAD | sed -ne \$p) = I
1147 test_expect_success
'rebase --continue removes CHERRY_PICK_HEAD' '
1148 git checkout -b commit-to-skip &&
1151 test_seq 5 | sed "s/$double/&&/" >seq &&
1154 git commit -m seq-$double
1157 git reset --hard HEAD~2 &&
1158 git cherry-pick seq-onto &&
1160 test_must_fail env FAKE_LINES= git rebase -i seq-onto &&
1161 test -d .git/rebase-merge &&
1162 git rebase --continue &&
1163 git diff --exit-code seq-onto &&
1164 test ! -d .git/rebase-merge &&
1165 test ! -f .git/CHERRY_PICK_HEAD
1168 rebase_setup_and_clean
() {
1169 test_when_finished
"
1170 git checkout master &&
1171 test_might_fail git branch -D $1 &&
1172 test_might_fail git rebase --abort
1174 git checkout
-b $1 master
1177 test_expect_success
'drop' '
1178 rebase_setup_and_clean drop-test &&
1180 FAKE_LINES="1 drop 2 3 drop 4 5" git rebase -i --root &&
1181 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1182 test C = $(git cat-file commit HEAD^ | sed -ne \$p) &&
1183 test A = $(git cat-file commit HEAD^^ | sed -ne \$p)
1187 Successfully rebased and updated refs/heads/missing-commit.
1190 test_expect_success
'rebase -i respects rebase.missingCommitsCheck = ignore' '
1191 test_config rebase.missingCommitsCheck ignore &&
1192 rebase_setup_and_clean missing-commit &&
1194 FAKE_LINES="1 2 3 4" \
1195 git rebase -i --root 2>actual &&
1196 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1197 test_i18ncmp expect actual
1201 Warning: some commits may have been dropped accidentally.
1202 Dropped commits (newer to older):
1203 - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
1204 To avoid this message, use "drop" to explicitly remove a commit.
1206 Use 'git config rebase.missingCommitsCheck' to change the level of warnings.
1207 The possible behaviours are: ignore, warn, error.
1209 Successfully rebased and updated refs/heads/missing-commit.
1212 test_expect_success
'rebase -i respects rebase.missingCommitsCheck = warn' '
1213 test_config rebase.missingCommitsCheck warn &&
1214 rebase_setup_and_clean missing-commit &&
1216 FAKE_LINES="1 2 3 4" \
1217 git rebase -i --root 2>actual &&
1218 test_i18ncmp expect actual &&
1219 test D = $(git cat-file commit HEAD | sed -ne \$p)
1223 Warning: some commits may have been dropped accidentally.
1224 Dropped commits (newer to older):
1225 - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
1226 - $(git rev-list --pretty=oneline --abbrev-commit -1 master~2)
1227 To avoid this message, use "drop" to explicitly remove a commit.
1229 Use 'git config rebase.missingCommitsCheck' to change the level of warnings.
1230 The possible behaviours are: ignore, warn, error.
1232 You can fix this with 'git rebase --edit-todo' and then run 'git rebase --continue'.
1233 Or you can abort the rebase with 'git rebase --abort'.
1236 test_expect_success
'rebase -i respects rebase.missingCommitsCheck = error' '
1237 test_config rebase.missingCommitsCheck error &&
1238 rebase_setup_and_clean missing-commit &&
1240 test_must_fail env FAKE_LINES="1 2 4" \
1241 git rebase -i --root 2>actual &&
1242 test_i18ncmp expect actual &&
1243 cp .git/rebase-merge/git-rebase-todo.backup \
1244 .git/rebase-merge/git-rebase-todo &&
1245 FAKE_LINES="1 2 drop 3 4 drop 5" \
1246 git rebase --edit-todo &&
1247 git rebase --continue &&
1248 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1249 test B = $(git cat-file commit HEAD^ | sed -ne \$p)
1253 Warning: the command isn't recognized in the following line:
1254 - badcmd $(git rev-list --oneline -1 master~1)
1256 You can fix this with 'git rebase --edit-todo' and then run 'git rebase --continue'.
1257 Or you can abort the rebase with 'git rebase --abort'.
1260 test_expect_success
'static check of bad command' '
1261 rebase_setup_and_clean bad-cmd &&
1263 test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \
1264 git rebase -i --root 2>actual &&
1265 test_i18ncmp expect actual &&
1266 FAKE_LINES="1 2 3 drop 4 5" git rebase --edit-todo &&
1267 git rebase --continue &&
1268 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1269 test C = $(git cat-file commit HEAD^ | sed -ne \$p)
1272 test_expect_success
'tabs and spaces are accepted in the todolist' '
1273 rebase_setup_and_clean indented-comment &&
1274 write_script add-indent.sh <<-\EOF &&
1276 # Turn single spaces into space/tab mix
1277 sed "1s/ / /g; 2s/ / /g; 3s/ / /g" "$1"
1278 printf "\n\t# comment\n #more\n\t # comment\n"
1282 test_set_editor "$(pwd)/add-indent.sh" &&
1283 git rebase -i HEAD^^^ &&
1284 test E = $(git cat-file commit HEAD | sed -ne \$p)
1288 Warning: the SHA-1 is missing or isn't a commit in the following line:
1289 - edit XXXXXXX False commit
1291 You can fix this with 'git rebase --edit-todo' and then run 'git rebase --continue'.
1292 Or you can abort the rebase with 'git rebase --abort'.
1295 test_expect_success
'static check of bad SHA-1' '
1296 rebase_setup_and_clean bad-sha &&
1298 test_must_fail env FAKE_LINES="1 2 edit fakesha 3 4 5 #" \
1299 git rebase -i --root 2>actual &&
1300 test_i18ncmp expect actual &&
1301 FAKE_LINES="1 2 4 5 6" git rebase --edit-todo &&
1302 git rebase --continue &&
1303 test E = $(git cat-file commit HEAD | sed -ne \$p)
1306 test_expect_success
'editor saves as CR/LF' '
1307 git checkout -b with-crlf &&
1308 write_script add-crs.sh <<-\EOF &&
1309 sed -e "s/\$/Q/" <"$1" | tr Q "\\015" >"$1".new &&
1313 test_set_editor "$(pwd)/add-crs.sh" &&
1319 test_expect_success
'rebase -i --gpg-sign=<key-id>' '
1321 FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" HEAD^ \
1323 test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err