30
. "$TEST_DIRECTORY"/lib-gpg.sh
31
32
test_write_lines 1 2 3 4 5 6 7 8 9 >file
33
+cp file file.orig
34
test_write_lines '1 X' 2 3 4 5 6 7 8 9 >file.1
35
+test_write_lines 1 2 '3 X' 4 5 6 7 8 9 >file.3
36
test_write_lines 1 2 3 4 '5 X' 6 7 8 9 >file.5
37
test_write_lines 1 2 3 4 5 6 7 8 '9 X' >file.9
38
test_write_lines 1 2 3 4 5 6 7 8 '9 Y' >file.9y
39
test_write_lines '1 X' 2 3 4 5 6 7 8 9 >result.1
40
test_write_lines '1 X' 2 3 4 '5 X' 6 7 8 9 >result.1-5
41
+test_write_lines '1 X' 2 3 4 5 6 7 8 '9 X' >result.1-9
42
test_write_lines '1 X' 2 3 4 '5 X' 6 7 8 '9 X' >result.1-5-9
43
+test_write_lines '1 X' 2 '3 X' 4 '5 X' 6 7 8 '9 X' >result.1-3-5-9
44
test_write_lines 1 2 3 4 5 6 7 8 '9 Z' >result.9z
45
46
create_merge_msgs () {
679
git merge c3
680
'
681
682
+test_expect_success 'merge with --autostash' '
683
+ git reset --hard c1 &&
684
+ git merge-file file file.orig file.9 &&
685
+ git merge --autostash c2 2>err &&
686
+ test_i18ngrep "Applied autostash." err &&
687
+ git show HEAD:file >merge-result &&
688
+ test_cmp result.1-5 merge-result &&
689
+ test_cmp result.1-5-9 file
690
+'
691
+
692
+test_expect_success 'merge with merge.autoStash' '
693
+ test_config merge.autoStash true &&
694
+ git reset --hard c1 &&
695
+ git merge-file file file.orig file.9 &&
696
+ git merge c2 2>err &&
697
+ test_i18ngrep "Applied autostash." err &&
698
+ git show HEAD:file >merge-result &&
699
+ test_cmp result.1-5 merge-result &&
700
+ test_cmp result.1-5-9 file
701
+'
702
+
703
+test_expect_success 'fast-forward merge with --autostash' '
704
+ git reset --hard c0 &&
705
+ git merge-file file file.orig file.5 &&
706
+ git merge --autostash c1 2>err &&
707
+ test_i18ngrep "Applied autostash." err &&
708
+ test_cmp result.1-5 file
709
+'
710
+
711
+test_expect_success 'octopus merge with --autostash' '
712
+ git reset --hard c1 &&
713
+ git merge-file file file.orig file.3 &&
714
+ git merge --autostash c2 c3 2>err &&
715
+ test_i18ngrep "Applied autostash." err &&
716
+ git show HEAD:file >merge-result &&
717
+ test_cmp result.1-5-9 merge-result &&
718
+ test_cmp result.1-3-5-9 file
719
+'
720
+
721
+test_expect_success 'conflicted merge with --autostash, --abort restores stash' '
722
+ git reset --hard c3 &&
723
+ cp file.1 file &&
724
+ test_must_fail git merge --autostash c7 &&
725
+ git merge --abort 2>err &&
726
+ test_i18ngrep "Applied autostash." err &&
727
+ test_cmp file.1 file
728
+'
729
+
730
+test_expect_success 'completed merge (git commit) with --no-commit and --autostash' '
731
+ git reset --hard c1 &&
732
+ git merge-file file file.orig file.9 &&
733
+ git diff >expect &&
734
+ git merge --no-commit --autostash c2 &&
735
+ git stash show -p MERGE_AUTOSTASH >actual &&
736
+ test_cmp expect actual &&
737
+ git commit 2>err &&
738
+ test_i18ngrep "Applied autostash." err &&
739
+ git show HEAD:file >merge-result &&
740
+ test_cmp result.1-5 merge-result &&
741
+ test_cmp result.1-5-9 file
742
+'
743
+
744
+test_expect_success 'completed merge (git merge --continue) with --no-commit and --autostash' '
745
+ git reset --hard c1 &&
746
+ git merge-file file file.orig file.9 &&
747
+ git diff >expect &&
748
+ git merge --no-commit --autostash c2 &&
749
+ git stash show -p MERGE_AUTOSTASH >actual &&
750
+ test_cmp expect actual &&
751
+ git merge --continue 2>err &&
752
+ test_i18ngrep "Applied autostash." err &&
753
+ git show HEAD:file >merge-result &&
754
+ test_cmp result.1-5 merge-result &&
755
+ test_cmp result.1-5-9 file
756
+'
757
+
758
+test_expect_success 'aborted merge (merge --abort) with --no-commit and --autostash' '
759
+ git reset --hard c1 &&
760
+ git merge-file file file.orig file.9 &&
761
+ git diff >expect &&
762
+ git merge --no-commit --autostash c2 &&
763
+ git stash show -p MERGE_AUTOSTASH >actual &&
764
+ test_cmp expect actual &&
765
+ git merge --abort 2>err &&
766
+ test_i18ngrep "Applied autostash." err &&
767
+ git diff >actual &&
768
+ test_cmp expect actual
769
+'
770
+
771
+test_expect_success 'aborted merge (reset --hard) with --no-commit and --autostash' '
772
+ git reset --hard c1 &&
773
+ git merge-file file file.orig file.9 &&
774
+ git diff >expect &&
775
+ git merge --no-commit --autostash c2 &&
776
+ git stash show -p MERGE_AUTOSTASH >actual &&
777
+ test_cmp expect actual &&
778
+ git reset --hard 2>err &&
779
+ test_i18ngrep "Autostash exists; creating a new stash entry." err &&
780
+ git diff --exit-code
781
+'
782
+
783
+test_expect_success 'quit merge with --no-commit and --autostash' '
784
+ git reset --hard c1 &&
785
+ git merge-file file file.orig file.9 &&
786
+ git diff >expect &&
787
+ git merge --no-commit --autostash c2 &&
788
+ git stash show -p MERGE_AUTOSTASH >actual &&
789
+ test_cmp expect actual &&
790
+ git diff HEAD >expect &&
791
+ git merge --quit 2>err &&
792
+ test_i18ngrep "Autostash exists; creating a new stash entry." err &&
793
+ git diff HEAD >actual &&
794
+ test_cmp expect actual
795
+'
796
+
797
+test_expect_success 'merge with conflicted --autostash changes' '
798
+ git reset --hard c1 &&
799
+ git merge-file file file.orig file.9y &&
800
+ git diff >expect &&
801
+ test_when_finished "test_might_fail git stash drop" &&
802
+ git merge --autostash c3 2>err &&
803
+ test_i18ngrep "Applying autostash resulted in conflicts." err &&
804
+ git show HEAD:file >merge-result &&
805
+ test_cmp result.1-9 merge-result &&
806
+ git stash show -p >actual &&
807
+ test_cmp expect actual
808
+'
809
+
810
cat >expected.branch <<\EOF
811
Merge branch 'c5-branch' (early part)
812
EOF