79
cat >expect <<-\EOF &&
80
error: nothing to do
81
EOF
82
- set_fake_editor &&
83
- test_must_fail env FAKE_LINES="1 exec_true" git rebase -i HEAD^ >actual 2>&1 &&
82
+ (
83
+ set_fake_editor &&
84
+ test_must_fail env FAKE_LINES="1 exec_true" \
85
+ git rebase -i HEAD^ >actual 2>&1
86
+ ) &&
87
test_i18ncmp expect actual
88
'
89
142
143
test_expect_success 'rebase -i with the exec command checks tree cleanness' '
144
git checkout master &&
142
- set_fake_editor &&
143
- test_must_fail env FAKE_LINES="exec_echo_foo_>file1 1" git rebase -i HEAD^ &&
145
+ (
146
+ set_fake_editor &&
147
+ test_must_fail env FAKE_LINES="exec_echo_foo_>file1 1" \
148
+ git rebase -i HEAD^
149
+ ) &&
150
test_cmp_rev master^ HEAD &&
151
git reset --hard &&
152
git rebase --continue
174
test_expect_success 'rebase -i with exec of inexistent command' '
175
git checkout master &&
176
test_when_finished "git rebase --abort" &&
171
- set_fake_editor &&
172
- test_must_fail env FAKE_LINES="exec_this-command-does-not-exist 1" \
173
- git rebase -i HEAD^ >actual 2>&1 &&
177
+ (
178
+ set_fake_editor &&
179
+ test_must_fail env FAKE_LINES="exec_this-command-does-not-exist 1" \
180
+ git rebase -i HEAD^ >actual 2>&1
181
+ ) &&
182
! grep "Maybe git-rebase is broken" actual
183
'
184
238
'
239
240
test_expect_success 'exchange two commits' '
233
- set_fake_editor &&
234
- FAKE_LINES="2 1" git rebase -i HEAD~2 &&
241
+ (
242
+ set_fake_editor &&
243
+ FAKE_LINES="2 1" git rebase -i HEAD~2
244
+ ) &&
245
test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
246
test G = $(git cat-file commit HEAD | sed -ne \$p)
247
'
342
test_tick &&
343
GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 &&
344
echo "******************************" &&
335
- set_fake_editor &&
336
- FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \
337
- git rebase -i --onto master HEAD~2 &&
345
+ (
346
+ set_fake_editor &&
347
+ FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \
348
+ git rebase -i --onto master HEAD~2
349
+ ) &&
350
test B = $(cat file7) &&
351
test $(git rev-parse HEAD^) = $(git rev-parse master)
352
'
367
368
test_expect_failure REBASE_P 'exchange two commits with -p' '
369
git checkout H &&
358
- set_fake_editor &&
359
- FAKE_LINES="2 1" git rebase -i -p HEAD~2 &&
370
+ (
371
+ set_fake_editor &&
372
+ FAKE_LINES="2 1" git rebase -i -p HEAD~2
373
+ ) &&
374
test H = $(git cat-file commit HEAD^ | sed -ne \$p) &&
375
test G = $(git cat-file commit HEAD | sed -ne \$p)
376
'
419
'
420
421
test_expect_success REBASE_P 'edit ancestor with -p' '
408
- set_fake_editor &&
409
- FAKE_LINES="1 2 edit 3 4" git rebase -i -p HEAD~3 &&
422
+ (
423
+ set_fake_editor &&
424
+ FAKE_LINES="1 2 edit 3 4" git rebase -i -p HEAD~3
425
+ ) &&
426
echo 2 > unrelated-file &&
427
test_tick &&
428
git commit -m L2-modified --amend unrelated-file &&
436
test_expect_success '--continue tries to commit' '
437
git reset --hard D &&
438
test_tick &&
423
- set_fake_editor &&
424
- test_must_fail git rebase -i --onto new-branch1 HEAD^ &&
425
- echo resolved > file1 &&
426
- git add file1 &&
427
- FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
439
+ (
440
+ set_fake_editor &&
441
+ test_must_fail git rebase -i --onto new-branch1 HEAD^ &&
442
+ echo resolved > file1 &&
443
+ git add file1 &&
444
+ FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue
445
+ ) &&
446
test $(git rev-parse HEAD^) = $(git rev-parse new-branch1) &&
447
git show HEAD | grep chouette
448
'
460
461
test_expect_success C_LOCALE_OUTPUT 'multi-squash only fires up editor once' '
462
base=$(git rev-parse HEAD~4) &&
445
- set_fake_editor &&
446
- FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 squash 2 squash 3 squash 4" \
447
- EXPECT_HEADER_COUNT=4 \
448
- git rebase -i $base &&
463
+ (
464
+ set_fake_editor &&
465
+ FAKE_COMMIT_AMEND="ONCE" \
466
+ FAKE_LINES="1 squash 2 squash 3 squash 4" \
467
+ EXPECT_HEADER_COUNT=4 \
468
+ git rebase -i $base
469
+ ) &&
470
test $base = $(git rev-parse HEAD^) &&
471
test 1 = $(git show | grep ONCE | wc -l)
472
'
474
test_expect_success C_LOCALE_OUTPUT 'multi-fixup does not fire up editor' '
475
git checkout -b multi-fixup E &&
476
base=$(git rev-parse HEAD~4) &&
456
- set_fake_editor &&
457
- FAKE_COMMIT_AMEND="NEVER" FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \
458
- git rebase -i $base &&
477
+ (
478
+ set_fake_editor &&
479
+ FAKE_COMMIT_AMEND="NEVER" \
480
+ FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \
481
+ git rebase -i $base
482
+ ) &&
483
test $base = $(git rev-parse HEAD^) &&
484
test 0 = $(git show | grep NEVER | wc -l) &&
485
git checkout @{-1} &&
489
test_expect_success 'commit message used after conflict' '
490
git checkout -b conflict-fixup conflict-branch &&
491
base=$(git rev-parse HEAD~4) &&
468
- set_fake_editor &&
469
- test_must_fail env FAKE_LINES="1 fixup 3 fixup 4" git rebase -i $base &&
470
- echo three > conflict &&
471
- git add conflict &&
472
- FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \
473
- git rebase --continue &&
492
+ (
493
+ set_fake_editor &&
494
+ test_must_fail env FAKE_LINES="1 fixup 3 fixup 4" \
495
+ git rebase -i $base &&
496
+ echo three > conflict &&
497
+ git add conflict &&
498
+ FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \
499
+ git rebase --continue
500
+ ) &&
501
test $base = $(git rev-parse HEAD^) &&
502
test 1 = $(git show | grep ONCE | wc -l) &&
503
git checkout @{-1} &&
507
test_expect_success 'commit message retained after conflict' '
508
git checkout -b conflict-squash conflict-branch &&
509
base=$(git rev-parse HEAD~4) &&
483
- set_fake_editor &&
484
- test_must_fail env FAKE_LINES="1 fixup 3 squash 4" git rebase -i $base &&
485
- echo three > conflict &&
486
- git add conflict &&
487
- FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \
488
- git rebase --continue &&
510
+ (
511
+ set_fake_editor &&
512
+ test_must_fail env FAKE_LINES="1 fixup 3 squash 4" \
513
+ git rebase -i $base &&
514
+ echo three > conflict &&
515
+ git add conflict &&
516
+ FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \
517
+ git rebase --continue
518
+ ) &&
519
test $base = $(git rev-parse HEAD^) &&
520
test 2 = $(git show | grep TWICE | wc -l) &&
521
git checkout @{-1} &&
532
EOF
533
git checkout -b squash-fixup E &&
534
base=$(git rev-parse HEAD~4) &&
505
- set_fake_editor &&
506
- FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 fixup 2 squash 3 fixup 4" \
507
- EXPECT_HEADER_COUNT=4 \
508
- git rebase -i $base &&
535
+ (
536
+ set_fake_editor &&
537
+ FAKE_COMMIT_AMEND="ONCE" \
538
+ FAKE_LINES="1 fixup 2 squash 3 fixup 4" \
539
+ EXPECT_HEADER_COUNT=4 \
540
+ git rebase -i $base
541
+ ) &&
542
git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup &&
543
test_cmp expect-squash-fixup actual-squash-fixup &&
544
git cat-file commit HEAD@{2} |
552
test_expect_success C_LOCALE_OUTPUT 'squash ignores comments' '
553
git checkout -b skip-comments E &&
554
base=$(git rev-parse HEAD~4) &&
522
- set_fake_editor &&
523
- FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \
524
- EXPECT_HEADER_COUNT=4 \
525
- git rebase -i $base &&
555
+ (
556
+ set_fake_editor &&
557
+ FAKE_COMMIT_AMEND="ONCE" \
558
+ FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \
559
+ EXPECT_HEADER_COUNT=4 \
560
+ git rebase -i $base
561
+ ) &&
562
test $base = $(git rev-parse HEAD^) &&
563
test 1 = $(git show | grep ONCE | wc -l) &&
564
git checkout @{-1} &&
568
test_expect_success C_LOCALE_OUTPUT 'squash ignores blank lines' '
569
git checkout -b skip-blank-lines E &&
570
base=$(git rev-parse HEAD~4) &&
535
- set_fake_editor &&
536
- FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \
537
- EXPECT_HEADER_COUNT=4 \
538
- git rebase -i $base &&
571
+ (
572
+ set_fake_editor &&
573
+ FAKE_COMMIT_AMEND="ONCE" \
574
+ FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \
575
+ EXPECT_HEADER_COUNT=4 \
576
+ git rebase -i $base
577
+ ) &&
578
test $base = $(git rev-parse HEAD^) &&
579
test 1 = $(git show | grep ONCE | wc -l) &&
580
git checkout @{-1} &&
584
test_expect_success 'squash works as expected' '
585
git checkout -b squash-works no-conflict-branch &&
586
one=$(git rev-parse HEAD~3) &&
548
- set_fake_editor &&
549
- FAKE_LINES="1 s 3 2" EXPECT_HEADER_COUNT=2 \
550
- git rebase -i HEAD~3 &&
587
+ (
588
+ set_fake_editor &&
589
+ FAKE_LINES="1 s 3 2" EXPECT_HEADER_COUNT=2 git rebase -i HEAD~3
590
+ ) &&
591
test $one = $(git rev-parse HEAD~2)
592
'
593
594
test_expect_success 'interrupted squash works as expected' '
595
git checkout -b interrupted-squash conflict-branch &&
596
one=$(git rev-parse HEAD~3) &&
557
- set_fake_editor &&
558
- test_must_fail env FAKE_LINES="1 squash 3 2" git rebase -i HEAD~3 &&
597
+ (
598
+ set_fake_editor &&
599
+ test_must_fail env FAKE_LINES="1 squash 3 2" \
600
+ git rebase -i HEAD~3
601
+ ) &&
602
test_write_lines one two four > conflict &&
603
git add conflict &&
604
test_must_fail git rebase --continue &&
611
test_expect_success 'interrupted squash works as expected (case 2)' '
612
git checkout -b interrupted-squash2 conflict-branch &&
613
one=$(git rev-parse HEAD~3) &&
571
- set_fake_editor &&
572
- test_must_fail env FAKE_LINES="3 squash 1 2" git rebase -i HEAD~3 &&
614
+ (
615
+ set_fake_editor &&
616
+ test_must_fail env FAKE_LINES="3 squash 1 2" \
617
+ git rebase -i HEAD~3
618
+ ) &&
619
test_write_lines one four > conflict &&
620
git add conflict &&
621
test_must_fail git rebase --continue &&
635
git commit -m "unrelated change" &&
636
parent=$(git rev-parse HEAD^) &&
637
test_tick &&
592
- set_fake_editor &&
593
- FAKE_LINES="edit 1" git rebase -i HEAD^ &&
594
- echo edited > file7 &&
595
- git add file7 &&
596
- FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue &&
638
+ (
639
+ set_fake_editor &&
640
+ FAKE_LINES="edit 1" git rebase -i HEAD^ &&
641
+ echo edited > file7 &&
642
+ git add file7 &&
643
+ FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue
644
+ ) &&
645
test edited = $(git show HEAD:file7) &&
646
git show HEAD | grep chouette &&
647
test $parent = $(git rev-parse HEAD^)
650
test_expect_success 'aborted --continue does not squash commits after "edit"' '
651
old=$(git rev-parse HEAD) &&
652
test_tick &&
605
- set_fake_editor &&
606
- FAKE_LINES="edit 1" git rebase -i HEAD^ &&
607
- echo "edited again" > file7 &&
608
- git add file7 &&
609
- test_must_fail env FAKE_COMMIT_MESSAGE=" " git rebase --continue &&
653
+ (
654
+ set_fake_editor &&
655
+ FAKE_LINES="edit 1" git rebase -i HEAD^ &&
656
+ echo "edited again" > file7 &&
657
+ git add file7 &&
658
+ test_must_fail env FAKE_COMMIT_MESSAGE=" " git rebase --continue
659
+ ) &&
660
test $old = $(git rev-parse HEAD) &&
661
git rebase --abort
662
'
663
664
test_expect_success 'auto-amend only edited commits after "edit"' '
665
test_tick &&
616
- set_fake_editor &&
617
- FAKE_LINES="edit 1" git rebase -i HEAD^ &&
618
- echo "edited again" > file7 &&
619
- git add file7 &&
620
- FAKE_COMMIT_MESSAGE="edited file7 again" git commit &&
621
- echo "and again" > file7 &&
622
- git add file7 &&
623
- test_tick &&
624
- test_must_fail env FAKE_COMMIT_MESSAGE="and again" git rebase --continue &&
666
+ (
667
+ set_fake_editor &&
668
+ FAKE_LINES="edit 1" git rebase -i HEAD^ &&
669
+ echo "edited again" > file7 &&
670
+ git add file7 &&
671
+ FAKE_COMMIT_MESSAGE="edited file7 again" git commit &&
672
+ echo "and again" > file7 &&
673
+ git add file7 &&
674
+ test_tick &&
675
+ test_must_fail env FAKE_COMMIT_MESSAGE="and again" \
676
+ git rebase --continue
677
+ ) &&
678
git rebase --abort
679
'
680
681
test_expect_success 'clean error after failed "exec"' '
682
test_tick &&
683
test_when_finished "git rebase --abort || :" &&
631
- set_fake_editor &&
632
- test_must_fail env FAKE_LINES="1 exec_false" git rebase -i HEAD^ &&
684
+ (
685
+ set_fake_editor &&
686
+ test_must_fail env FAKE_LINES="1 exec_false" git rebase -i HEAD^
687
+ ) &&
688
echo "edited again" > file7 &&
689
git add file7 &&
690
test_must_fail git rebase --continue 2>error &&
695
grandparent=$(git rev-parse HEAD~2) &&
696
git checkout $(git rev-parse HEAD) &&
697
test_tick &&
643
- set_fake_editor &&
644
- FAKE_LINES="2 1" git rebase -i HEAD~2 &&
698
+ (
699
+ set_fake_editor &&
700
+ FAKE_LINES="2 1" git rebase -i HEAD~2
701
+ ) &&
702
test $grandparent = $(git rev-parse HEAD~2)
703
'
704
713
test_must_fail git commit -m doesnt-verify file1 &&
714
git commit -m doesnt-verify --no-verify file1 &&
715
test_tick &&
659
- set_fake_editor &&
660
- FAKE_LINES=2 git rebase -i HEAD~2
661
-
716
+ (
717
+ set_fake_editor &&
718
+ FAKE_LINES=2 git rebase -i HEAD~2
719
+ )
720
'
721
722
test_expect_success 'rebase with a file named HEAD in worktree' '
736
git commit -m "Add body"
737
) &&
738
681
- set_fake_editor &&
682
- FAKE_LINES="1 squash 2" git rebase -i @{-1} &&
739
+ (
740
+ set_fake_editor &&
741
+ FAKE_LINES="1 squash 2" git rebase -i @{-1}
742
+ ) &&
743
test "$(git show -s --pretty=format:%an)" = "Squashed Away"
744
745
'
780
'
781
782
test_expect_success 'submodule rebase -i' '
723
- set_fake_editor &&
724
- FAKE_LINES="1 squash 2 3" git rebase -i A
783
+ (
784
+ set_fake_editor &&
785
+ FAKE_LINES="1 squash 2 3" git rebase -i A
786
+ )
787
'
788
789
test_expect_success 'submodule conflict setup' '
832
833
test_expect_success 'reword' '
834
git checkout -b reword-branch master &&
773
- set_fake_editor &&
774
- FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" git rebase -i A &&
775
- git show HEAD | grep "E changed" &&
776
- test $(git rev-parse master) != $(git rev-parse HEAD) &&
777
- test $(git rev-parse master^) = $(git rev-parse HEAD^) &&
778
- FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" git rebase -i A &&
779
- git show HEAD^ | grep "D changed" &&
780
- FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" git rebase -i A &&
781
- git show HEAD~3 | grep "B changed" &&
782
- FAKE_LINES="1 r 2 pick 3 p 4" FAKE_COMMIT_MESSAGE="C changed" git rebase -i A &&
835
+ (
836
+ set_fake_editor &&
837
+ FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" \
838
+ git rebase -i A &&
839
+ git show HEAD | grep "E changed" &&
840
+ test $(git rev-parse master) != $(git rev-parse HEAD) &&
841
+ test $(git rev-parse master^) = $(git rev-parse HEAD^) &&
842
+ FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" \
843
+ git rebase -i A &&
844
+ git show HEAD^ | grep "D changed" &&
845
+ FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" \
846
+ git rebase -i A &&
847
+ git show HEAD~3 | grep "B changed" &&
848
+ FAKE_LINES="1 r 2 pick 3 p 4" FAKE_COMMIT_MESSAGE="C changed" \
849
+ git rebase -i A
850
+ ) &&
851
git show HEAD~2 | grep "C changed"
852
'
853
871
EOF
872
git reset --hard n3 &&
873
git notes add -m"an earlier note" n2 &&
806
- set_fake_editor &&
807
- GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 f 2" git rebase -i n1 &&
874
+ (
875
+ set_fake_editor &&
876
+ GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 f 2" \
877
+ git rebase -i n1
878
+ ) &&
879
git notes show > output &&
880
test_cmp expect output
881
'
884
git symbolic-ref HEAD &&
885
grandparent=$(git rev-parse HEAD~2) &&
886
test_tick &&
816
- set_fake_editor &&
817
- FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0 &&
887
+ (
888
+ set_fake_editor &&
889
+ FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0
890
+ ) &&
891
test $grandparent = $(git rev-parse HEAD~2) &&
892
test_must_fail git symbolic-ref HEAD
893
'
928
test_expect_success 'rebase-i history with funny messages' '
929
git rev-list A..funny >expect &&
930
test_tick &&
858
- set_fake_editor &&
859
- FAKE_LINES="1 2 3 4" git rebase -i A &&
931
+ (
932
+ set_fake_editor &&
933
+ FAKE_LINES="1 2 3 4" git rebase -i A
934
+ ) &&
935
git rev-list A.. >actual &&
936
test_cmp expect actual
937
'
945
'
946
947
test_expect_success 'running "git rebase -i --exec git show HEAD"' '
873
- set_fake_editor &&
874
- git rebase -i --exec "git show HEAD" HEAD~2 >actual &&
948
(
949
+ set_fake_editor &&
950
+ git rebase -i --exec "git show HEAD" HEAD~2 >actual &&
951
FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
952
export FAKE_LINES &&
953
git rebase -i HEAD~2 >expect
958
959
test_expect_success 'running "git rebase --exec git show HEAD -i"' '
960
git reset --hard execute &&
886
- set_fake_editor &&
887
- git rebase --exec "git show HEAD" -i HEAD~2 >actual &&
961
(
962
+ set_fake_editor &&
963
+ git rebase --exec "git show HEAD" -i HEAD~2 >actual &&
964
FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
965
export FAKE_LINES &&
966
git rebase -i HEAD~2 >expect
971
972
test_expect_success 'running "git rebase -ix git show HEAD"' '
973
git reset --hard execute &&
899
- set_fake_editor &&
900
- git rebase -ix "git show HEAD" HEAD~2 >actual &&
974
(
975
+ set_fake_editor &&
976
+ git rebase -ix "git show HEAD" HEAD~2 >actual &&
977
FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
978
export FAKE_LINES &&
979
git rebase -i HEAD~2 >expect
985
986
test_expect_success 'rebase -ix with several <CMD>' '
987
git reset --hard execute &&
913
- set_fake_editor &&
914
- git rebase -ix "git show HEAD; pwd" HEAD~2 >actual &&
988
(
989
+ set_fake_editor &&
990
+ git rebase -ix "git show HEAD; pwd" HEAD~2 >actual &&
991
FAKE_LINES="1 exec_git_show_HEAD;_pwd 2 exec_git_show_HEAD;_pwd" &&
992
export FAKE_LINES &&
993
git rebase -i HEAD~2 >expect
998
999
test_expect_success 'rebase -ix with several instances of --exec' '
1000
git reset --hard execute &&
926
- set_fake_editor &&
927
- git rebase -i --exec "git show HEAD" --exec "pwd" HEAD~2 >actual &&
1001
(
1002
+ set_fake_editor &&
1003
+ git rebase -i --exec "git show HEAD" --exec "pwd" HEAD~2 >actual &&
1004
FAKE_LINES="1 exec_git_show_HEAD exec_pwd 2
1005
exec_git_show_HEAD exec_pwd" &&
1006
export FAKE_LINES &&
1019
echo bis >bis.txt &&
1020
git add bis.txt &&
1021
git commit -m "fixup! two_exec" &&
947
- set_fake_editor &&
1022
git checkout -b autosquash_actual &&
1023
git rebase -i --exec "git show HEAD" --autosquash HEAD~4 >actual &&
1024
git checkout autosquash &&
1025
(
1026
+ set_fake_editor &&
1027
git checkout -b autosquash_expected &&
1028
FAKE_LINES="1 fixup 3 fixup 4 exec_git_show_HEAD 2 exec_git_show_HEAD" &&
1029
export FAKE_LINES &&
1052
1053
test_expect_success 'rebase -i --root re-order and drop commits' '
1054
git checkout E &&
980
- set_fake_editor &&
981
- FAKE_LINES="3 1 2 5" git rebase -i --root &&
1055
+ (
1056
+ set_fake_editor &&
1057
+ FAKE_LINES="3 1 2 5" git rebase -i --root
1058
+ ) &&
1059
test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1060
test B = $(git cat-file commit HEAD^ | sed -ne \$p) &&
1061
test A = $(git cat-file commit HEAD^^ | sed -ne \$p) &&
1068
echo B >file7 &&
1069
git add file7 &&
1070
GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
994
- set_fake_editor &&
995
- FAKE_LINES="2" git rebase -i --root &&
1071
+ (
1072
+ set_fake_editor &&
1073
+ FAKE_LINES="2" git rebase -i --root
1074
+ ) &&
1075
git cat-file commit HEAD | grep -q "^author Twerp Snog" &&
1076
git cat-file commit HEAD | grep -q "^different author$"
1077
'
1078
1079
test_expect_success 'rebase -i --root temporary sentinel commit' '
1080
git checkout B &&
1002
- set_fake_editor &&
1003
- test_must_fail env FAKE_LINES="2" git rebase -i --root &&
1081
+ (
1082
+ set_fake_editor &&
1083
+ test_must_fail env FAKE_LINES="2" git rebase -i --root
1084
+ ) &&
1085
git cat-file commit HEAD | grep "^tree 4b825dc642cb" &&
1086
git rebase --abort
1087
'
1088
1089
test_expect_success 'rebase -i --root fixup root commit' '
1090
git checkout B &&
1010
- set_fake_editor &&
1011
- FAKE_LINES="1 fixup 2" git rebase -i --root &&
1091
+ (
1092
+ set_fake_editor &&
1093
+ FAKE_LINES="1 fixup 2" git rebase -i --root
1094
+ ) &&
1095
test A = $(git cat-file commit HEAD | sed -ne \$p) &&
1096
test B = $(git show HEAD:file1) &&
1097
test 0 = $(git cat-file commit HEAD | grep -c ^parent\ )
1100
test_expect_success 'rebase -i --root reword original root commit' '
1101
test_when_finished "test_might_fail git rebase --abort" &&
1102
git checkout -b reword-original-root-branch master &&
1020
- set_fake_editor &&
1021
- FAKE_LINES="reword 1 2" FAKE_COMMIT_MESSAGE="A changed" \
1022
- git rebase -i --root &&
1103
+ (
1104
+ set_fake_editor &&
1105
+ FAKE_LINES="reword 1 2" FAKE_COMMIT_MESSAGE="A changed" \
1106
+ git rebase -i --root
1107
+ ) &&
1108
git show HEAD^ | grep "A changed" &&
1109
test -z "$(git show -s --format=%p HEAD^)"
1110
'
1112
test_expect_success 'rebase -i --root reword new root commit' '
1113
test_when_finished "test_might_fail git rebase --abort" &&
1114
git checkout -b reword-now-root-branch master &&
1030
- set_fake_editor &&
1031
- FAKE_LINES="reword 3 1" FAKE_COMMIT_MESSAGE="C changed" \
1032
- git rebase -i --root &&
1115
+ (
1116
+ set_fake_editor &&
1117
+ FAKE_LINES="reword 3 1" FAKE_COMMIT_MESSAGE="C changed" \
1118
+ git rebase -i --root
1119
+ ) &&
1120
git show HEAD^ | grep "C changed" &&
1121
test -z "$(git show -s --format=%p HEAD^)"
1122
'
1128
git rm file1 &&
1129
git commit -m "remove file 1 add file 2" &&
1130
echo z >file1 &&
1044
- set_fake_editor &&
1045
- test_must_fail env FAKE_LINES="1 2" git rebase -i --root &&
1131
+ (
1132
+ set_fake_editor &&
1133
+ test_must_fail env FAKE_LINES="1 2" git rebase -i --root
1134
+ ) &&
1135
rm file1 &&
1136
git rebase --continue &&
1137
test "$(git log -1 --format=%B)" = "remove file 1 add file 2" &&
1141
test_expect_success 'rebase -i --root reword root when root has untracked file conflict' '
1142
test_when_finished "reset_rebase" &&
1143
echo z>file1 &&
1055
- set_fake_editor &&
1056
- test_must_fail env FAKE_LINES="reword 1 2" \
1057
- FAKE_COMMIT_MESSAGE="Modified A" git rebase -i --root &&
1058
- rm file1 &&
1059
- FAKE_COMMIT_MESSAGE="Reworded A" git rebase --continue &&
1144
+ (
1145
+ set_fake_editor &&
1146
+ test_must_fail env FAKE_LINES="reword 1 2" \
1147
+ FAKE_COMMIT_MESSAGE="Modified A" git rebase -i --root &&
1148
+ rm file1 &&
1149
+ FAKE_COMMIT_MESSAGE="Reworded A" git rebase --continue
1150
+ ) &&
1151
test "$(git log -1 --format=%B HEAD^)" = "Reworded A" &&
1152
test "$(git rev-list --count HEAD)" = 2
1153
'
1156
git checkout reword-original-root-branch &&
1157
git reset --hard &&
1158
git checkout conflict-branch &&
1068
- set_fake_editor &&
1069
- test_must_fail git rebase --onto HEAD~2 HEAD~ &&
1070
- test_must_fail git rebase --edit-todo &&
1159
+ (
1160
+ set_fake_editor &&
1161
+ test_must_fail git rebase --onto HEAD~2 HEAD~ &&
1162
+ test_must_fail git rebase --edit-todo
1163
+ ) &&
1164
git rebase --abort
1165
'
1166
1167
test_expect_success 'rebase --edit-todo can be used to modify todo' '
1168
git reset --hard &&
1169
git checkout no-conflict-branch^0 &&
1077
- set_fake_editor &&
1078
- FAKE_LINES="edit 1 2 3" git rebase -i HEAD~3 &&
1079
- FAKE_LINES="2 1" git rebase --edit-todo &&
1080
- git rebase --continue &&
1170
+ (
1171
+ set_fake_editor &&
1172
+ FAKE_LINES="edit 1 2 3" git rebase -i HEAD~3 &&
1173
+ FAKE_LINES="2 1" git rebase --edit-todo &&
1174
+ git rebase --continue
1175
+ ) &&
1176
test M = $(git cat-file commit HEAD^ | sed -ne \$p) &&
1177
test L = $(git cat-file commit HEAD | sed -ne \$p)
1178
'
1201
sed -e "2,\$s/^/\\\\/" "$1" >"$1.tmp" &&
1202
mv "$1.tmp" "$1"
1203
EOF
1109
- test_set_editor "$(pwd)/remove-all-but-first.sh" &&
1110
- git rebase -i B &&
1204
+ (
1205
+ test_set_editor "$(pwd)/remove-all-but-first.sh" &&
1206
+ git rebase -i B
1207
+ ) &&
1208
test B = $(git cat-file commit HEAD^ | sed -ne \$p)
1209
'
1210
1213
write_script copy-edit-script.sh <<-\EOF &&
1214
cp "$1" edit-script
1215
EOF
1119
- test_set_editor "$(pwd)/copy-edit-script.sh" &&
1216
test_when_finished "git rebase --abort || :" &&
1121
- git rebase -i HEAD^ &&
1217
+ (
1218
+ test_set_editor "$(pwd)/copy-edit-script.sh" &&
1219
+ git rebase -i HEAD^
1220
+ ) &&
1221
test -z "$(grep -ve "^#" -e "^\$" -e "^pick" edit-script)"
1222
'
1223
1252
echo five >conflict &&
1253
echo Z >file1 &&
1254
git commit -a -m "one file conflict" &&
1156
- set_fake_editor &&
1157
- FAKE_LINES="edit 1 2" git rebase -i --strategy=recursive -Xours conflict-branch &&
1255
+ (
1256
+ set_fake_editor &&
1257
+ FAKE_LINES="edit 1 2" git rebase -i --strategy=recursive \
1258
+ -Xours conflict-branch
1259
+ ) &&
1260
git rebase --continue &&
1261
test $(git show conflict-branch:conflict) = $(cat conflict) &&
1262
test $(cat file1) = Z
1297
1298
test_expect_success 'respect core.abbrev' '
1299
git config core.abbrev 12 &&
1198
- set_cat_todo_editor &&
1199
- test_must_fail git rebase -i HEAD~4 >todo-list &&
1300
+ (
1301
+ set_cat_todo_editor &&
1302
+ test_must_fail git rebase -i HEAD~4 >todo-list
1303
+ ) &&
1304
test 4 = $(grep -c "pick [0-9a-f]\{12,\}" todo-list)
1305
'
1306
1308
write_script dump-raw.sh <<-\EOF &&
1309
cat "$1"
1310
EOF
1207
- test_set_editor "$(pwd)/dump-raw.sh" &&
1208
- git rebase -i HEAD~4 >actual &&
1311
+ (
1312
+ test_set_editor "$(pwd)/dump-raw.sh" &&
1313
+ git rebase -i HEAD~4 >actual
1314
+ ) &&
1315
test_i18ngrep "^# Rebase ..* onto ..* ([0-9]" actual
1316
'
1317
1318
test_expect_success 'rebase -i commits that overwrite untracked files (pick)' '
1319
git checkout --force branch2 &&
1320
git clean -f &&
1215
- set_fake_editor &&
1216
- FAKE_LINES="edit 1 2" git rebase -i A &&
1321
+ (
1322
+ set_fake_editor &&
1323
+ FAKE_LINES="edit 1 2" git rebase -i A
1324
+ ) &&
1325
test_cmp_rev HEAD F &&
1326
test_path_is_missing file6 &&
1327
>file6 &&
1336
git checkout --force branch2 &&
1337
git clean -f &&
1338
git tag original-branch2 &&
1231
- set_fake_editor &&
1232
- FAKE_LINES="edit 1 squash 2" git rebase -i A &&
1339
+ (
1340
+ set_fake_editor &&
1341
+ FAKE_LINES="edit 1 squash 2" git rebase -i A
1342
+ ) &&
1343
test_cmp_rev HEAD F &&
1344
test_path_is_missing file6 &&
1345
>file6 &&
1354
test_expect_success 'rebase -i commits that overwrite untracked files (no ff)' '
1355
git checkout --force branch2 &&
1356
git clean -f &&
1247
- set_fake_editor &&
1248
- FAKE_LINES="edit 1 2" git rebase -i --no-ff A &&
1357
+ (
1358
+ set_fake_editor &&
1359
+ FAKE_LINES="edit 1 2" git rebase -i --no-ff A
1360
+ ) &&
1361
test $(git cat-file commit HEAD | sed -ne \$p) = F &&
1362
test_path_is_missing file6 &&
1363
>file6 &&
1380
git tag seq-onto &&
1381
git reset --hard HEAD~2 &&
1382
git cherry-pick seq-onto &&
1271
- set_fake_editor &&
1272
- test_must_fail env FAKE_LINES= git rebase -i seq-onto &&
1383
+ (
1384
+ set_fake_editor &&
1385
+ test_must_fail env FAKE_LINES= git rebase -i seq-onto
1386
+ ) &&
1387
test -d .git/rebase-merge &&
1388
git rebase --continue &&
1389
git diff --exit-code seq-onto &&
1402
1403
test_expect_success 'drop' '
1404
rebase_setup_and_clean drop-test &&
1291
- set_fake_editor &&
1292
- FAKE_LINES="1 drop 2 3 d 4 5" git rebase -i --root &&
1405
+ (
1406
+ set_fake_editor &&
1407
+ FAKE_LINES="1 drop 2 3 d 4 5" git rebase -i --root
1408
+ ) &&
1409
test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1410
test C = $(git cat-file commit HEAD^ | sed -ne \$p) &&
1411
test A = $(git cat-file commit HEAD^^ | sed -ne \$p)
1414
test_expect_success 'rebase -i respects rebase.missingCommitsCheck = ignore' '
1415
test_config rebase.missingCommitsCheck ignore &&
1416
rebase_setup_and_clean missing-commit &&
1301
- set_fake_editor &&
1302
- FAKE_LINES="1 2 3 4" \
1303
- git rebase -i --root 2>actual &&
1417
+ (
1418
+ set_fake_editor &&
1419
+ FAKE_LINES="1 2 3 4" git rebase -i --root 2>actual
1420
+ ) &&
1421
test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1422
test_i18ngrep \
1423
"Successfully rebased and updated refs/heads/missing-commit" \
1433
EOF
1434
test_config rebase.missingCommitsCheck warn &&
1435
rebase_setup_and_clean missing-commit &&
1319
- set_fake_editor &&
1320
- FAKE_LINES="1 2 3 4" \
1321
- git rebase -i --root 2>actual.2 &&
1436
+ (
1437
+ set_fake_editor &&
1438
+ FAKE_LINES="1 2 3 4" git rebase -i --root 2>actual.2
1439
+ ) &&
1440
head -n4 actual.2 >actual &&
1441
test_i18ncmp expect actual &&
1442
test D = $(git cat-file commit HEAD | sed -ne \$p)
1458
EOF
1459
test_config rebase.missingCommitsCheck error &&
1460
rebase_setup_and_clean missing-commit &&
1343
- set_fake_editor &&
1344
- test_must_fail env FAKE_LINES="1 2 4" \
1345
- git rebase -i --root 2>actual &&
1346
- test_i18ncmp expect actual &&
1347
- cp .git/rebase-merge/git-rebase-todo.backup \
1348
- .git/rebase-merge/git-rebase-todo &&
1349
- FAKE_LINES="1 2 drop 3 4 drop 5" \
1350
- git rebase --edit-todo &&
1461
+ (
1462
+ set_fake_editor &&
1463
+ test_must_fail env FAKE_LINES="1 2 4" \
1464
+ git rebase -i --root 2>actual &&
1465
+ test_i18ncmp expect actual &&
1466
+ cp .git/rebase-merge/git-rebase-todo.backup \
1467
+ .git/rebase-merge/git-rebase-todo &&
1468
+ FAKE_LINES="1 2 drop 3 4 drop 5" git rebase --edit-todo
1469
+ ) &&
1470
git rebase --continue &&
1471
test D = $(git cat-file commit HEAD | sed -ne \$p) &&
1472
test B = $(git cat-file commit HEAD^ | sed -ne \$p)
1487
x git show HEAD
1488
EOF
1489
git checkout abbrevcmd &&
1371
- set_cat_todo_editor &&
1490
test_config rebase.abbreviateCommands true &&
1373
- test_must_fail git rebase -i --exec "git show HEAD" \
1374
- --autosquash master >actual &&
1491
+ (
1492
+ set_cat_todo_editor &&
1493
+ test_must_fail git rebase -i --exec "git show HEAD" \
1494
+ --autosquash master >actual
1495
+ ) &&
1496
test_cmp expected actual
1497
'
1498
1499
test_expect_success 'static check of bad command' '
1500
rebase_setup_and_clean bad-cmd &&
1380
- set_fake_editor &&
1381
- test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \
1501
+ (
1502
+ set_fake_editor &&
1503
+ test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \
1504
git rebase -i --root 2>actual &&
1383
- test_i18ngrep "badcmd $(git rev-list --oneline -1 master~1)" actual &&
1384
- test_i18ngrep "You can fix this with .git rebase --edit-todo.." actual &&
1385
- FAKE_LINES="1 2 3 drop 4 5" git rebase --edit-todo &&
1505
+ test_i18ngrep "badcmd $(git rev-list --oneline -1 master~1)" \
1506
+ actual &&
1507
+ test_i18ngrep "You can fix this with .git rebase --edit-todo.." \
1508
+ actual &&
1509
+ FAKE_LINES="1 2 3 drop 4 5" git rebase --edit-todo
1510
+ ) &&
1511
git rebase --continue &&
1512
test E = $(git cat-file commit HEAD | sed -ne \$p) &&
1513
test C = $(git cat-file commit HEAD^ | sed -ne \$p)
1523
) >"$1.new"
1524
mv "$1.new" "$1"
1525
EOF
1401
- test_set_editor "$(pwd)/add-indent.sh" &&
1402
- git rebase -i HEAD^^^ &&
1526
+ (
1527
+ test_set_editor "$(pwd)/add-indent.sh" &&
1528
+ git rebase -i HEAD^^^
1529
+ ) &&
1530
test E = $(git cat-file commit HEAD | sed -ne \$p)
1531
'
1532
1533
test_expect_success 'static check of bad SHA-1' '
1534
rebase_setup_and_clean bad-sha &&
1408
- set_fake_editor &&
1409
- test_must_fail env FAKE_LINES="1 2 edit fakesha 3 4 5 #" \
1410
- git rebase -i --root 2>actual &&
1411
- test_i18ngrep "edit XXXXXXX False commit" actual &&
1412
- test_i18ngrep "You can fix this with .git rebase --edit-todo.." actual &&
1413
- FAKE_LINES="1 2 4 5 6" git rebase --edit-todo &&
1535
+ (
1536
+ set_fake_editor &&
1537
+ test_must_fail env FAKE_LINES="1 2 edit fakesha 3 4 5 #" \
1538
+ git rebase -i --root 2>actual &&
1539
+ test_i18ngrep "edit XXXXXXX False commit" actual &&
1540
+ test_i18ngrep "You can fix this with .git rebase --edit-todo.." \
1541
+ actual &&
1542
+ FAKE_LINES="1 2 4 5 6" git rebase --edit-todo
1543
+ ) &&
1544
git rebase --continue &&
1545
test E = $(git cat-file commit HEAD | sed -ne \$p)
1546
'
1560
SQ="'"
1561
test_expect_success 'rebase -i --gpg-sign=<key-id>' '
1562
test_when_finished "test_might_fail git rebase --abort" &&
1433
- set_fake_editor &&
1434
- FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" HEAD^ \
1435
- >out 2>err &&
1563
+ (
1564
+ set_fake_editor &&
1565
+ FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" \
1566
+ HEAD^ >out 2>err
1567
+ ) &&
1568
test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err
1569
'
1570
1571
test_expect_success 'rebase -i --gpg-sign=<key-id> overrides commit.gpgSign' '
1572
test_when_finished "test_might_fail git rebase --abort" &&
1573
test_config commit.gpgsign true &&
1442
- set_fake_editor &&
1443
- FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" HEAD^ \
1444
- >out 2>err &&
1574
+ (
1575
+ set_fake_editor &&
1576
+ FAKE_LINES="edit 1" git rebase -i --gpg-sign="\"S I Gner\"" \
1577
+ HEAD^ >out 2>err
1578
+ ) &&
1579
test_i18ngrep "$SQ-S\"S I Gner\"$SQ" err
1580
'
1581
1582
test_expect_success 'valid author header after --root swap' '
1583
rebase_setup_and_clean author-header no-conflict-branch &&
1450
- set_fake_editor &&
1584
git commit --amend --author="Au ${SQ}thor <author@example.com>" --no-edit &&
1585
git cat-file commit HEAD | grep ^author >expected &&
1453
- FAKE_LINES="5 1" git rebase -i --root &&
1586
+ (
1587
+ set_fake_editor &&
1588
+ FAKE_LINES="5 1" git rebase -i --root
1589
+ ) &&
1590
git cat-file commit HEAD^ | grep ^author >actual &&
1591
test_cmp expected actual
1592
'
1593
1594
test_expect_success 'valid author header when author contains single quote' '
1595
rebase_setup_and_clean author-header no-conflict-branch &&
1460
- set_fake_editor &&
1596
git commit --amend --author="Au ${SQ}thor <author@example.com>" --no-edit &&
1597
git cat-file commit HEAD | grep ^author >expected &&
1463
- FAKE_LINES="2" git rebase -i HEAD~2 &&
1598
+ (
1599
+ set_fake_editor &&
1600
+ FAKE_LINES="2" git rebase -i HEAD~2
1601
+ ) &&
1602
git cat-file commit HEAD | grep ^author >actual &&
1603
test_cmp expected actual
1604
'