implicit interactive rebase: don't run sequence editor
[git.git] / t / t3404-rebase-interactive.sh
blob2b961745cc0aa302d3ac8ea72c4ad919de2e8bbf
1 #!/bin/sh
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.
11 Initial setup:
13 one - two - three - four (conflict-branch)
15 A - B - C - D - E (master)
16 | \
17 | F - G - H (branch1)
18 | \
19 |\ I (branch2)
20 | \
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".
28 . ./test-lib.sh
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 &&
60 test_commit P fileP
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.
67 SHELL=
68 export SHELL
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 cat > expect <<EOF
79 error: nothing to do
80 EOF
82 test_expect_success 'rebase -i with empty HEAD' '
83 set_fake_editor &&
84 test_must_fail env FAKE_LINES="1 exec_true" git rebase -i HEAD^ >actual 2>&1 &&
85 test_i18ncmp expect actual
88 test_expect_success 'rebase -i with the exec command' '
89 git checkout master &&
91 set_fake_editor &&
92 FAKE_LINES="1 exec_>touch-one
93 2 exec_>touch-two exec_false exec_>touch-three
94 3 4 exec_>\"touch-file__name_with_spaces\";_>touch-after-semicolon 5" &&
95 export FAKE_LINES &&
96 test_must_fail git rebase -i A
97 ) &&
98 test_path_is_file touch-one &&
99 test_path_is_file touch-two &&
100 test_path_is_missing touch-three " (should have stopped before)" &&
101 test_cmp_rev C HEAD &&
102 git rebase --continue &&
103 test_path_is_file touch-three &&
104 test_path_is_file "touch-file name with spaces" &&
105 test_path_is_file touch-after-semicolon &&
106 test_cmp_rev master HEAD &&
107 rm -f touch-*
110 test_expect_success 'rebase -i with the exec command runs from tree root' '
111 git checkout master &&
112 mkdir subdir && (cd subdir &&
113 set_fake_editor &&
114 FAKE_LINES="1 exec_>touch-subdir" \
115 git rebase -i HEAD^
116 ) &&
117 test_path_is_file touch-subdir &&
118 rm -fr subdir
121 test_expect_success 'rebase -i with exec allows git commands in subdirs' '
122 test_when_finished "rm -rf subdir" &&
123 test_when_finished "git rebase --abort ||:" &&
124 git checkout master &&
125 mkdir subdir && (cd subdir &&
126 set_fake_editor &&
127 FAKE_LINES="1 x_cd_subdir_&&_git_rev-parse_--is-inside-work-tree" \
128 git rebase -i HEAD^
132 test_expect_success 'rebase -i sets work tree properly' '
133 test_when_finished "rm -rf subdir" &&
134 test_when_finished "test_might_fail git rebase --abort" &&
135 mkdir subdir &&
136 git rebase -x "(cd subdir && git rev-parse --show-toplevel)" HEAD^ \
137 >actual &&
138 ! grep "/subdir$" actual
141 test_expect_success 'rebase -i with the exec command checks tree cleanness' '
142 git checkout master &&
143 set_fake_editor &&
144 test_must_fail env FAKE_LINES="exec_echo_foo_>file1 1" git rebase -i HEAD^ &&
145 test_cmp_rev master^ HEAD &&
146 git reset --hard &&
147 git rebase --continue
150 test_expect_success 'rebase -i with exec of inexistent command' '
151 git checkout master &&
152 test_when_finished "git rebase --abort" &&
153 set_fake_editor &&
154 test_must_fail env FAKE_LINES="exec_this-command-does-not-exist 1" \
155 git rebase -i HEAD^ >actual 2>&1 &&
156 ! grep "Maybe git-rebase is broken" actual
159 test_expect_success 'implicit interactive rebase does not invoke sequence editor' '
160 test_when_finished "git rebase --abort ||:" &&
161 GIT_SEQUENCE_EDITOR="echo bad >" git rebase -x"echo one" @^
164 test_expect_success 'no changes are a nop' '
165 git checkout branch2 &&
166 set_fake_editor &&
167 git rebase -i F &&
168 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
169 test $(git rev-parse I) = $(git rev-parse HEAD)
172 test_expect_success 'test the [branch] option' '
173 git checkout -b dead-end &&
174 git rm file6 &&
175 git commit -m "stop here" &&
176 set_fake_editor &&
177 git rebase -i F branch2 &&
178 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
179 test $(git rev-parse I) = $(git rev-parse branch2) &&
180 test $(git rev-parse I) = $(git rev-parse HEAD)
183 test_expect_success 'test --onto <branch>' '
184 git checkout -b test-onto branch2 &&
185 set_fake_editor &&
186 git rebase -i --onto branch1 F &&
187 test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" &&
188 test $(git rev-parse HEAD^) = $(git rev-parse branch1) &&
189 test $(git rev-parse I) = $(git rev-parse branch2)
192 test_expect_success 'rebase on top of a non-conflicting commit' '
193 git checkout branch1 &&
194 git tag original-branch1 &&
195 set_fake_editor &&
196 git rebase -i branch2 &&
197 test file6 = $(git diff --name-only original-branch1) &&
198 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
199 test $(git rev-parse I) = $(git rev-parse branch2) &&
200 test $(git rev-parse I) = $(git rev-parse HEAD~2)
203 test_expect_success 'reflog for the branch shows state before rebase' '
204 test $(git rev-parse branch1@{1}) = $(git rev-parse original-branch1)
207 test_expect_success 'reflog for the branch shows correct finish message' '
208 printf "rebase -i (finish): refs/heads/branch1 onto %s\n" \
209 "$(git rev-parse branch2)" >expected &&
210 git log -g --pretty=%gs -1 refs/heads/branch1 >actual &&
211 test_cmp expected actual
214 test_expect_success 'exchange two commits' '
215 set_fake_editor &&
216 FAKE_LINES="2 1" git rebase -i HEAD~2 &&
217 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
218 test G = $(git cat-file commit HEAD | sed -ne \$p)
221 cat > expect << EOF
222 diff --git a/file1 b/file1
223 index f70f10e..fd79235 100644
224 --- a/file1
225 +++ b/file1
226 @@ -1 +1 @@
231 cat > expect2 << EOF
232 <<<<<<< HEAD
234 =======
236 >>>>>>> 5d18e54... G
239 test_expect_success 'stop on conflicting pick' '
240 git tag new-branch1 &&
241 set_fake_editor &&
242 test_must_fail git rebase -i master &&
243 test "$(git rev-parse HEAD~3)" = "$(git rev-parse master)" &&
244 test_cmp expect .git/rebase-merge/patch &&
245 test_cmp expect2 file1 &&
246 test "$(git diff --name-status |
247 sed -n -e "/^U/s/^U[^a-z]*//p")" = file1 &&
248 test 4 = $(grep -v "^#" < .git/rebase-merge/done | wc -l) &&
249 test 0 = $(grep -c "^[^#]" < .git/rebase-merge/git-rebase-todo)
252 test_expect_success 'show conflicted patch' '
253 GIT_TRACE=1 git rebase --show-current-patch >/dev/null 2>stderr &&
254 grep "show.*REBASE_HEAD" stderr &&
255 # the original stopped-sha1 is abbreviated
256 stopped_sha1="$(git rev-parse $(cat ".git/rebase-merge/stopped-sha"))" &&
257 test "$(git rev-parse REBASE_HEAD)" = "$stopped_sha1"
260 test_expect_success 'abort' '
261 git rebase --abort &&
262 test $(git rev-parse new-branch1) = $(git rev-parse HEAD) &&
263 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
264 test_path_is_missing .git/rebase-merge
267 test_expect_success 'abort with error when new base cannot be checked out' '
268 git rm --cached file1 &&
269 git commit -m "remove file in base" &&
270 set_fake_editor &&
271 test_must_fail git rebase -i master > output 2>&1 &&
272 test_i18ngrep "The following untracked working tree files would be overwritten by checkout:" \
273 output &&
274 test_i18ngrep "file1" output &&
275 test_path_is_missing .git/rebase-merge &&
276 git reset --hard HEAD^
279 test_expect_success 'retain authorship' '
280 echo A > file7 &&
281 git add file7 &&
282 test_tick &&
283 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
284 git tag twerp &&
285 set_fake_editor &&
286 git rebase -i --onto master HEAD^ &&
287 git show HEAD | grep "^Author: Twerp Snog"
290 test_expect_success 'retain authorship w/ conflicts' '
291 oGIT_AUTHOR_NAME=$GIT_AUTHOR_NAME &&
292 test_when_finished "GIT_AUTHOR_NAME=\$oGIT_AUTHOR_NAME" &&
294 git reset --hard twerp &&
295 test_commit a conflict a conflict-a &&
296 git reset --hard twerp &&
298 GIT_AUTHOR_NAME=AttributeMe &&
299 export GIT_AUTHOR_NAME &&
300 test_commit b conflict b conflict-b &&
301 GIT_AUTHOR_NAME=$oGIT_AUTHOR_NAME &&
303 set_fake_editor &&
304 test_must_fail git rebase -i conflict-a &&
305 echo resolved >conflict &&
306 git add conflict &&
307 git rebase --continue &&
308 test $(git rev-parse conflict-a^0) = $(git rev-parse HEAD^) &&
309 git show >out &&
310 grep AttributeMe out
313 test_expect_success 'squash' '
314 git reset --hard twerp &&
315 echo B > file7 &&
316 test_tick &&
317 GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 &&
318 echo "******************************" &&
319 set_fake_editor &&
320 FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \
321 git rebase -i --onto master HEAD~2 &&
322 test B = $(cat file7) &&
323 test $(git rev-parse HEAD^) = $(git rev-parse master)
326 test_expect_success 'retain authorship when squashing' '
327 git show HEAD | grep "^Author: Twerp Snog"
330 test_expect_success REBASE_P '-p handles "no changes" gracefully' '
331 HEAD=$(git rev-parse HEAD) &&
332 set_fake_editor &&
333 git rebase -i -p HEAD^ &&
334 git update-index --refresh &&
335 git diff-files --quiet &&
336 git diff-index --quiet --cached HEAD -- &&
337 test $HEAD = $(git rev-parse HEAD)
340 test_expect_failure REBASE_P 'exchange two commits with -p' '
341 git checkout H &&
342 set_fake_editor &&
343 FAKE_LINES="2 1" git rebase -i -p HEAD~2 &&
344 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
345 test G = $(git cat-file commit HEAD | sed -ne \$p)
348 test_expect_success REBASE_P 'preserve merges with -p' '
349 git checkout -b to-be-preserved master^ &&
350 : > unrelated-file &&
351 git add unrelated-file &&
352 test_tick &&
353 git commit -m "unrelated" &&
354 git checkout -b another-branch master &&
355 echo B > file1 &&
356 test_tick &&
357 git commit -m J file1 &&
358 test_tick &&
359 git merge to-be-preserved &&
360 echo C > file1 &&
361 test_tick &&
362 git commit -m K file1 &&
363 echo D > file1 &&
364 test_tick &&
365 git commit -m L1 file1 &&
366 git checkout HEAD^ &&
367 echo 1 > unrelated-file &&
368 test_tick &&
369 git commit -m L2 unrelated-file &&
370 test_tick &&
371 git merge another-branch &&
372 echo E > file1 &&
373 test_tick &&
374 git commit -m M file1 &&
375 git checkout -b to-be-rebased &&
376 test_tick &&
377 set_fake_editor &&
378 git rebase -i -p --onto branch1 master &&
379 git update-index --refresh &&
380 git diff-files --quiet &&
381 git diff-index --quiet --cached HEAD -- &&
382 test $(git rev-parse HEAD~6) = $(git rev-parse branch1) &&
383 test $(git rev-parse HEAD~4^2) = $(git rev-parse to-be-preserved) &&
384 test $(git rev-parse HEAD^^2^) = $(git rev-parse HEAD^^^) &&
385 test $(git show HEAD~5:file1) = B &&
386 test $(git show HEAD~3:file1) = C &&
387 test $(git show HEAD:file1) = E &&
388 test $(git show HEAD:unrelated-file) = 1
391 test_expect_success REBASE_P 'edit ancestor with -p' '
392 set_fake_editor &&
393 FAKE_LINES="1 2 edit 3 4" git rebase -i -p HEAD~3 &&
394 echo 2 > unrelated-file &&
395 test_tick &&
396 git commit -m L2-modified --amend unrelated-file &&
397 git rebase --continue &&
398 git update-index --refresh &&
399 git diff-files --quiet &&
400 git diff-index --quiet --cached HEAD -- &&
401 test $(git show HEAD:unrelated-file) = 2
404 test_expect_success '--continue tries to commit' '
405 git reset --hard D &&
406 test_tick &&
407 set_fake_editor &&
408 test_must_fail git rebase -i --onto new-branch1 HEAD^ &&
409 echo resolved > file1 &&
410 git add file1 &&
411 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
412 test $(git rev-parse HEAD^) = $(git rev-parse new-branch1) &&
413 git show HEAD | grep chouette
416 test_expect_success 'verbose flag is heeded, even after --continue' '
417 git reset --hard master@{1} &&
418 test_tick &&
419 set_fake_editor &&
420 test_must_fail git rebase -v -i --onto new-branch1 HEAD^ &&
421 echo resolved > file1 &&
422 git add file1 &&
423 git rebase --continue > output &&
424 grep "^ file1 | 2 +-$" output
427 test_expect_success C_LOCALE_OUTPUT 'multi-squash only fires up editor once' '
428 base=$(git rev-parse HEAD~4) &&
429 set_fake_editor &&
430 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 squash 2 squash 3 squash 4" \
431 EXPECT_HEADER_COUNT=4 \
432 git rebase -i $base &&
433 test $base = $(git rev-parse HEAD^) &&
434 test 1 = $(git show | grep ONCE | wc -l)
437 test_expect_success C_LOCALE_OUTPUT 'multi-fixup does not fire up editor' '
438 git checkout -b multi-fixup E &&
439 base=$(git rev-parse HEAD~4) &&
440 set_fake_editor &&
441 FAKE_COMMIT_AMEND="NEVER" FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \
442 git rebase -i $base &&
443 test $base = $(git rev-parse HEAD^) &&
444 test 0 = $(git show | grep NEVER | wc -l) &&
445 git checkout @{-1} &&
446 git branch -D multi-fixup
449 test_expect_success 'commit message used after conflict' '
450 git checkout -b conflict-fixup conflict-branch &&
451 base=$(git rev-parse HEAD~4) &&
452 set_fake_editor &&
453 test_must_fail env FAKE_LINES="1 fixup 3 fixup 4" git rebase -i $base &&
454 echo three > conflict &&
455 git add conflict &&
456 FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \
457 git rebase --continue &&
458 test $base = $(git rev-parse HEAD^) &&
459 test 1 = $(git show | grep ONCE | wc -l) &&
460 git checkout @{-1} &&
461 git branch -D conflict-fixup
464 test_expect_success 'commit message retained after conflict' '
465 git checkout -b conflict-squash conflict-branch &&
466 base=$(git rev-parse HEAD~4) &&
467 set_fake_editor &&
468 test_must_fail env FAKE_LINES="1 fixup 3 squash 4" git rebase -i $base &&
469 echo three > conflict &&
470 git add conflict &&
471 FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \
472 git rebase --continue &&
473 test $base = $(git rev-parse HEAD^) &&
474 test 2 = $(git show | grep TWICE | wc -l) &&
475 git checkout @{-1} &&
476 git branch -D conflict-squash
479 cat > expect-squash-fixup << EOF
484 ONCE
487 test_expect_success C_LOCALE_OUTPUT 'squash and fixup generate correct log messages' '
488 git checkout -b squash-fixup E &&
489 base=$(git rev-parse HEAD~4) &&
490 set_fake_editor &&
491 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 fixup 2 squash 3 fixup 4" \
492 EXPECT_HEADER_COUNT=4 \
493 git rebase -i $base &&
494 git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup &&
495 test_cmp expect-squash-fixup actual-squash-fixup &&
496 git cat-file commit HEAD@{2} |
497 grep "^# This is a combination of 3 commits\." &&
498 git cat-file commit HEAD@{3} |
499 grep "^# This is a combination of 2 commits\." &&
500 git checkout @{-1} &&
501 git branch -D squash-fixup
504 test_expect_success C_LOCALE_OUTPUT 'squash ignores comments' '
505 git checkout -b skip-comments E &&
506 base=$(git rev-parse HEAD~4) &&
507 set_fake_editor &&
508 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \
509 EXPECT_HEADER_COUNT=4 \
510 git rebase -i $base &&
511 test $base = $(git rev-parse HEAD^) &&
512 test 1 = $(git show | grep ONCE | wc -l) &&
513 git checkout @{-1} &&
514 git branch -D skip-comments
517 test_expect_success C_LOCALE_OUTPUT 'squash ignores blank lines' '
518 git checkout -b skip-blank-lines E &&
519 base=$(git rev-parse HEAD~4) &&
520 set_fake_editor &&
521 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \
522 EXPECT_HEADER_COUNT=4 \
523 git rebase -i $base &&
524 test $base = $(git rev-parse HEAD^) &&
525 test 1 = $(git show | grep ONCE | wc -l) &&
526 git checkout @{-1} &&
527 git branch -D skip-blank-lines
530 test_expect_success 'squash works as expected' '
531 git checkout -b squash-works no-conflict-branch &&
532 one=$(git rev-parse HEAD~3) &&
533 set_fake_editor &&
534 FAKE_LINES="1 s 3 2" EXPECT_HEADER_COUNT=2 \
535 git rebase -i HEAD~3 &&
536 test $one = $(git rev-parse HEAD~2)
539 test_expect_success 'interrupted squash works as expected' '
540 git checkout -b interrupted-squash conflict-branch &&
541 one=$(git rev-parse HEAD~3) &&
542 set_fake_editor &&
543 test_must_fail env FAKE_LINES="1 squash 3 2" git rebase -i HEAD~3 &&
544 test_write_lines one two four > conflict &&
545 git add conflict &&
546 test_must_fail git rebase --continue &&
547 echo resolved > conflict &&
548 git add conflict &&
549 git rebase --continue &&
550 test $one = $(git rev-parse HEAD~2)
553 test_expect_success 'interrupted squash works as expected (case 2)' '
554 git checkout -b interrupted-squash2 conflict-branch &&
555 one=$(git rev-parse HEAD~3) &&
556 set_fake_editor &&
557 test_must_fail env FAKE_LINES="3 squash 1 2" git rebase -i HEAD~3 &&
558 test_write_lines one four > conflict &&
559 git add conflict &&
560 test_must_fail git rebase --continue &&
561 test_write_lines one two four > conflict &&
562 git add conflict &&
563 test_must_fail git rebase --continue &&
564 echo resolved > conflict &&
565 git add conflict &&
566 git rebase --continue &&
567 test $one = $(git rev-parse HEAD~2)
570 test_expect_success '--continue tries to commit, even for "edit"' '
571 echo unrelated > file7 &&
572 git add file7 &&
573 test_tick &&
574 git commit -m "unrelated change" &&
575 parent=$(git rev-parse HEAD^) &&
576 test_tick &&
577 set_fake_editor &&
578 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
579 echo edited > file7 &&
580 git add file7 &&
581 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
582 test edited = $(git show HEAD:file7) &&
583 git show HEAD | grep chouette &&
584 test $parent = $(git rev-parse HEAD^)
587 test_expect_success 'aborted --continue does not squash commits after "edit"' '
588 old=$(git rev-parse HEAD) &&
589 test_tick &&
590 set_fake_editor &&
591 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
592 echo "edited again" > file7 &&
593 git add file7 &&
594 test_must_fail env FAKE_COMMIT_MESSAGE=" " git rebase --continue &&
595 test $old = $(git rev-parse HEAD) &&
596 git rebase --abort
599 test_expect_success 'auto-amend only edited commits after "edit"' '
600 test_tick &&
601 set_fake_editor &&
602 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
603 echo "edited again" > file7 &&
604 git add file7 &&
605 FAKE_COMMIT_MESSAGE="edited file7 again" git commit &&
606 echo "and again" > file7 &&
607 git add file7 &&
608 test_tick &&
609 test_must_fail env FAKE_COMMIT_MESSAGE="and again" git rebase --continue &&
610 git rebase --abort
613 test_expect_success 'clean error after failed "exec"' '
614 test_tick &&
615 test_when_finished "git rebase --abort || :" &&
616 set_fake_editor &&
617 test_must_fail env FAKE_LINES="1 exec_false" git rebase -i HEAD^ &&
618 echo "edited again" > file7 &&
619 git add file7 &&
620 test_must_fail git rebase --continue 2>error &&
621 test_i18ngrep "you have staged changes in your working tree" error
624 test_expect_success 'rebase a detached HEAD' '
625 grandparent=$(git rev-parse HEAD~2) &&
626 git checkout $(git rev-parse HEAD) &&
627 test_tick &&
628 set_fake_editor &&
629 FAKE_LINES="2 1" git rebase -i HEAD~2 &&
630 test $grandparent = $(git rev-parse HEAD~2)
633 test_expect_success 'rebase a commit violating pre-commit' '
635 mkdir -p .git/hooks &&
636 write_script .git/hooks/pre-commit <<-\EOF &&
637 test -z "$(git diff --cached --check)"
639 echo "monde! " >> file1 &&
640 test_tick &&
641 test_must_fail git commit -m doesnt-verify file1 &&
642 git commit -m doesnt-verify --no-verify file1 &&
643 test_tick &&
644 set_fake_editor &&
645 FAKE_LINES=2 git rebase -i HEAD~2
649 test_expect_success 'rebase with a file named HEAD in worktree' '
651 rm -fr .git/hooks &&
652 git reset --hard &&
653 git checkout -b branch3 A &&
656 GIT_AUTHOR_NAME="Squashed Away" &&
657 export GIT_AUTHOR_NAME &&
658 >HEAD &&
659 git add HEAD &&
660 git commit -m "Add head" &&
661 >BODY &&
662 git add BODY &&
663 git commit -m "Add body"
664 ) &&
666 set_fake_editor &&
667 FAKE_LINES="1 squash 2" git rebase -i @{-1} &&
668 test "$(git show -s --pretty=format:%an)" = "Squashed Away"
672 test_expect_success 'do "noop" when there is nothing to cherry-pick' '
674 git checkout -b branch4 HEAD &&
675 GIT_EDITOR=: git commit --amend \
676 --author="Somebody else <somebody@else.com>" &&
677 test $(git rev-parse branch3) != $(git rev-parse branch4) &&
678 set_fake_editor &&
679 git rebase -i branch3 &&
680 test $(git rev-parse branch3) = $(git rev-parse branch4)
684 test_expect_success 'submodule rebase setup' '
685 git checkout A &&
686 mkdir sub &&
688 cd sub && git init && >elif &&
689 git add elif && git commit -m "submodule initial"
690 ) &&
691 echo 1 >file1 &&
692 git add file1 sub &&
693 test_tick &&
694 git commit -m "One" &&
695 echo 2 >file1 &&
696 test_tick &&
697 git commit -a -m "Two" &&
699 cd sub && echo 3 >elif &&
700 git commit -a -m "submodule second"
701 ) &&
702 test_tick &&
703 set_fake_editor &&
704 git commit -a -m "Three changes submodule"
707 test_expect_success 'submodule rebase -i' '
708 set_fake_editor &&
709 FAKE_LINES="1 squash 2 3" git rebase -i A
712 test_expect_success 'submodule conflict setup' '
713 git tag submodule-base &&
714 git checkout HEAD^ &&
716 cd sub && git checkout HEAD^ && echo 4 >elif &&
717 git add elif && git commit -m "submodule conflict"
718 ) &&
719 git add sub &&
720 test_tick &&
721 git commit -m "Conflict in submodule" &&
722 git tag submodule-topic
725 test_expect_success 'rebase -i continue with only submodule staged' '
726 set_fake_editor &&
727 test_must_fail git rebase -i submodule-base &&
728 git add sub &&
729 git rebase --continue &&
730 test $(git rev-parse submodule-base) != $(git rev-parse HEAD)
733 test_expect_success 'rebase -i continue with unstaged submodule' '
734 git checkout submodule-topic &&
735 git reset --hard &&
736 set_fake_editor &&
737 test_must_fail git rebase -i submodule-base &&
738 git reset &&
739 git rebase --continue &&
740 test $(git rev-parse submodule-base) = $(git rev-parse HEAD)
743 test_expect_success 'avoid unnecessary reset' '
744 git checkout master &&
745 git reset --hard &&
746 test-tool chmtime =123456789 file3 &&
747 git update-index --refresh &&
748 HEAD=$(git rev-parse HEAD) &&
749 set_fake_editor &&
750 git rebase -i HEAD~4 &&
751 test $HEAD = $(git rev-parse HEAD) &&
752 MTIME=$(test-tool chmtime --get file3) &&
753 test 123456789 = $MTIME
756 test_expect_success 'reword' '
757 git checkout -b reword-branch master &&
758 set_fake_editor &&
759 FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" git rebase -i A &&
760 git show HEAD | grep "E changed" &&
761 test $(git rev-parse master) != $(git rev-parse HEAD) &&
762 test $(git rev-parse master^) = $(git rev-parse HEAD^) &&
763 FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" git rebase -i A &&
764 git show HEAD^ | grep "D changed" &&
765 FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" git rebase -i A &&
766 git show HEAD~3 | grep "B changed" &&
767 FAKE_LINES="1 r 2 pick 3 p 4" FAKE_COMMIT_MESSAGE="C changed" git rebase -i A &&
768 git show HEAD~2 | grep "C changed"
771 test_expect_success 'rebase -i can copy notes' '
772 git config notes.rewrite.rebase true &&
773 git config notes.rewriteRef "refs/notes/*" &&
774 test_commit n1 &&
775 test_commit n2 &&
776 test_commit n3 &&
777 git notes add -m"a note" n3 &&
778 set_fake_editor &&
779 git rebase -i --onto n1 n2 &&
780 test "a note" = "$(git notes show HEAD)"
783 cat >expect <<EOF
784 an earlier note
786 a note
789 test_expect_success 'rebase -i can copy notes over a fixup' '
790 git reset --hard n3 &&
791 git notes add -m"an earlier note" n2 &&
792 set_fake_editor &&
793 GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 f 2" git rebase -i n1 &&
794 git notes show > output &&
795 test_cmp expect output
798 test_expect_success 'rebase while detaching HEAD' '
799 git symbolic-ref HEAD &&
800 grandparent=$(git rev-parse HEAD~2) &&
801 test_tick &&
802 set_fake_editor &&
803 FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0 &&
804 test $grandparent = $(git rev-parse HEAD~2) &&
805 test_must_fail git symbolic-ref HEAD
808 test_tick # Ensure that the rebased commits get a different timestamp.
809 test_expect_success 'always cherry-pick with --no-ff' '
810 git checkout no-ff-branch &&
811 git tag original-no-ff-branch &&
812 set_fake_editor &&
813 git rebase -i --no-ff A &&
814 for p in 0 1 2
816 test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) &&
817 git diff HEAD~$p original-no-ff-branch~$p > out &&
818 test_must_be_empty out
819 done &&
820 test $(git rev-parse HEAD~3) = $(git rev-parse original-no-ff-branch~3) &&
821 git diff HEAD~3 original-no-ff-branch~3 > out &&
822 test_must_be_empty out
825 test_expect_success 'set up commits with funny messages' '
826 git checkout -b funny A &&
827 echo >>file1 &&
828 test_tick &&
829 git commit -a -m "end with slash\\" &&
830 echo >>file1 &&
831 test_tick &&
832 git commit -a -m "something (\000) that looks like octal" &&
833 echo >>file1 &&
834 test_tick &&
835 git commit -a -m "something (\n) that looks like a newline" &&
836 echo >>file1 &&
837 test_tick &&
838 git commit -a -m "another commit"
841 test_expect_success 'rebase-i history with funny messages' '
842 git rev-list A..funny >expect &&
843 test_tick &&
844 set_fake_editor &&
845 FAKE_LINES="1 2 3 4" git rebase -i A &&
846 git rev-list A.. >actual &&
847 test_cmp expect actual
850 test_expect_success 'prepare for rebase -i --exec' '
851 git checkout master &&
852 git checkout -b execute &&
853 test_commit one_exec main.txt one_exec &&
854 test_commit two_exec main.txt two_exec &&
855 test_commit three_exec main.txt three_exec
858 test_expect_success 'running "git rebase -i --exec git show HEAD"' '
859 set_fake_editor &&
860 git rebase -i --exec "git show HEAD" HEAD~2 >actual &&
862 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
863 export FAKE_LINES &&
864 git rebase -i HEAD~2 >expect
865 ) &&
866 sed -e "1,9d" expect >expected &&
867 test_cmp expected actual
870 test_expect_success 'running "git rebase --exec git show HEAD -i"' '
871 git reset --hard execute &&
872 set_fake_editor &&
873 git rebase --exec "git show HEAD" -i HEAD~2 >actual &&
875 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
876 export FAKE_LINES &&
877 git rebase -i HEAD~2 >expect
878 ) &&
879 sed -e "1,9d" expect >expected &&
880 test_cmp expected actual
883 test_expect_success 'running "git rebase -ix git show HEAD"' '
884 git reset --hard execute &&
885 set_fake_editor &&
886 git rebase -ix "git show HEAD" HEAD~2 >actual &&
888 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
889 export FAKE_LINES &&
890 git rebase -i HEAD~2 >expect
891 ) &&
892 sed -e "1,9d" expect >expected &&
893 test_cmp expected actual
897 test_expect_success 'rebase -ix with several <CMD>' '
898 git reset --hard execute &&
899 set_fake_editor &&
900 git rebase -ix "git show HEAD; pwd" HEAD~2 >actual &&
902 FAKE_LINES="1 exec_git_show_HEAD;_pwd 2 exec_git_show_HEAD;_pwd" &&
903 export FAKE_LINES &&
904 git rebase -i HEAD~2 >expect
905 ) &&
906 sed -e "1,9d" expect >expected &&
907 test_cmp expected actual
910 test_expect_success 'rebase -ix with several instances of --exec' '
911 git reset --hard execute &&
912 set_fake_editor &&
913 git rebase -i --exec "git show HEAD" --exec "pwd" HEAD~2 >actual &&
915 FAKE_LINES="1 exec_git_show_HEAD exec_pwd 2
916 exec_git_show_HEAD exec_pwd" &&
917 export FAKE_LINES &&
918 git rebase -i HEAD~2 >expect
919 ) &&
920 sed -e "1,11d" expect >expected &&
921 test_cmp expected actual
924 test_expect_success C_LOCALE_OUTPUT 'rebase -ix with --autosquash' '
925 git reset --hard execute &&
926 git checkout -b autosquash &&
927 echo second >second.txt &&
928 git add second.txt &&
929 git commit -m "fixup! two_exec" &&
930 echo bis >bis.txt &&
931 git add bis.txt &&
932 git commit -m "fixup! two_exec" &&
933 set_fake_editor &&
935 git checkout -b autosquash_actual &&
936 git rebase -i --exec "git show HEAD" --autosquash HEAD~4 >actual
937 ) &&
938 git checkout autosquash &&
940 git checkout -b autosquash_expected &&
941 FAKE_LINES="1 fixup 3 fixup 4 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
942 export FAKE_LINES &&
943 git rebase -i HEAD~4 >expect
944 ) &&
945 sed -e "1,13d" expect >expected &&
946 test_cmp expected actual
949 test_expect_success 'rebase --exec works without -i ' '
950 git reset --hard execute &&
951 rm -rf exec_output &&
952 EDITOR="echo >invoked_editor" git rebase --exec "echo a line >>exec_output" HEAD~2 2>actual &&
953 test_i18ngrep "Successfully rebased and updated" actual &&
954 test_line_count = 2 exec_output &&
955 test_path_is_missing invoked_editor
958 test_expect_success 'rebase -i --exec without <CMD>' '
959 git reset --hard execute &&
960 set_fake_editor &&
961 test_must_fail git rebase -i --exec 2>actual &&
962 test_i18ngrep "requires a value" actual &&
963 git checkout master
966 test_expect_success 'rebase -i --root re-order and drop commits' '
967 git checkout E &&
968 set_fake_editor &&
969 FAKE_LINES="3 1 2 5" git rebase -i --root &&
970 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
971 test B = $(git cat-file commit HEAD^ | sed -ne \$p) &&
972 test A = $(git cat-file commit HEAD^^ | sed -ne \$p) &&
973 test C = $(git cat-file commit HEAD^^^ | sed -ne \$p) &&
974 test 0 = $(git cat-file commit HEAD^^^ | grep -c ^parent\ )
977 test_expect_success 'rebase -i --root retain root commit author and message' '
978 git checkout A &&
979 echo B >file7 &&
980 git add file7 &&
981 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
982 set_fake_editor &&
983 FAKE_LINES="2" git rebase -i --root &&
984 git cat-file commit HEAD | grep -q "^author Twerp Snog" &&
985 git cat-file commit HEAD | grep -q "^different author$"
988 test_expect_success 'rebase -i --root temporary sentinel commit' '
989 git checkout B &&
990 set_fake_editor &&
991 test_must_fail env FAKE_LINES="2" git rebase -i --root &&
992 git cat-file commit HEAD | grep "^tree 4b825dc642cb" &&
993 git rebase --abort
996 test_expect_success 'rebase -i --root fixup root commit' '
997 git checkout B &&
998 set_fake_editor &&
999 FAKE_LINES="1 fixup 2" git rebase -i --root &&
1000 test A = $(git cat-file commit HEAD | sed -ne \$p) &&
1001 test B = $(git show HEAD:file1) &&
1002 test 0 = $(git cat-file commit HEAD | grep -c ^parent\ )
1005 test_expect_success 'rebase -i --root reword root commit' '
1006 test_when_finished "test_might_fail git rebase --abort" &&
1007 git checkout -b reword-root-branch master &&
1008 set_fake_editor &&
1009 FAKE_LINES="reword 1 2" FAKE_COMMIT_MESSAGE="A changed" \
1010 git rebase -i --root &&
1011 git show HEAD^ | grep "A changed" &&
1012 test -z "$(git show -s --format=%p HEAD^)"
1015 test_expect_success 'rebase -i --root when root has untracked file confilct' '
1016 test_when_finished "reset_rebase" &&
1017 git checkout -b failing-root-pick A &&
1018 echo x >file2 &&
1019 git rm file1 &&
1020 git commit -m "remove file 1 add file 2" &&
1021 echo z >file1 &&
1022 set_fake_editor &&
1023 test_must_fail env FAKE_LINES="1 2" git rebase -i --root &&
1024 rm file1 &&
1025 git rebase --continue &&
1026 test "$(git log -1 --format=%B)" = "remove file 1 add file 2" &&
1027 test "$(git rev-list --count HEAD)" = 2
1030 test_expect_success 'rebase -i --root reword root when root has untracked file conflict' '
1031 test_when_finished "reset_rebase" &&
1032 echo z>file1 &&
1033 set_fake_editor &&
1034 test_must_fail env FAKE_LINES="reword 1 2" \
1035 FAKE_COMMIT_MESSAGE="Modified A" git rebase -i --root &&
1036 rm file1 &&
1037 FAKE_COMMIT_MESSAGE="Reworded A" git rebase --continue &&
1038 test "$(git log -1 --format=%B HEAD^)" = "Reworded A" &&
1039 test "$(git rev-list --count HEAD)" = 2
1042 test_expect_success C_LOCALE_OUTPUT 'rebase --edit-todo does not work on non-interactive rebase' '
1043 git checkout reword-root-branch &&
1044 git reset --hard &&
1045 git checkout conflict-branch &&
1046 set_fake_editor &&
1047 test_must_fail git rebase --onto HEAD~2 HEAD~ &&
1048 test_must_fail git rebase --edit-todo &&
1049 git rebase --abort
1052 test_expect_success 'rebase --edit-todo can be used to modify todo' '
1053 git reset --hard &&
1054 git checkout no-conflict-branch^0 &&
1055 set_fake_editor &&
1056 FAKE_LINES="edit 1 2 3" git rebase -i HEAD~3 &&
1057 FAKE_LINES="2 1" git rebase --edit-todo &&
1058 git rebase --continue &&
1059 test M = $(git cat-file commit HEAD^ | sed -ne \$p) &&
1060 test L = $(git cat-file commit HEAD | sed -ne \$p)
1063 test_expect_success 'rebase -i produces readable reflog' '
1064 git reset --hard &&
1065 git branch -f branch-reflog-test H &&
1066 set_fake_editor &&
1067 git rebase -i --onto I F branch-reflog-test &&
1068 cat >expect <<-\EOF &&
1069 rebase -i (finish): returning to refs/heads/branch-reflog-test
1070 rebase -i (pick): H
1071 rebase -i (pick): G
1072 rebase -i (start): checkout I
1074 git reflog -n4 HEAD |
1075 sed "s/[^:]*: //" >actual &&
1076 test_cmp expect actual
1079 test_expect_success 'rebase -i respects core.commentchar' '
1080 git reset --hard &&
1081 git checkout E^0 &&
1082 test_config core.commentchar "\\" &&
1083 write_script remove-all-but-first.sh <<-\EOF &&
1084 sed -e "2,\$s/^/\\\\/" "$1" >"$1.tmp" &&
1085 mv "$1.tmp" "$1"
1087 test_set_editor "$(pwd)/remove-all-but-first.sh" &&
1088 git rebase -i B &&
1089 test B = $(git cat-file commit HEAD^ | sed -ne \$p)
1092 test_expect_success 'rebase -i respects core.commentchar=auto' '
1093 test_config core.commentchar auto &&
1094 write_script copy-edit-script.sh <<-\EOF &&
1095 cp "$1" edit-script
1097 test_set_editor "$(pwd)/copy-edit-script.sh" &&
1098 test_when_finished "git rebase --abort || :" &&
1099 git rebase -i HEAD^ &&
1100 test -z "$(grep -ve "^#" -e "^\$" -e "^pick" edit-script)"
1103 test_expect_success 'rebase -i, with <onto> and <upstream> specified as :/quuxery' '
1104 test_when_finished "git branch -D torebase" &&
1105 git checkout -b torebase branch1 &&
1106 upstream=$(git rev-parse ":/J") &&
1107 onto=$(git rev-parse ":/A") &&
1108 git rebase --onto $onto $upstream &&
1109 git reset --hard branch1 &&
1110 git rebase --onto ":/A" ":/J" &&
1111 git checkout branch1
1114 test_expect_success 'rebase -i with --strategy and -X' '
1115 git checkout -b conflict-merge-use-theirs conflict-branch &&
1116 git reset --hard HEAD^ &&
1117 echo five >conflict &&
1118 echo Z >file1 &&
1119 git commit -a -m "one file conflict" &&
1120 EDITOR=true git rebase -i --strategy=recursive -Xours conflict-branch &&
1121 test $(git show conflict-branch:conflict) = $(cat conflict) &&
1122 test $(cat file1) = Z
1125 test_expect_success 'interrupted rebase -i with --strategy and -X' '
1126 git checkout -b conflict-merge-use-theirs-interrupted conflict-branch &&
1127 git reset --hard HEAD^ &&
1128 >breakpoint &&
1129 git add breakpoint &&
1130 git commit -m "breakpoint for interactive mode" &&
1131 echo five >conflict &&
1132 echo Z >file1 &&
1133 git commit -a -m "one file conflict" &&
1134 set_fake_editor &&
1135 FAKE_LINES="edit 1 2" git rebase -i --strategy=recursive -Xours conflict-branch &&
1136 git rebase --continue &&
1137 test $(git show conflict-branch:conflict) = $(cat conflict) &&
1138 test $(cat file1) = Z
1141 test_expect_success 'rebase -i error on commits with \ in message' '
1142 current_head=$(git rev-parse HEAD) &&
1143 test_when_finished "git rebase --abort; git reset --hard $current_head; rm -f error" &&
1144 test_commit TO-REMOVE will-conflict old-content &&
1145 test_commit "\temp" will-conflict new-content dummy &&
1146 test_must_fail env EDITOR=true git rebase -i HEAD^ --onto HEAD^^ 2>error &&
1147 test_expect_code 1 grep " emp" error
1150 test_expect_success 'short SHA-1 setup' '
1151 test_when_finished "git checkout master" &&
1152 git checkout --orphan collide &&
1153 git rm -rf . &&
1155 unset test_tick &&
1156 test_commit collide1 collide &&
1157 test_commit --notick collide2 collide &&
1158 test_commit --notick collide3 collide
1162 test_expect_success 'short SHA-1 collide' '
1163 test_when_finished "reset_rebase && git checkout master" &&
1164 git checkout collide &&
1166 unset test_tick &&
1167 test_tick &&
1168 set_fake_editor &&
1169 FAKE_COMMIT_MESSAGE="collide2 ac4f2ee" \
1170 FAKE_LINES="reword 1 2" git rebase -i HEAD~2
1174 test_expect_success 'respect core.abbrev' '
1175 git config core.abbrev 12 &&
1176 set_cat_todo_editor &&
1177 test_must_fail git rebase -i HEAD~4 >todo-list &&
1178 test 4 = $(grep -c "pick [0-9a-f]\{12,\}" todo-list)
1181 test_expect_success 'todo count' '
1182 write_script dump-raw.sh <<-\EOF &&
1183 cat "$1"
1185 test_set_editor "$(pwd)/dump-raw.sh" &&
1186 git rebase -i HEAD~4 >actual &&
1187 test_i18ngrep "^# Rebase ..* onto ..* ([0-9]" actual
1190 test_expect_success 'rebase -i commits that overwrite untracked files (pick)' '
1191 git checkout --force branch2 &&
1192 git clean -f &&
1193 set_fake_editor &&
1194 FAKE_LINES="edit 1 2" git rebase -i A &&
1195 test_cmp_rev HEAD F &&
1196 test_path_is_missing file6 &&
1197 >file6 &&
1198 test_must_fail git rebase --continue &&
1199 test_cmp_rev HEAD F &&
1200 rm file6 &&
1201 git rebase --continue &&
1202 test_cmp_rev HEAD I
1205 test_expect_success 'rebase -i commits that overwrite untracked files (squash)' '
1206 git checkout --force branch2 &&
1207 git clean -f &&
1208 git tag original-branch2 &&
1209 set_fake_editor &&
1210 FAKE_LINES="edit 1 squash 2" git rebase -i A &&
1211 test_cmp_rev HEAD F &&
1212 test_path_is_missing file6 &&
1213 >file6 &&
1214 test_must_fail git rebase --continue &&
1215 test_cmp_rev HEAD F &&
1216 rm file6 &&
1217 git rebase --continue &&
1218 test $(git cat-file commit HEAD | sed -ne \$p) = I &&
1219 git reset --hard original-branch2
1222 test_expect_success 'rebase -i commits that overwrite untracked files (no ff)' '
1223 git checkout --force branch2 &&
1224 git clean -f &&
1225 set_fake_editor &&
1226 FAKE_LINES="edit 1 2" git rebase -i --no-ff A &&
1227 test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1228 test_path_is_missing file6 &&
1229 >file6 &&
1230 test_must_fail git rebase --continue &&
1231 test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1232 rm file6 &&
1233 git rebase --continue &&
1234 test $(git cat-file commit HEAD | sed -ne \$p) = I
1237 test_expect_success 'rebase --continue removes CHERRY_PICK_HEAD' '
1238 git checkout -b commit-to-skip &&
1239 for double in X 3 1
1241 test_seq 5 | sed "s/$double/&&/" >seq &&
1242 git add seq &&
1243 test_tick &&
1244 git commit -m seq-$double
1245 done &&
1246 git tag seq-onto &&
1247 git reset --hard HEAD~2 &&
1248 git cherry-pick seq-onto &&
1249 set_fake_editor &&
1250 test_must_fail env FAKE_LINES= git rebase -i seq-onto &&
1251 test -d .git/rebase-merge &&
1252 git rebase --continue &&
1253 git diff --exit-code seq-onto &&
1254 test ! -d .git/rebase-merge &&
1255 test ! -f .git/CHERRY_PICK_HEAD
1258 rebase_setup_and_clean () {
1259 test_when_finished "
1260 git checkout master &&
1261 test_might_fail git branch -D $1 &&
1262 test_might_fail git rebase --abort
1263 " &&
1264 git checkout -b $1 ${2:-master}
1267 test_expect_success 'drop' '
1268 rebase_setup_and_clean drop-test &&
1269 set_fake_editor &&
1270 FAKE_LINES="1 drop 2 3 d 4 5" git rebase -i --root &&
1271 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1272 test C = $(git cat-file commit HEAD^ | sed -ne \$p) &&
1273 test A = $(git cat-file commit HEAD^^ | sed -ne \$p)
1276 test_expect_success 'rebase -i respects rebase.missingCommitsCheck = ignore' '
1277 test_config rebase.missingCommitsCheck ignore &&
1278 rebase_setup_and_clean missing-commit &&
1279 set_fake_editor &&
1280 FAKE_LINES="1 2 3 4" \
1281 git rebase -i --root 2>actual &&
1282 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1283 test_i18ngrep \
1284 "Successfully rebased and updated refs/heads/missing-commit" \
1285 actual
1288 cat >expect <<EOF
1289 Warning: some commits may have been dropped accidentally.
1290 Dropped commits (newer to older):
1291 - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
1292 To avoid this message, use "drop" to explicitly remove a commit.
1294 Use 'git config rebase.missingCommitsCheck' to change the level of warnings.
1295 The possible behaviours are: ignore, warn, error.
1297 Rebasing (1/4)
1298 Rebasing (2/4)
1299 Rebasing (3/4)
1300 Rebasing (4/4)
1301 Successfully rebased and updated refs/heads/missing-commit.
1304 cr_to_nl () {
1305 tr '\015' '\012'
1308 test_expect_success 'rebase -i respects rebase.missingCommitsCheck = warn' '
1309 test_config rebase.missingCommitsCheck warn &&
1310 rebase_setup_and_clean missing-commit &&
1311 set_fake_editor &&
1312 FAKE_LINES="1 2 3 4" \
1313 git rebase -i --root 2>actual.2 &&
1314 cr_to_nl <actual.2 >actual &&
1315 test_i18ncmp expect actual &&
1316 test D = $(git cat-file commit HEAD | sed -ne \$p)
1319 cat >expect <<EOF
1320 Warning: some commits may have been dropped accidentally.
1321 Dropped commits (newer to older):
1322 - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
1323 - $(git rev-list --pretty=oneline --abbrev-commit -1 master~2)
1324 To avoid this message, use "drop" to explicitly remove a commit.
1326 Use 'git config rebase.missingCommitsCheck' to change the level of warnings.
1327 The possible behaviours are: ignore, warn, error.
1329 You can fix this with 'git rebase --edit-todo' and then run 'git rebase --continue'.
1330 Or you can abort the rebase with 'git rebase --abort'.
1333 test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' '
1334 test_config rebase.missingCommitsCheck error &&
1335 rebase_setup_and_clean missing-commit &&
1336 set_fake_editor &&
1337 test_must_fail env FAKE_LINES="1 2 4" \
1338 git rebase -i --root 2>actual &&
1339 test_i18ncmp expect actual &&
1340 cp .git/rebase-merge/git-rebase-todo.backup \
1341 .git/rebase-merge/git-rebase-todo &&
1342 FAKE_LINES="1 2 drop 3 4 drop 5" \
1343 git rebase --edit-todo &&
1344 git rebase --continue &&
1345 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1346 test B = $(git cat-file commit HEAD^ | sed -ne \$p)
1349 test_expect_success 'respects rebase.abbreviateCommands with fixup, squash and exec' '
1350 rebase_setup_and_clean abbrevcmd &&
1351 test_commit "first" file1.txt "first line" first &&
1352 test_commit "second" file1.txt "another line" second &&
1353 test_commit "fixup! first" file2.txt "first line again" first_fixup &&
1354 test_commit "squash! second" file1.txt "another line here" second_squash &&
1355 cat >expected <<-EOF &&
1356 p $(git rev-list --abbrev-commit -1 first) first
1357 f $(git rev-list --abbrev-commit -1 first_fixup) fixup! first
1358 x git show HEAD
1359 p $(git rev-list --abbrev-commit -1 second) second
1360 s $(git rev-list --abbrev-commit -1 second_squash) squash! second
1361 x git show HEAD
1363 git checkout abbrevcmd &&
1364 set_cat_todo_editor &&
1365 test_config rebase.abbreviateCommands true &&
1366 test_must_fail git rebase -i --exec "git show HEAD" \
1367 --autosquash master >actual &&
1368 test_cmp expected actual
1371 test_expect_success 'static check of bad command' '
1372 rebase_setup_and_clean bad-cmd &&
1373 set_fake_editor &&
1374 test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \
1375 git rebase -i --root 2>actual &&
1376 test_i18ngrep "badcmd $(git rev-list --oneline -1 master~1)" actual &&
1377 test_i18ngrep "You can fix this with .git rebase --edit-todo.." actual &&
1378 FAKE_LINES="1 2 3 drop 4 5" git rebase --edit-todo &&
1379 git rebase --continue &&
1380 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1381 test C = $(git cat-file commit HEAD^ | sed -ne \$p)
1384 test_expect_success 'tabs and spaces are accepted in the todolist' '
1385 rebase_setup_and_clean indented-comment &&
1386 write_script add-indent.sh <<-\EOF &&
1388 # Turn single spaces into space/tab mix
1389 sed "1s/ / /g; 2s/ / /g; 3s/ / /g" "$1"
1390 printf "\n\t# comment\n #more\n\t # comment\n"
1391 ) >"$1.new"
1392 mv "$1.new" "$1"
1394 test_set_editor "$(pwd)/add-indent.sh" &&
1395 git rebase -i HEAD^^^ &&
1396 test E = $(git cat-file commit HEAD | sed -ne \$p)
1399 test_expect_success 'static check of bad SHA-1' '
1400 rebase_setup_and_clean bad-sha &&
1401 set_fake_editor &&
1402 test_must_fail env FAKE_LINES="1 2 edit fakesha 3 4 5 #" \
1403 git rebase -i --root 2>actual &&
1404 test_i18ngrep "edit XXXXXXX False commit" actual &&
1405 test_i18ngrep "You can fix this with .git rebase --edit-todo.." actual &&
1406 FAKE_LINES="1 2 4 5 6" git rebase --edit-todo &&
1407 git rebase --continue &&
1408 test E = $(git cat-file commit HEAD | sed -ne \$p)
1411 test_expect_success 'editor saves as CR/LF' '
1412 git checkout -b with-crlf &&
1413 write_script add-crs.sh <<-\EOF &&
1414 sed -e "s/\$/Q/" <"$1" | tr Q "\\015" >"$1".new &&
1415 mv -f "$1".new "$1"
1418 test_set_editor "$(pwd)/add-crs.sh" &&
1419 git rebase -i HEAD^
1423 SQ="'"
1424 test_expect_success 'rebase -i --gpg-sign=<key-id>' '
1425 test_when_finished "test_might_fail git rebase --abort" &&
1426 set_fake_editor &&
1427 FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" HEAD^ \
1428 >out 2>err &&
1429 test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err
1432 test_expect_success 'rebase -i --gpg-sign=<key-id> overrides commit.gpgSign' '
1433 test_when_finished "test_might_fail git rebase --abort" &&
1434 test_config commit.gpgsign true &&
1435 set_fake_editor &&
1436 FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" HEAD^ \
1437 >out 2>err &&
1438 test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err
1441 test_expect_success 'valid author header after --root swap' '
1442 rebase_setup_and_clean author-header no-conflict-branch &&
1443 set_fake_editor &&
1444 git commit --amend --author="Au ${SQ}thor <author@example.com>" --no-edit &&
1445 git cat-file commit HEAD | grep ^author >expected &&
1446 FAKE_LINES="5 1" git rebase -i --root &&
1447 git cat-file commit HEAD^ | grep ^author >actual &&
1448 test_cmp expected actual
1451 test_expect_success 'valid author header when author contains single quote' '
1452 rebase_setup_and_clean author-header no-conflict-branch &&
1453 set_fake_editor &&
1454 git commit --amend --author="Au ${SQ}thor <author@example.com>" --no-edit &&
1455 git cat-file commit HEAD | grep ^author >expected &&
1456 FAKE_LINES="2" git rebase -i HEAD~2 &&
1457 git cat-file commit HEAD | grep ^author >actual &&
1458 test_cmp expected actual
1461 test_done