1#!/bin/sh
2#
3# Copyright (c) 2007 Johannes E. Schindelin
4#
5
6test_description='git rebase interactive
7
8This test runs git rebase "interactively", by faking an edit, and verifies
9that the result still makes sense.
10
11Initial setup:
12
13 one - two - three - four (conflict-branch)
14 /
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)
22 \
23 N - O - P (no-ff-branch)
24
25 where A, B, D and G all touch file1, and one, two, three, four all
26 touch file "conflict".
27'
28. ./test-lib.sh
29
30. "$TEST_DIRECTORY"/lib-rebase.sh
31
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.
34
35test_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
61'
62
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.
67SHELL=
68export SHELL
69
70test_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
76'
77
78test_expect_success 'rebase -i with the exec command' '
79 git checkout master &&
80 (
81 set_fake_editor &&
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" &&
85 export FAKE_LINES &&
86 test_must_fail git rebase -i A
87 ) &&
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 &&
97 rm -f touch-*
98'
99
100test_expect_success 'rebase -i with the exec command runs from tree root' '
101 git checkout master &&
102 mkdir subdir && (cd subdir &&
103 set_fake_editor &&
104 FAKE_LINES="1 exec_>touch-subdir" \
105 git rebase -i HEAD^
106 ) &&
107 test_path_is_file touch-subdir &&
108 rm -fr subdir
109'
110
111test_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 &&
116 set_fake_editor &&
117 FAKE_LINES="1 exec_cd_subdir_&&_git_rev-parse_--is-inside-work-tree" \
118 git rebase -i HEAD^
119 )
120'
121
122test_expect_success 'rebase -i with the exec command checks tree cleanness' '
123 git checkout master &&
124 set_fake_editor &&
125 test_must_fail env FAKE_LINES="exec_echo_foo_>file1 1" git rebase -i HEAD^ &&
126 test_cmp_rev master^ HEAD &&
127 git reset --hard &&
128 git rebase --continue
129'
130
131test_expect_success 'rebase -i with exec of inexistent command' '
132 git checkout master &&
133 test_when_finished "git rebase --abort" &&
134 set_fake_editor &&
135 test_must_fail env FAKE_LINES="exec_this-command-does-not-exist 1" \
136 git rebase -i HEAD^ >actual 2>&1 &&
137 ! grep "Maybe git-rebase is broken" actual
138'
139
140test_expect_success 'no changes are a nop' '
141 git checkout branch2 &&
142 set_fake_editor &&
143 git rebase -i F &&
144 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
145 test $(git rev-parse I) = $(git rev-parse HEAD)
146'
147
148test_expect_success 'test the [branch] option' '
149 git checkout -b dead-end &&
150 git rm file6 &&
151 git commit -m "stop here" &&
152 set_fake_editor &&
153 git rebase -i F branch2 &&
154 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" &&
155 test $(git rev-parse I) = $(git rev-parse branch2) &&
156 test $(git rev-parse I) = $(git rev-parse HEAD)
157'
158
159test_expect_success 'test --onto <branch>' '
160 git checkout -b test-onto branch2 &&
161 set_fake_editor &&
162 git rebase -i --onto branch1 F &&
163 test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" &&
164 test $(git rev-parse HEAD^) = $(git rev-parse branch1) &&
165 test $(git rev-parse I) = $(git rev-parse branch2)
166'
167
168test_expect_success 'rebase on top of a non-conflicting commit' '
169 git checkout branch1 &&
170 git tag original-branch1 &&
171 set_fake_editor &&
172 git rebase -i branch2 &&
173 test file6 = $(git diff --name-only original-branch1) &&
174 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
175 test $(git rev-parse I) = $(git rev-parse branch2) &&
176 test $(git rev-parse I) = $(git rev-parse HEAD~2)
177'
178
179test_expect_success 'reflog for the branch shows state before rebase' '
180 test $(git rev-parse branch1@{1}) = $(git rev-parse original-branch1)
181'
182
183test_expect_success 'reflog for the branch shows correct finish message' '
184 printf "rebase -i (finish): refs/heads/branch1 onto %s\n" \
185 "$(git rev-parse branch2)" >expected &&
186 git log -g --pretty=%gs -1 refs/heads/branch1 >actual &&
187 test_cmp expected actual
188'
189
190test_expect_success 'exchange two commits' '
191 set_fake_editor &&
192 FAKE_LINES="2 1" git rebase -i HEAD~2 &&
193 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
194 test G = $(git cat-file commit HEAD | sed -ne \$p)
195'
196
197cat > expect << EOF
198diff --git a/file1 b/file1
199index f70f10e..fd79235 100644
200--- a/file1
201+++ b/file1
202@@ -1 +1 @@
203-A
204+G
205EOF
206
207cat > expect2 << EOF
208<<<<<<< HEAD
209D
210=======
211G
212>>>>>>> 5d18e54... G
213EOF
214
215test_expect_success 'stop on conflicting pick' '
216 git tag new-branch1 &&
217 set_fake_editor &&
218 test_must_fail git rebase -i master &&
219 test "$(git rev-parse HEAD~3)" = "$(git rev-parse master)" &&
220 test_cmp expect .git/rebase-merge/patch &&
221 test_cmp expect2 file1 &&
222 test "$(git diff --name-status |
223 sed -n -e "/^U/s/^U[^a-z]*//p")" = file1 &&
224 test 4 = $(grep -v "^#" < .git/rebase-merge/done | wc -l) &&
225 test 0 = $(grep -c "^[^#]" < .git/rebase-merge/git-rebase-todo)
226'
227
228test_expect_success 'abort' '
229 git rebase --abort &&
230 test $(git rev-parse new-branch1) = $(git rev-parse HEAD) &&
231 test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" &&
232 test_path_is_missing .git/rebase-merge
233'
234
235test_expect_success 'abort with error when new base cannot be checked out' '
236 git rm --cached file1 &&
237 git commit -m "remove file in base" &&
238 set_fake_editor &&
239 test_must_fail git rebase -i master > output 2>&1 &&
240 test_i18ngrep "The following untracked working tree files would be overwritten by checkout:" \
241 output &&
242 test_i18ngrep "file1" output &&
243 test_path_is_missing .git/rebase-merge &&
244 git reset --hard HEAD^
245'
246
247test_expect_success 'retain authorship' '
248 echo A > file7 &&
249 git add file7 &&
250 test_tick &&
251 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
252 git tag twerp &&
253 set_fake_editor &&
254 git rebase -i --onto master HEAD^ &&
255 git show HEAD | grep "^Author: Twerp Snog"
256'
257
258test_expect_success 'retain authorship w/ conflicts' '
259 git reset --hard twerp &&
260 test_commit a conflict a conflict-a &&
261 git reset --hard twerp &&
262 GIT_AUTHOR_NAME=AttributeMe \
263 test_commit b conflict b conflict-b &&
264 set_fake_editor &&
265 test_must_fail git rebase -i conflict-a &&
266 echo resolved >conflict &&
267 git add conflict &&
268 git rebase --continue &&
269 test $(git rev-parse conflict-a^0) = $(git rev-parse HEAD^) &&
270 git show >out &&
271 grep AttributeMe out
272'
273
274test_expect_success 'squash' '
275 git reset --hard twerp &&
276 echo B > file7 &&
277 test_tick &&
278 GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 &&
279 echo "******************************" &&
280 set_fake_editor &&
281 FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \
282 git rebase -i --onto master HEAD~2 &&
283 test B = $(cat file7) &&
284 test $(git rev-parse HEAD^) = $(git rev-parse master)
285'
286
287test_expect_success 'retain authorship when squashing' '
288 git show HEAD | grep "^Author: Twerp Snog"
289'
290
291test_expect_success '-p handles "no changes" gracefully' '
292 HEAD=$(git rev-parse HEAD) &&
293 set_fake_editor &&
294 git rebase -i -p HEAD^ &&
295 git update-index --refresh &&
296 git diff-files --quiet &&
297 git diff-index --quiet --cached HEAD -- &&
298 test $HEAD = $(git rev-parse HEAD)
299'
300
301test_expect_failure 'exchange two commits with -p' '
302 git checkout H &&
303 set_fake_editor &&
304 FAKE_LINES="2 1" git rebase -i -p HEAD~2 &&
305 test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
306 test G = $(git cat-file commit HEAD | sed -ne \$p)
307'
308
309test_expect_success 'preserve merges with -p' '
310 git checkout -b to-be-preserved master^ &&
311 : > unrelated-file &&
312 git add unrelated-file &&
313 test_tick &&
314 git commit -m "unrelated" &&
315 git checkout -b another-branch master &&
316 echo B > file1 &&
317 test_tick &&
318 git commit -m J file1 &&
319 test_tick &&
320 git merge to-be-preserved &&
321 echo C > file1 &&
322 test_tick &&
323 git commit -m K file1 &&
324 echo D > file1 &&
325 test_tick &&
326 git commit -m L1 file1 &&
327 git checkout HEAD^ &&
328 echo 1 > unrelated-file &&
329 test_tick &&
330 git commit -m L2 unrelated-file &&
331 test_tick &&
332 git merge another-branch &&
333 echo E > file1 &&
334 test_tick &&
335 git commit -m M file1 &&
336 git checkout -b to-be-rebased &&
337 test_tick &&
338 set_fake_editor &&
339 git rebase -i -p --onto branch1 master &&
340 git update-index --refresh &&
341 git diff-files --quiet &&
342 git diff-index --quiet --cached HEAD -- &&
343 test $(git rev-parse HEAD~6) = $(git rev-parse branch1) &&
344 test $(git rev-parse HEAD~4^2) = $(git rev-parse to-be-preserved) &&
345 test $(git rev-parse HEAD^^2^) = $(git rev-parse HEAD^^^) &&
346 test $(git show HEAD~5:file1) = B &&
347 test $(git show HEAD~3:file1) = C &&
348 test $(git show HEAD:file1) = E &&
349 test $(git show HEAD:unrelated-file) = 1
350'
351
352test_expect_success 'edit ancestor with -p' '
353 set_fake_editor &&
354 FAKE_LINES="1 2 edit 3 4" git rebase -i -p HEAD~3 &&
355 echo 2 > unrelated-file &&
356 test_tick &&
357 git commit -m L2-modified --amend unrelated-file &&
358 git rebase --continue &&
359 git update-index --refresh &&
360 git diff-files --quiet &&
361 git diff-index --quiet --cached HEAD -- &&
362 test $(git show HEAD:unrelated-file) = 2
363'
364
365test_expect_success '--continue tries to commit' '
366 test_tick &&
367 set_fake_editor &&
368 test_must_fail git rebase -i --onto new-branch1 HEAD^ &&
369 echo resolved > file1 &&
370 git add file1 &&
371 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
372 test $(git rev-parse HEAD^) = $(git rev-parse new-branch1) &&
373 git show HEAD | grep chouette
374'
375
376test_expect_success 'verbose flag is heeded, even after --continue' '
377 git reset --hard master@{1} &&
378 test_tick &&
379 set_fake_editor &&
380 test_must_fail git rebase -v -i --onto new-branch1 HEAD^ &&
381 echo resolved > file1 &&
382 git add file1 &&
383 git rebase --continue > output &&
384 grep "^ file1 | 2 +-$" output
385'
386
387test_expect_success C_LOCALE_OUTPUT 'multi-squash only fires up editor once' '
388 base=$(git rev-parse HEAD~4) &&
389 set_fake_editor &&
390 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 squash 2 squash 3 squash 4" \
391 EXPECT_HEADER_COUNT=4 \
392 git rebase -i $base &&
393 test $base = $(git rev-parse HEAD^) &&
394 test 1 = $(git show | grep ONCE | wc -l)
395'
396
397test_expect_success C_LOCALE_OUTPUT 'multi-fixup does not fire up editor' '
398 git checkout -b multi-fixup E &&
399 base=$(git rev-parse HEAD~4) &&
400 set_fake_editor &&
401 FAKE_COMMIT_AMEND="NEVER" FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \
402 git rebase -i $base &&
403 test $base = $(git rev-parse HEAD^) &&
404 test 0 = $(git show | grep NEVER | wc -l) &&
405 git checkout to-be-rebased &&
406 git branch -D multi-fixup
407'
408
409test_expect_success 'commit message used after conflict' '
410 git checkout -b conflict-fixup conflict-branch &&
411 base=$(git rev-parse HEAD~4) &&
412 set_fake_editor &&
413 test_must_fail env FAKE_LINES="1 fixup 3 fixup 4" git rebase -i $base &&
414 echo three > conflict &&
415 git add conflict &&
416 FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \
417 git rebase --continue &&
418 test $base = $(git rev-parse HEAD^) &&
419 test 1 = $(git show | grep ONCE | wc -l) &&
420 git checkout to-be-rebased &&
421 git branch -D conflict-fixup
422'
423
424test_expect_success 'commit message retained after conflict' '
425 git checkout -b conflict-squash conflict-branch &&
426 base=$(git rev-parse HEAD~4) &&
427 set_fake_editor &&
428 test_must_fail env FAKE_LINES="1 fixup 3 squash 4" git rebase -i $base &&
429 echo three > conflict &&
430 git add conflict &&
431 FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \
432 git rebase --continue &&
433 test $base = $(git rev-parse HEAD^) &&
434 test 2 = $(git show | grep TWICE | wc -l) &&
435 git checkout to-be-rebased &&
436 git branch -D conflict-squash
437'
438
439cat > expect-squash-fixup << EOF
440B
441
442D
443
444ONCE
445EOF
446
447test_expect_success C_LOCALE_OUTPUT 'squash and fixup generate correct log messages' '
448 git checkout -b squash-fixup E &&
449 base=$(git rev-parse HEAD~4) &&
450 set_fake_editor &&
451 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 fixup 2 squash 3 fixup 4" \
452 EXPECT_HEADER_COUNT=4 \
453 git rebase -i $base &&
454 git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup &&
455 test_cmp expect-squash-fixup actual-squash-fixup &&
456 git checkout to-be-rebased &&
457 git branch -D squash-fixup
458'
459
460test_expect_success C_LOCALE_OUTPUT 'squash ignores comments' '
461 git checkout -b skip-comments E &&
462 base=$(git rev-parse HEAD~4) &&
463 set_fake_editor &&
464 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \
465 EXPECT_HEADER_COUNT=4 \
466 git rebase -i $base &&
467 test $base = $(git rev-parse HEAD^) &&
468 test 1 = $(git show | grep ONCE | wc -l) &&
469 git checkout to-be-rebased &&
470 git branch -D skip-comments
471'
472
473test_expect_success C_LOCALE_OUTPUT 'squash ignores blank lines' '
474 git checkout -b skip-blank-lines E &&
475 base=$(git rev-parse HEAD~4) &&
476 set_fake_editor &&
477 FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \
478 EXPECT_HEADER_COUNT=4 \
479 git rebase -i $base &&
480 test $base = $(git rev-parse HEAD^) &&
481 test 1 = $(git show | grep ONCE | wc -l) &&
482 git checkout to-be-rebased &&
483 git branch -D skip-blank-lines
484'
485
486test_expect_success 'squash works as expected' '
487 git checkout -b squash-works no-conflict-branch &&
488 one=$(git rev-parse HEAD~3) &&
489 set_fake_editor &&
490 FAKE_LINES="1 squash 3 2" EXPECT_HEADER_COUNT=2 \
491 git rebase -i HEAD~3 &&
492 test $one = $(git rev-parse HEAD~2)
493'
494
495test_expect_success 'interrupted squash works as expected' '
496 git checkout -b interrupted-squash conflict-branch &&
497 one=$(git rev-parse HEAD~3) &&
498 set_fake_editor &&
499 test_must_fail env FAKE_LINES="1 squash 3 2" git rebase -i HEAD~3 &&
500 (echo one; echo two; echo four) > conflict &&
501 git add conflict &&
502 test_must_fail git rebase --continue &&
503 echo resolved > conflict &&
504 git add conflict &&
505 git rebase --continue &&
506 test $one = $(git rev-parse HEAD~2)
507'
508
509test_expect_success 'interrupted squash works as expected (case 2)' '
510 git checkout -b interrupted-squash2 conflict-branch &&
511 one=$(git rev-parse HEAD~3) &&
512 set_fake_editor &&
513 test_must_fail env FAKE_LINES="3 squash 1 2" git rebase -i HEAD~3 &&
514 (echo one; echo four) > conflict &&
515 git add conflict &&
516 test_must_fail git rebase --continue &&
517 (echo one; echo two; echo four) > conflict &&
518 git add conflict &&
519 test_must_fail git rebase --continue &&
520 echo resolved > conflict &&
521 git add conflict &&
522 git rebase --continue &&
523 test $one = $(git rev-parse HEAD~2)
524'
525
526test_expect_success '--continue tries to commit, even for "edit"' '
527 echo unrelated > file7 &&
528 git add file7 &&
529 test_tick &&
530 git commit -m "unrelated change" &&
531 parent=$(git rev-parse HEAD^) &&
532 test_tick &&
533 set_fake_editor &&
534 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
535 echo edited > file7 &&
536 git add file7 &&
537 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
538 test edited = $(git show HEAD:file7) &&
539 git show HEAD | grep chouette &&
540 test $parent = $(git rev-parse HEAD^)
541'
542
543test_expect_success 'aborted --continue does not squash commits after "edit"' '
544 old=$(git rev-parse HEAD) &&
545 test_tick &&
546 set_fake_editor &&
547 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
548 echo "edited again" > file7 &&
549 git add file7 &&
550 test_must_fail env FAKE_COMMIT_MESSAGE=" " git rebase --continue &&
551 test $old = $(git rev-parse HEAD) &&
552 git rebase --abort
553'
554
555test_expect_success 'auto-amend only edited commits after "edit"' '
556 test_tick &&
557 set_fake_editor &&
558 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
559 echo "edited again" > file7 &&
560 git add file7 &&
561 FAKE_COMMIT_MESSAGE="edited file7 again" git commit &&
562 echo "and again" > file7 &&
563 git add file7 &&
564 test_tick &&
565 test_must_fail env FAKE_COMMIT_MESSAGE="and again" git rebase --continue &&
566 git rebase --abort
567'
568
569test_expect_success 'clean error after failed "exec"' '
570 test_tick &&
571 test_when_finished "git rebase --abort || :" &&
572 set_fake_editor &&
573 test_must_fail env FAKE_LINES="1 exec_false" git rebase -i HEAD^ &&
574 echo "edited again" > file7 &&
575 git add file7 &&
576 test_must_fail git rebase --continue 2>error &&
577 test_i18ngrep "you have staged changes in your working tree" error
578'
579
580test_expect_success 'rebase a detached HEAD' '
581 grandparent=$(git rev-parse HEAD~2) &&
582 git checkout $(git rev-parse HEAD) &&
583 test_tick &&
584 set_fake_editor &&
585 FAKE_LINES="2 1" git rebase -i HEAD~2 &&
586 test $grandparent = $(git rev-parse HEAD~2)
587'
588
589test_expect_success 'rebase a commit violating pre-commit' '
590
591 mkdir -p .git/hooks &&
592 write_script .git/hooks/pre-commit <<-\EOF &&
593 test -z "$(git diff --cached --check)"
594 EOF
595 echo "monde! " >> file1 &&
596 test_tick &&
597 test_must_fail git commit -m doesnt-verify file1 &&
598 git commit -m doesnt-verify --no-verify file1 &&
599 test_tick &&
600 set_fake_editor &&
601 FAKE_LINES=2 git rebase -i HEAD~2
602
603'
604
605test_expect_success 'rebase with a file named HEAD in worktree' '
606
607 rm -fr .git/hooks &&
608 git reset --hard &&
609 git checkout -b branch3 A &&
610
611 (
612 GIT_AUTHOR_NAME="Squashed Away" &&
613 export GIT_AUTHOR_NAME &&
614 >HEAD &&
615 git add HEAD &&
616 git commit -m "Add head" &&
617 >BODY &&
618 git add BODY &&
619 git commit -m "Add body"
620 ) &&
621
622 set_fake_editor &&
623 FAKE_LINES="1 squash 2" git rebase -i to-be-rebased &&
624 test "$(git show -s --pretty=format:%an)" = "Squashed Away"
625
626'
627
628test_expect_success 'do "noop" when there is nothing to cherry-pick' '
629
630 git checkout -b branch4 HEAD &&
631 GIT_EDITOR=: git commit --amend \
632 --author="Somebody else <somebody@else.com>" &&
633 test $(git rev-parse branch3) != $(git rev-parse branch4) &&
634 set_fake_editor &&
635 git rebase -i branch3 &&
636 test $(git rev-parse branch3) = $(git rev-parse branch4)
637
638'
639
640test_expect_success 'submodule rebase setup' '
641 git checkout A &&
642 mkdir sub &&
643 (
644 cd sub && git init && >elif &&
645 git add elif && git commit -m "submodule initial"
646 ) &&
647 echo 1 >file1 &&
648 git add file1 sub &&
649 test_tick &&
650 git commit -m "One" &&
651 echo 2 >file1 &&
652 test_tick &&
653 git commit -a -m "Two" &&
654 (
655 cd sub && echo 3 >elif &&
656 git commit -a -m "submodule second"
657 ) &&
658 test_tick &&
659 set_fake_editor &&
660 git commit -a -m "Three changes submodule"
661'
662
663test_expect_success 'submodule rebase -i' '
664 set_fake_editor &&
665 FAKE_LINES="1 squash 2 3" git rebase -i A
666'
667
668test_expect_success 'submodule conflict setup' '
669 git tag submodule-base &&
670 git checkout HEAD^ &&
671 (
672 cd sub && git checkout HEAD^ && echo 4 >elif &&
673 git add elif && git commit -m "submodule conflict"
674 ) &&
675 git add sub &&
676 test_tick &&
677 git commit -m "Conflict in submodule" &&
678 git tag submodule-topic
679'
680
681test_expect_success 'rebase -i continue with only submodule staged' '
682 set_fake_editor &&
683 test_must_fail git rebase -i submodule-base &&
684 git add sub &&
685 git rebase --continue &&
686 test $(git rev-parse submodule-base) != $(git rev-parse HEAD)
687'
688
689test_expect_success 'rebase -i continue with unstaged submodule' '
690 git checkout submodule-topic &&
691 git reset --hard &&
692 set_fake_editor &&
693 test_must_fail git rebase -i submodule-base &&
694 git reset &&
695 git rebase --continue &&
696 test $(git rev-parse submodule-base) = $(git rev-parse HEAD)
697'
698
699test_expect_success 'avoid unnecessary reset' '
700 git checkout master &&
701 git reset --hard &&
702 test-chmtime =123456789 file3 &&
703 git update-index --refresh &&
704 HEAD=$(git rev-parse HEAD) &&
705 set_fake_editor &&
706 git rebase -i HEAD~4 &&
707 test $HEAD = $(git rev-parse HEAD) &&
708 MTIME=$(test-chmtime -v +0 file3 | sed 's/[^0-9].*$//') &&
709 test 123456789 = $MTIME
710'
711
712test_expect_success 'reword' '
713 git checkout -b reword-branch master &&
714 set_fake_editor &&
715 FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" git rebase -i A &&
716 git show HEAD | grep "E changed" &&
717 test $(git rev-parse master) != $(git rev-parse HEAD) &&
718 test $(git rev-parse master^) = $(git rev-parse HEAD^) &&
719 FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" git rebase -i A &&
720 git show HEAD^ | grep "D changed" &&
721 FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" git rebase -i A &&
722 git show HEAD~3 | grep "B changed" &&
723 FAKE_LINES="1 reword 2 3 4" FAKE_COMMIT_MESSAGE="C changed" git rebase -i A &&
724 git show HEAD~2 | grep "C changed"
725'
726
727test_expect_success 'rebase -i can copy notes' '
728 git config notes.rewrite.rebase true &&
729 git config notes.rewriteRef "refs/notes/*" &&
730 test_commit n1 &&
731 test_commit n2 &&
732 test_commit n3 &&
733 git notes add -m"a note" n3 &&
734 set_fake_editor &&
735 git rebase -i --onto n1 n2 &&
736 test "a note" = "$(git notes show HEAD)"
737'
738
739cat >expect <<EOF
740an earlier note
741
742a note
743EOF
744
745test_expect_success 'rebase -i can copy notes over a fixup' '
746 git reset --hard n3 &&
747 git notes add -m"an earlier note" n2 &&
748 set_fake_editor &&
749 GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 fixup 2" git rebase -i n1 &&
750 git notes show > output &&
751 test_cmp expect output
752'
753
754test_expect_success 'rebase while detaching HEAD' '
755 git symbolic-ref HEAD &&
756 grandparent=$(git rev-parse HEAD~2) &&
757 test_tick &&
758 set_fake_editor &&
759 FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0 &&
760 test $grandparent = $(git rev-parse HEAD~2) &&
761 test_must_fail git symbolic-ref HEAD
762'
763
764test_tick # Ensure that the rebased commits get a different timestamp.
765test_expect_success 'always cherry-pick with --no-ff' '
766 git checkout no-ff-branch &&
767 git tag original-no-ff-branch &&
768 set_fake_editor &&
769 git rebase -i --no-ff A &&
770 touch empty &&
771 for p in 0 1 2
772 do
773 test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) &&
774 git diff HEAD~$p original-no-ff-branch~$p > out &&
775 test_cmp empty out
776 done &&
777 test $(git rev-parse HEAD~3) = $(git rev-parse original-no-ff-branch~3) &&
778 git diff HEAD~3 original-no-ff-branch~3 > out &&
779 test_cmp empty out
780'
781
782test_expect_success 'set up commits with funny messages' '
783 git checkout -b funny A &&
784 echo >>file1 &&
785 test_tick &&
786 git commit -a -m "end with slash\\" &&
787 echo >>file1 &&
788 test_tick &&
789 git commit -a -m "something (\000) that looks like octal" &&
790 echo >>file1 &&
791 test_tick &&
792 git commit -a -m "something (\n) that looks like a newline" &&
793 echo >>file1 &&
794 test_tick &&
795 git commit -a -m "another commit"
796'
797
798test_expect_success 'rebase-i history with funny messages' '
799 git rev-list A..funny >expect &&
800 test_tick &&
801 set_fake_editor &&
802 FAKE_LINES="1 2 3 4" git rebase -i A &&
803 git rev-list A.. >actual &&
804 test_cmp expect actual
805'
806
807test_expect_success 'prepare for rebase -i --exec' '
808 git checkout master &&
809 git checkout -b execute &&
810 test_commit one_exec main.txt one_exec &&
811 test_commit two_exec main.txt two_exec &&
812 test_commit three_exec main.txt three_exec
813'
814
815test_expect_success 'running "git rebase -i --exec git show HEAD"' '
816 set_fake_editor &&
817 git rebase -i --exec "git show HEAD" HEAD~2 >actual &&
818 (
819 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
820 export FAKE_LINES &&
821 git rebase -i HEAD~2 >expect
822 ) &&
823 sed -e "1,9d" expect >expected &&
824 test_cmp expected actual
825'
826
827test_expect_success 'running "git rebase --exec git show HEAD -i"' '
828 git reset --hard execute &&
829 set_fake_editor &&
830 git rebase --exec "git show HEAD" -i HEAD~2 >actual &&
831 (
832 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
833 export FAKE_LINES &&
834 git rebase -i HEAD~2 >expect
835 ) &&
836 sed -e "1,9d" expect >expected &&
837 test_cmp expected actual
838'
839
840test_expect_success 'running "git rebase -ix git show HEAD"' '
841 git reset --hard execute &&
842 set_fake_editor &&
843 git rebase -ix "git show HEAD" HEAD~2 >actual &&
844 (
845 FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
846 export FAKE_LINES &&
847 git rebase -i HEAD~2 >expect
848 ) &&
849 sed -e "1,9d" expect >expected &&
850 test_cmp expected actual
851'
852
853
854test_expect_success 'rebase -ix with several <CMD>' '
855 git reset --hard execute &&
856 set_fake_editor &&
857 git rebase -ix "git show HEAD; pwd" HEAD~2 >actual &&
858 (
859 FAKE_LINES="1 exec_git_show_HEAD;_pwd 2 exec_git_show_HEAD;_pwd" &&
860 export FAKE_LINES &&
861 git rebase -i HEAD~2 >expect
862 ) &&
863 sed -e "1,9d" expect >expected &&
864 test_cmp expected actual
865'
866
867test_expect_success 'rebase -ix with several instances of --exec' '
868 git reset --hard execute &&
869 set_fake_editor &&
870 git rebase -i --exec "git show HEAD" --exec "pwd" HEAD~2 >actual &&
871 (
872 FAKE_LINES="1 exec_git_show_HEAD exec_pwd 2
873 exec_git_show_HEAD exec_pwd" &&
874 export FAKE_LINES &&
875 git rebase -i HEAD~2 >expect
876 ) &&
877 sed -e "1,11d" expect >expected &&
878 test_cmp expected actual
879'
880
881test_expect_success C_LOCALE_OUTPUT 'rebase -ix with --autosquash' '
882 git reset --hard execute &&
883 git checkout -b autosquash &&
884 echo second >second.txt &&
885 git add second.txt &&
886 git commit -m "fixup! two_exec" &&
887 echo bis >bis.txt &&
888 git add bis.txt &&
889 git commit -m "fixup! two_exec" &&
890 set_fake_editor &&
891 (
892 git checkout -b autosquash_actual &&
893 git rebase -i --exec "git show HEAD" --autosquash HEAD~4 >actual
894 ) &&
895 git checkout autosquash &&
896 (
897 git checkout -b autosquash_expected &&
898 FAKE_LINES="1 fixup 3 fixup 4 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
899 export FAKE_LINES &&
900 git rebase -i HEAD~4 >expect
901 ) &&
902 sed -e "1,13d" expect >expected &&
903 test_cmp expected actual
904'
905
906test_expect_success 'rebase --exec works without -i ' '
907 git reset --hard execute &&
908 rm -rf exec_output &&
909 EDITOR="echo >invoked_editor" git rebase --exec "echo a line >>exec_output" HEAD~2 2>actual &&
910 test_i18ngrep "Successfully rebased and updated" actual &&
911 test_line_count = 2 exec_output &&
912 test_path_is_missing invoked_editor
913'
914
915test_expect_success 'rebase -i --exec without <CMD>' '
916 git reset --hard execute &&
917 set_fake_editor &&
918 test_must_fail git rebase -i --exec 2>actual &&
919 test_i18ngrep "requires a value" actual &&
920 git checkout master
921'
922
923test_expect_success 'rebase -i --root re-order and drop commits' '
924 git checkout E &&
925 set_fake_editor &&
926 FAKE_LINES="3 1 2 5" git rebase -i --root &&
927 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
928 test B = $(git cat-file commit HEAD^ | sed -ne \$p) &&
929 test A = $(git cat-file commit HEAD^^ | sed -ne \$p) &&
930 test C = $(git cat-file commit HEAD^^^ | sed -ne \$p) &&
931 test 0 = $(git cat-file commit HEAD^^^ | grep -c ^parent\ )
932'
933
934test_expect_success 'rebase -i --root retain root commit author and message' '
935 git checkout A &&
936 echo B >file7 &&
937 git add file7 &&
938 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
939 set_fake_editor &&
940 FAKE_LINES="2" git rebase -i --root &&
941 git cat-file commit HEAD | grep -q "^author Twerp Snog" &&
942 git cat-file commit HEAD | grep -q "^different author$"
943'
944
945test_expect_success 'rebase -i --root temporary sentinel commit' '
946 git checkout B &&
947 set_fake_editor &&
948 test_must_fail env FAKE_LINES="2" git rebase -i --root &&
949 git cat-file commit HEAD | grep "^tree 4b825dc642cb" &&
950 git rebase --abort
951'
952
953test_expect_success 'rebase -i --root fixup root commit' '
954 git checkout B &&
955 set_fake_editor &&
956 FAKE_LINES="1 fixup 2" git rebase -i --root &&
957 test A = $(git cat-file commit HEAD | sed -ne \$p) &&
958 test B = $(git show HEAD:file1) &&
959 test 0 = $(git cat-file commit HEAD | grep -c ^parent\ )
960'
961
962test_expect_success C_LOCALE_OUTPUT 'rebase --edit-todo does not work on non-interactive rebase' '
963 git reset --hard &&
964 git checkout conflict-branch &&
965 set_fake_editor &&
966 test_must_fail git rebase --onto HEAD~2 HEAD~ &&
967 test_must_fail git rebase --edit-todo &&
968 git rebase --abort
969'
970
971test_expect_success 'rebase --edit-todo can be used to modify todo' '
972 git reset --hard &&
973 git checkout no-conflict-branch^0 &&
974 set_fake_editor &&
975 FAKE_LINES="edit 1 2 3" git rebase -i HEAD~3 &&
976 FAKE_LINES="2 1" git rebase --edit-todo &&
977 git rebase --continue &&
978 test M = $(git cat-file commit HEAD^ | sed -ne \$p) &&
979 test L = $(git cat-file commit HEAD | sed -ne \$p)
980'
981
982test_expect_success 'rebase -i produces readable reflog' '
983 git reset --hard &&
984 git branch -f branch-reflog-test H &&
985 set_fake_editor &&
986 git rebase -i --onto I F branch-reflog-test &&
987 cat >expect <<-\EOF &&
988 rebase -i (finish): returning to refs/heads/branch-reflog-test
989 rebase -i (pick): H
990 rebase -i (pick): G
991 rebase -i (start): checkout I
992 EOF
993 git reflog -n4 HEAD |
994 sed "s/[^:]*: //" >actual &&
995 test_cmp expect actual
996'
997
998test_expect_success 'rebase -i respects core.commentchar' '
999 git reset --hard &&
1000 git checkout E^0 &&
1001 test_config core.commentchar "\\" &&
1002 write_script remove-all-but-first.sh <<-\EOF &&
1003 sed -e "2,\$s/^/\\\\/" "$1" >"$1.tmp" &&
1004 mv "$1.tmp" "$1"
1005 EOF
1006 test_set_editor "$(pwd)/remove-all-but-first.sh" &&
1007 git rebase -i B &&
1008 test B = $(git cat-file commit HEAD^ | sed -ne \$p)
1009'
1010
1011test_expect_success 'rebase -i respects core.commentchar=auto' '
1012 test_config core.commentchar auto &&
1013 write_script copy-edit-script.sh <<-\EOF &&
1014 cp "$1" edit-script
1015 EOF
1016 test_set_editor "$(pwd)/copy-edit-script.sh" &&
1017 test_when_finished "git rebase --abort || :" &&
1018 git rebase -i HEAD^ &&
1019 test -z "$(grep -ve "^#" -e "^\$" -e "^pick" edit-script)"
1020'
1021
1022test_expect_success 'rebase -i, with <onto> and <upstream> specified as :/quuxery' '
1023 test_when_finished "git branch -D torebase" &&
1024 git checkout -b torebase branch1 &&
1025 upstream=$(git rev-parse ":/J") &&
1026 onto=$(git rev-parse ":/A") &&
1027 git rebase --onto $onto $upstream &&
1028 git reset --hard branch1 &&
1029 git rebase --onto ":/A" ":/J" &&
1030 git checkout branch1
1031'
1032
1033test_expect_success 'rebase -i with --strategy and -X' '
1034 git checkout -b conflict-merge-use-theirs conflict-branch &&
1035 git reset --hard HEAD^ &&
1036 echo five >conflict &&
1037 echo Z >file1 &&
1038 git commit -a -m "one file conflict" &&
1039 EDITOR=true git rebase -i --strategy=recursive -Xours conflict-branch &&
1040 test $(git show conflict-branch:conflict) = $(cat conflict) &&
1041 test $(cat file1) = Z
1042'
1043
1044test_expect_success 'interrupted rebase -i with --strategy and -X' '
1045 git checkout -b conflict-merge-use-theirs-interrupted conflict-branch &&
1046 git reset --hard HEAD^ &&
1047 >breakpoint &&
1048 git add breakpoint &&
1049 git commit -m "breakpoint for interactive mode" &&
1050 echo five >conflict &&
1051 echo Z >file1 &&
1052 git commit -a -m "one file conflict" &&
1053 set_fake_editor &&
1054 FAKE_LINES="edit 1 2" git rebase -i --strategy=recursive -Xours conflict-branch &&
1055 git rebase --continue &&
1056 test $(git show conflict-branch:conflict) = $(cat conflict) &&
1057 test $(cat file1) = Z
1058'
1059
1060test_expect_success 'rebase -i error on commits with \ in message' '
1061 current_head=$(git rev-parse HEAD) &&
1062 test_when_finished "git rebase --abort; git reset --hard $current_head; rm -f error" &&
1063 test_commit TO-REMOVE will-conflict old-content &&
1064 test_commit "\temp" will-conflict new-content dummy &&
1065 test_must_fail env EDITOR=true git rebase -i HEAD^ --onto HEAD^^ 2>error &&
1066 test_expect_code 1 grep " emp" error
1067'
1068
1069test_expect_success 'short SHA-1 setup' '
1070 test_when_finished "git checkout master" &&
1071 git checkout --orphan collide &&
1072 git rm -rf . &&
1073 (
1074 unset test_tick &&
1075 test_commit collide1 collide &&
1076 test_commit --notick collide2 collide &&
1077 test_commit --notick collide3 collide
1078 )
1079'
1080
1081test_expect_success 'short SHA-1 collide' '
1082 test_when_finished "reset_rebase && git checkout master" &&
1083 git checkout collide &&
1084 (
1085 unset test_tick &&
1086 test_tick &&
1087 set_fake_editor &&
1088 FAKE_COMMIT_MESSAGE="collide2 ac4f2ee" \
1089 FAKE_LINES="reword 1 2" git rebase -i HEAD~2
1090 )
1091'
1092
1093test_expect_success 'respect core.abbrev' '
1094 git config core.abbrev 12 &&
1095 set_cat_todo_editor &&
1096 test_must_fail git rebase -i HEAD~4 >todo-list &&
1097 test 4 = $(grep -c "pick [0-9a-f]\{12,\}" todo-list)
1098'
1099
1100test_expect_success 'todo count' '
1101 write_script dump-raw.sh <<-\EOF &&
1102 cat "$1"
1103 EOF
1104 test_set_editor "$(pwd)/dump-raw.sh" &&
1105 git rebase -i HEAD~4 >actual &&
1106 test_i18ngrep "^# Rebase ..* onto ..* ([0-9]" actual
1107'
1108
1109test_expect_success 'rebase -i commits that overwrite untracked files (pick)' '
1110 git checkout --force branch2 &&
1111 git clean -f &&
1112 set_fake_editor &&
1113 FAKE_LINES="edit 1 2" git rebase -i A &&
1114 test_cmp_rev HEAD F &&
1115 test_path_is_missing file6 &&
1116 >file6 &&
1117 test_must_fail git rebase --continue &&
1118 test_cmp_rev HEAD F &&
1119 rm file6 &&
1120 git rebase --continue &&
1121 test_cmp_rev HEAD I
1122'
1123
1124test_expect_success 'rebase -i commits that overwrite untracked files (squash)' '
1125 git checkout --force branch2 &&
1126 git clean -f &&
1127 git tag original-branch2 &&
1128 set_fake_editor &&
1129 FAKE_LINES="edit 1 squash 2" git rebase -i A &&
1130 test_cmp_rev HEAD F &&
1131 test_path_is_missing file6 &&
1132 >file6 &&
1133 test_must_fail git rebase --continue &&
1134 test_cmp_rev HEAD F &&
1135 rm file6 &&
1136 git rebase --continue &&
1137 test $(git cat-file commit HEAD | sed -ne \$p) = I &&
1138 git reset --hard original-branch2
1139'
1140
1141test_expect_success 'rebase -i commits that overwrite untracked files (no ff)' '
1142 git checkout --force branch2 &&
1143 git clean -f &&
1144 set_fake_editor &&
1145 FAKE_LINES="edit 1 2" git rebase -i --no-ff A &&
1146 test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1147 test_path_is_missing file6 &&
1148 >file6 &&
1149 test_must_fail git rebase --continue &&
1150 test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1151 rm file6 &&
1152 git rebase --continue &&
1153 test $(git cat-file commit HEAD | sed -ne \$p) = I
1154'
1155
1156test_expect_success 'rebase --continue removes CHERRY_PICK_HEAD' '
1157 git checkout -b commit-to-skip &&
1158 for double in X 3 1
1159 do
1160 test_seq 5 | sed "s/$double/&&/" >seq &&
1161 git add seq &&
1162 test_tick &&
1163 git commit -m seq-$double
1164 done &&
1165 git tag seq-onto &&
1166 git reset --hard HEAD~2 &&
1167 git cherry-pick seq-onto &&
1168 set_fake_editor &&
1169 test_must_fail env FAKE_LINES= git rebase -i seq-onto &&
1170 test -d .git/rebase-merge &&
1171 git rebase --continue &&
1172 git diff --exit-code seq-onto &&
1173 test ! -d .git/rebase-merge &&
1174 test ! -f .git/CHERRY_PICK_HEAD
1175'
1176
1177rebase_setup_and_clean () {
1178 test_when_finished "
1179 git checkout master &&
1180 test_might_fail git branch -D $1 &&
1181 test_might_fail git rebase --abort
1182 " &&
1183 git checkout -b $1 master
1184}
1185
1186test_expect_success 'drop' '
1187 rebase_setup_and_clean drop-test &&
1188 set_fake_editor &&
1189 FAKE_LINES="1 drop 2 3 drop 4 5" git rebase -i --root &&
1190 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1191 test C = $(git cat-file commit HEAD^ | sed -ne \$p) &&
1192 test A = $(git cat-file commit HEAD^^ | sed -ne \$p)
1193'
1194
1195cat >expect <<EOF
1196Successfully rebased and updated refs/heads/missing-commit.
1197EOF
1198
1199test_expect_success 'rebase -i respects rebase.missingCommitsCheck = ignore' '
1200 test_config rebase.missingCommitsCheck ignore &&
1201 rebase_setup_and_clean missing-commit &&
1202 set_fake_editor &&
1203 FAKE_LINES="1 2 3 4" \
1204 git rebase -i --root 2>actual &&
1205 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1206 test_i18ncmp expect actual
1207'
1208
1209cat >expect <<EOF
1210Warning: some commits may have been dropped accidentally.
1211Dropped commits (newer to older):
1212 - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
1213To avoid this message, use "drop" to explicitly remove a commit.
1214
1215Use 'git config rebase.missingCommitsCheck' to change the level of warnings.
1216The possible behaviours are: ignore, warn, error.
1217
1218Successfully rebased and updated refs/heads/missing-commit.
1219EOF
1220
1221test_expect_success 'rebase -i respects rebase.missingCommitsCheck = warn' '
1222 test_config rebase.missingCommitsCheck warn &&
1223 rebase_setup_and_clean missing-commit &&
1224 set_fake_editor &&
1225 FAKE_LINES="1 2 3 4" \
1226 git rebase -i --root 2>actual &&
1227 test_i18ncmp expect actual &&
1228 test D = $(git cat-file commit HEAD | sed -ne \$p)
1229'
1230
1231cat >expect <<EOF
1232Warning: some commits may have been dropped accidentally.
1233Dropped commits (newer to older):
1234 - $(git rev-list --pretty=oneline --abbrev-commit -1 master)
1235 - $(git rev-list --pretty=oneline --abbrev-commit -1 master~2)
1236To avoid this message, use "drop" to explicitly remove a commit.
1237
1238Use 'git config rebase.missingCommitsCheck' to change the level of warnings.
1239The possible behaviours are: ignore, warn, error.
1240
1241You can fix this with 'git rebase --edit-todo' and then run 'git rebase --continue'.
1242Or you can abort the rebase with 'git rebase --abort'.
1243EOF
1244
1245test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' '
1246 test_config rebase.missingCommitsCheck error &&
1247 rebase_setup_and_clean missing-commit &&
1248 set_fake_editor &&
1249 test_must_fail env FAKE_LINES="1 2 4" \
1250 git rebase -i --root 2>actual &&
1251 test_i18ncmp expect actual &&
1252 cp .git/rebase-merge/git-rebase-todo.backup \
1253 .git/rebase-merge/git-rebase-todo &&
1254 FAKE_LINES="1 2 drop 3 4 drop 5" \
1255 git rebase --edit-todo &&
1256 git rebase --continue &&
1257 test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1258 test B = $(git cat-file commit HEAD^ | sed -ne \$p)
1259'
1260
1261test_expect_success 'respects rebase.abbreviateCommands with fixup, squash and exec' '
1262 rebase_setup_and_clean abbrevcmd &&
1263 test_commit "first" file1.txt "first line" first &&
1264 test_commit "second" file1.txt "another line" second &&
1265 test_commit "fixup! first" file2.txt "first line again" first_fixup &&
1266 test_commit "squash! second" file1.txt "another line here" second_squash &&
1267 cat >expected <<-EOF &&
1268 p $(git rev-list --abbrev-commit -1 first) first
1269 f $(git rev-list --abbrev-commit -1 first_fixup) fixup! first
1270 x git show HEAD
1271 p $(git rev-list --abbrev-commit -1 second) second
1272 s $(git rev-list --abbrev-commit -1 second_squash) squash! second
1273 x git show HEAD
1274 EOF
1275 git checkout abbrevcmd &&
1276 set_cat_todo_editor &&
1277 test_config rebase.abbreviateCommands true &&
1278 test_must_fail git rebase -i --exec "git show HEAD" \
1279 --autosquash master >actual &&
1280 test_cmp expected actual
1281'
1282
1283test_expect_success 'static check of bad command' '
1284 rebase_setup_and_clean bad-cmd &&
1285 set_fake_editor &&
1286 test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \
1287 git rebase -i --root 2>actual &&
1288 test_i18ngrep "badcmd $(git rev-list --oneline -1 master~1)" actual &&
1289 test_i18ngrep "You can fix this with .git rebase --edit-todo.." actual &&
1290 FAKE_LINES="1 2 3 drop 4 5" git rebase --edit-todo &&
1291 git rebase --continue &&
1292 test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1293 test C = $(git cat-file commit HEAD^ | sed -ne \$p)
1294'
1295
1296test_expect_success 'tabs and spaces are accepted in the todolist' '
1297 rebase_setup_and_clean indented-comment &&
1298 write_script add-indent.sh <<-\EOF &&
1299 (
1300 # Turn single spaces into space/tab mix
1301 sed "1s/ / /g; 2s/ / /g; 3s/ / /g" "$1"
1302 printf "\n\t# comment\n #more\n\t # comment\n"
1303 ) >"$1.new"
1304 mv "$1.new" "$1"
1305 EOF
1306 test_set_editor "$(pwd)/add-indent.sh" &&
1307 git rebase -i HEAD^^^ &&
1308 test E = $(git cat-file commit HEAD | sed -ne \$p)
1309'
1310
1311test_expect_success 'static check of bad SHA-1' '
1312 rebase_setup_and_clean bad-sha &&
1313 set_fake_editor &&
1314 test_must_fail env FAKE_LINES="1 2 edit fakesha 3 4 5 #" \
1315 git rebase -i --root 2>actual &&
1316 test_i18ngrep "edit XXXXXXX False commit" actual &&
1317 test_i18ngrep "You can fix this with .git rebase --edit-todo.." actual &&
1318 FAKE_LINES="1 2 4 5 6" git rebase --edit-todo &&
1319 git rebase --continue &&
1320 test E = $(git cat-file commit HEAD | sed -ne \$p)
1321'
1322
1323test_expect_success 'editor saves as CR/LF' '
1324 git checkout -b with-crlf &&
1325 write_script add-crs.sh <<-\EOF &&
1326 sed -e "s/\$/Q/" <"$1" | tr Q "\\015" >"$1".new &&
1327 mv -f "$1".new "$1"
1328 EOF
1329 (
1330 test_set_editor "$(pwd)/add-crs.sh" &&
1331 git rebase -i HEAD^
1332 )
1333'
1334
1335SQ="'"
1336test_expect_success 'rebase -i --gpg-sign=<key-id>' '
1337 set_fake_editor &&
1338 FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" HEAD^ \
1339 >out 2>err &&
1340 test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err
1341'
1342
1343test_done