t6423, t6436: note improved ort handling with dirty files

The "recursive" backend relies on unpack_trees() to check if unstaged changes would be overwritten by a merge, but unpack_trees() does not understand renames -- and once it returns, it has already written many updates to the working tree and index. As such, "recursive" had to do a special 4-way merge where it would need to also treat the working copy as an extra source of differences that we had to carefully avoid overwriting and resulting in moving files to new locations to avoid conflicts. The "ort" backend, by contrast, does the complete merge inmemory, and only updates the index and working copy as a post-processing step. If there are dirty files in the way, it can simply abort the merge. Update t6423 and t6436 to reflect the better merge abilities and expectations we have for ort, while still leaving the best-case-as-good-as-recursive-can-do expectations there for the recursive backend so we retain its stability until we are ready to deprecate and remove it. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Oct 26, 2020 at 17:01 UTC 23bef2e33c3290ae308c2ce37e290a25eb5b97bc
2 files changed +165 -119
t/t6423-merge-rename-directories.sh
+152 -114
@@ -3634,28 +3634,35 @@ test_expect_success '11a: Avoid losing dirty contents with simple rename' '
3634 echo stuff >>z/c &&
3635
3636 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3637 - test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3637 + if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3638 + then
3639 + test_path_is_missing .git/MERGE_HEAD &&
3640 + test_i18ngrep "error: Your local changes to the following files would be overwritten by merge" err
3641 + else
3642 + test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3643
3639 - test_seq 1 10 >expected &&
3640 - echo stuff >>expected &&
3641 - test_cmp expected z/c &&
3644 + git ls-files -s >out &&
3645 + test_line_count = 2 out &&
3646 + git ls-files -u >out &&
3647 + test_line_count = 1 out &&
3648 + git ls-files -o >out &&
3649 + test_line_count = 3 out &&
3650
3643 - git ls-files -s >out &&
3644 - test_line_count = 2 out &&
3645 - git ls-files -u >out &&
3646 - test_line_count = 1 out &&
3647 - git ls-files -o >out &&
3648 - test_line_count = 4 out &&
3651 + git rev-parse >actual \
3652 + :0:z/a :2:z/c &&
3653 + git rev-parse >expect \
3654 + O:z/a B:z/b &&
3655 + test_cmp expect actual &&
3656
3650 - git rev-parse >actual \
3651 - :0:z/a :2:z/c &&
3652 - git rev-parse >expect \
3653 - O:z/a B:z/b &&
3654 - test_cmp expect actual &&
3657 + git hash-object z/c~HEAD >actual &&
3658 + git rev-parse B:z/b >expect &&
3659 + test_cmp expect actual
3660 + fi &&
3661 +
3662 + test_seq 1 10 >expected &&
3663 + echo stuff >>expected &&
3664 + test_cmp expected z/c
3665
3656 - git hash-object z/c~HEAD >actual &&
3657 - git rev-parse B:z/b >expect &&
3658 - test_cmp expect actual
3666 )
3667 '
3668
@@ -3706,32 +3713,39 @@ test_expect_success '11b: Avoid losing dirty file involved in directory rename'
3713 git checkout A^0 &&
3714 echo stuff >>z/c &&
3715
3709 - git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3710 - test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3716 + if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3717 + then
3718 + test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3719 + test_path_is_missing .git/MERGE_HEAD &&
3720 + test_i18ngrep "error: Your local changes to the following files would be overwritten by merge" err
3721 + else
3722 + git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3723 + test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3724
3712 - grep -q stuff z/c &&
3713 - test_seq 1 10 >expected &&
3714 - echo stuff >>expected &&
3715 - test_cmp expected z/c &&
3725 + git ls-files -s >out &&
3726 + test_line_count = 3 out &&
3727 + git ls-files -u >out &&
3728 + test_line_count = 0 out &&
3729 + git ls-files -m >out &&
3730 + test_line_count = 0 out &&
3731 + git ls-files -o >out &&
3732 + test_line_count = 3 out &&
3733
3717 - git ls-files -s >out &&
3718 - test_line_count = 3 out &&
3719 - git ls-files -u >out &&
3720 - test_line_count = 0 out &&
3721 - git ls-files -m >out &&
3722 - test_line_count = 0 out &&
3723 - git ls-files -o >out &&
3724 - test_line_count = 4 out &&
3734 + git rev-parse >actual \
3735 + :0:x/b :0:y/a :0:y/c &&
3736 + git rev-parse >expect \
3737 + O:x/b O:z/a B:x/c &&
3738 + test_cmp expect actual &&
3739
3726 - git rev-parse >actual \
3727 - :0:x/b :0:y/a :0:y/c &&
3728 - git rev-parse >expect \
3729 - O:x/b O:z/a B:x/c &&
3730 - test_cmp expect actual &&
3740 + git hash-object y/c >actual &&
3741 + git rev-parse B:x/c >expect &&
3742 + test_cmp expect actual
3743 + fi &&
3744
3732 - git hash-object y/c >actual &&
3733 - git rev-parse B:x/c >expect &&
3734 - test_cmp expect actual
3745 + grep -q stuff z/c &&
3746 + test_seq 1 10 >expected &&
3747 + echo stuff >>expected &&
3748 + test_cmp expected z/c
3749 )
3750 '
3751
@@ -3783,7 +3797,13 @@ test_expect_success '11c: Avoid losing not-uptodate with rename + D/F conflict'
3797 echo stuff >>y/c &&
3798
3799 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3786 - test_i18ngrep "following files would be overwritten by merge" err &&
3800 + if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3801 + then
3802 + test_path_is_missing .git/MERGE_HEAD &&
3803 + test_i18ngrep "error: Your local changes to the following files would be overwritten by merge" err
3804 + else
3805 + test_i18ngrep "following files would be overwritten by merge" err
3806 + fi &&
3807
3808 grep -q stuff y/c &&
3809 test_seq 1 10 >expected &&
@@ -3851,29 +3871,35 @@ test_expect_success '11d: Avoid losing not-uptodate with rename + D/F conflict'
3871 echo stuff >>z/c &&
3872
3873 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3854 - test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3874 + if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3875 + then
3876 + test_path_is_missing .git/MERGE_HEAD &&
3877 + test_i18ngrep "error: Your local changes to the following files would be overwritten by merge" err
3878 + else
3879 + test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3880
3856 - grep -q stuff z/c &&
3857 - test_seq 1 10 >expected &&
3858 - echo stuff >>expected &&
3859 - test_cmp expected z/c &&
3881 + git ls-files -s >out &&
3882 + test_line_count = 4 out &&
3883 + git ls-files -u >out &&
3884 + test_line_count = 1 out &&
3885 + git ls-files -o >out &&
3886 + test_line_count = 4 out &&
3887
3861 - git ls-files -s >out &&
3862 - test_line_count = 4 out &&
3863 - git ls-files -u >out &&
3864 - test_line_count = 1 out &&
3865 - git ls-files -o >out &&
3866 - test_line_count = 5 out &&
3888 + git rev-parse >actual \
3889 + :0:x/b :0:y/a :0:y/c/d :3:y/c &&
3890 + git rev-parse >expect \
3891 + O:x/b O:z/a B:y/c/d B:x/c &&
3892 + test_cmp expect actual &&
3893
3868 - git rev-parse >actual \
3869 - :0:x/b :0:y/a :0:y/c/d :3:y/c &&
3870 - git rev-parse >expect \
3871 - O:x/b O:z/a B:y/c/d B:x/c &&
3872 - test_cmp expect actual &&
3894 + git hash-object y/c~HEAD >actual &&
3895 + git rev-parse B:x/c >expect &&
3896 + test_cmp expect actual
3897 + fi &&
3898
3874 - git hash-object y/c~HEAD >actual &&
3875 - git rev-parse B:x/c >expect &&
3876 - test_cmp expect actual
3899 + grep -q stuff z/c &&
3900 + test_seq 1 10 >expected &&
3901 + echo stuff >>expected &&
3902 + test_cmp expected z/c
3903 )
3904 '
3905
@@ -3931,37 +3957,43 @@ test_expect_success '11e: Avoid deleting not-uptodate with dir rename/rename(1to
3957 echo mods >>y/c &&
3958
3959 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3934 - test_i18ngrep "CONFLICT (rename/rename)" out &&
3935 - test_i18ngrep "Refusing to lose dirty file at y/c" out &&
3960 + if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3961 + then
3962 + test_path_is_missing .git/MERGE_HEAD &&
3963 + test_i18ngrep "error: Your local changes to the following files would be overwritten by merge" err
3964 + else
3965 + test_i18ngrep "CONFLICT (rename/rename)" out &&
3966 + test_i18ngrep "Refusing to lose dirty file at y/c" out &&
3967
3937 - git ls-files -s >out &&
3938 - test_line_count = 7 out &&
3939 - git ls-files -u >out &&
3940 - test_line_count = 4 out &&
3941 - git ls-files -o >out &&
3942 - test_line_count = 3 out &&
3968 + git ls-files -s >out &&
3969 + test_line_count = 7 out &&
3970 + git ls-files -u >out &&
3971 + test_line_count = 4 out &&
3972 + git ls-files -o >out &&
3973 + test_line_count = 3 out &&
3974 +
3975 + git rev-parse >actual \
3976 + :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :2:y/c :3:y/c &&
3977 + git rev-parse >expect \
3978 + O:z/a O:z/b O:x/d O:x/c O:x/c A:y/c O:x/c &&
3979 + test_cmp expect actual &&
3980 +
3981 + # See if y/c~merged has expected contents; requires manually
3982 + # doing the expected file merge
3983 + git cat-file -p A:y/c >c1 &&
3984 + git cat-file -p B:z/c >c2 &&
3985 + >empty &&
3986 + test_must_fail git merge-file \
3987 + -L "HEAD" \
3988 + -L "" \
3989 + -L "B^0" \
3990 + c1 empty c2 &&
3991 + test_cmp c1 y/c~merged
3992 + fi &&
3993
3994 echo different >expected &&
3995 echo mods >>expected &&
3946 - test_cmp expected y/c &&
3947 -
3948 - git rev-parse >actual \
3949 - :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :2:y/c :3:y/c &&
3950 - git rev-parse >expect \
3951 - O:z/a O:z/b O:x/d O:x/c O:x/c A:y/c O:x/c &&
3952 - test_cmp expect actual &&
3953 -
3954 - # See if y/c~merged has expected contents; requires manually
3955 - # doing the expected file merge
3956 - git cat-file -p A:y/c >c1 &&
3957 - git cat-file -p B:z/c >c2 &&
3958 - >empty &&
3959 - test_must_fail git merge-file \
3960 - -L "HEAD" \
3961 - -L "" \
3962 - -L "B^0" \
3963 - c1 empty c2 &&
3964 - test_cmp c1 y/c~merged
3996 + test_cmp expected y/c
3997 )
3998 '
3999
@@ -4014,38 +4046,44 @@ test_expect_success '11f: Avoid deleting not-uptodate with dir rename/rename(2to
4046 echo important >>y/wham &&
4047
4048 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4017 - test_i18ngrep "CONFLICT (rename/rename)" out &&
4018 - test_i18ngrep "Refusing to lose dirty file at y/wham" out &&
4049 + if test "$GIT_TEST_MERGE_ALGORITHM" = ort
4050 + then
4051 + test_path_is_missing .git/MERGE_HEAD &&
4052 + test_i18ngrep "error: Your local changes to the following files would be overwritten by merge" err
4053 + else
4054 + test_i18ngrep "CONFLICT (rename/rename)" out &&
4055 + test_i18ngrep "Refusing to lose dirty file at y/wham" out &&
4056
4020 - git ls-files -s >out &&
4021 - test_line_count = 4 out &&
4022 - git ls-files -u >out &&
4023 - test_line_count = 2 out &&
4024 - git ls-files -o >out &&
4025 - test_line_count = 3 out &&
4057 + git ls-files -s >out &&
4058 + test_line_count = 4 out &&
4059 + git ls-files -u >out &&
4060 + test_line_count = 2 out &&
4061 + git ls-files -o >out &&
4062 + test_line_count = 3 out &&
4063
4027 - test_seq 1 10 >expected &&
4028 - echo important >>expected &&
4029 - test_cmp expected y/wham &&
4064 + test_must_fail git rev-parse :1:y/wham &&
4065
4031 - test_must_fail git rev-parse :1:y/wham &&
4066 + git rev-parse >actual \
4067 + :0:y/a :0:y/b :2:y/wham :3:y/wham &&
4068 + git rev-parse >expect \
4069 + O:z/a O:z/b O:x/c O:x/d &&
4070 + test_cmp expect actual &&
4071
4033 - git rev-parse >actual \
4034 - :0:y/a :0:y/b :2:y/wham :3:y/wham &&
4035 - git rev-parse >expect \
4036 - O:z/a O:z/b O:x/c O:x/d &&
4037 - test_cmp expect actual &&
4072 + # Test that two-way merge in y/wham~merged is as expected
4073 + git cat-file -p :2:y/wham >expect &&
4074 + git cat-file -p :3:y/wham >other &&
4075 + >empty &&
4076 + test_must_fail git merge-file \
4077 + -L "HEAD" \
4078 + -L "" \
4079 + -L "B^0" \
4080 + expect empty other &&
4081 + test_cmp expect y/wham~merged
4082 + fi &&
4083
4039 - # Test that the two-way merge in y/wham~merged is as expected
4040 - git cat-file -p :2:y/wham >expect &&
4041 - git cat-file -p :3:y/wham >other &&
4042 - >empty &&
4043 - test_must_fail git merge-file \
4044 - -L "HEAD" \
4045 - -L "" \
4046 - -L "B^0" \
4047 - expect empty other &&
4048 - test_cmp expect y/wham~merged
4084 + test_seq 1 10 >expected &&
4085 + echo important >>expected &&
4086 + test_cmp expected y/wham
4087 )
4088 '
4089
t/t6436-merge-overwrite.sh
+13 -5
@@ -97,11 +97,19 @@ test_expect_success 'will not overwrite unstaged changes in renamed file' '
97 git mv c1.c other.c &&
98 git commit -m rename &&
99 cp important other.c &&
100 - test_must_fail git merge c1a >out &&
101 - test_i18ngrep "Refusing to lose dirty file at other.c" out &&
102 - test_path_is_file other.c~HEAD &&
103 - test $(git hash-object other.c~HEAD) = $(git rev-parse c1a:c1.c) &&
104 - test_cmp important other.c
100 + if test "$GIT_TEST_MERGE_ALGORITHM" = ort
101 + then
102 + test_must_fail git merge c1a >out 2>err &&
103 + test_i18ngrep "would be overwritten by merge" err &&
104 + test_cmp important other.c &&
105 + test_path_is_missing .git/MERGE_HEAD
106 + else
107 + test_must_fail git merge c1a >out &&
108 + test_i18ngrep "Refusing to lose dirty file at other.c" out &&
109 + test_path_is_file other.c~HEAD &&
110 + test $(git hash-object other.c~HEAD) = $(git rev-parse c1a:c1.c) &&
111 + test_cmp important other.c
112 + fi
113 '
114
115 test_expect_success 'will not overwrite untracked subtree' '