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