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