merge-recursive: avoid spurious rename/rename conflict from dir renames
If a file on one side of history was renamed, and merely modified on the other side, then applying a directory rename to the modified side gives us a rename/rename(1to2) conflict. We should only apply directory renames to pairs representing either adds or renames. Making this change means that a directory rename testcase that was previously reported as a rename/delete conflict will now be reported as a modify/delete conflict. Reviewed-by: Stefan Beller <sbeller@google.com> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Apr 19, 2018 at 10:58 UTC
6e7e027fe5f4a8d61597a86e7f2b6087e23a759c
2 files changed
+27
-32
merge-recursive.c
+2
-2
@@ -1992,7 +1992,7 @@ static void compute_collisions(struct hashmap *collisions,
1992
char *new_path;
1993
struct diff_filepair *pair = pairs->queue[i];
1994
1995
- if (pair->status == 'D')
1995
+ if (pair->status != 'A' && pair->status != 'R')
1996
continue;
1997
dir_rename_ent = check_dir_renamed(pair->two->path,
1998
dir_renames);
@@ -2219,7 +2219,7 @@ static struct string_list *get_renames(struct merge_options *o,
2219
struct diff_filepair *pair = pairs->queue[i];
2220
char *new_path; /* non-NULL only with directory renames */
2221
2222
- if (pair->status == 'D') {
2222
+ if (pair->status != 'A' && pair->status != 'R') {
2223
diff_free_filepair(pair);
2224
continue;
2225
}
t/t6043-merge-rename-directories.sh
+25
-30
@@ -2078,18 +2078,23 @@ test_expect_success '8b-check: Dual-directory rename, one into the others way, w
2078
)
2079
'
2080
2081
-# Testcase 8c, rename+modify/delete
2082
-# (Related to testcases 5b and 8d)
2081
+# Testcase 8c, modify/delete or rename+modify/delete?
2082
+# (Related to testcases 5b, 8d, and 9h)
2083
# Commit O: z/{b,c,d}
2084
# Commit A: y/{b,c}
2085
# Commit B: z/{b,c,d_modified,e}
2086
-# Expected: y/{b,c,e}, CONFLICT(rename+modify/delete: x/d -> y/d or deleted)
2086
+# Expected: y/{b,c,e}, CONFLICT(modify/delete: on z/d)
2087
#
2088
-# Note: This testcase doesn't present any concerns for me...until you
2089
-# compare it with testcases 5b and 8d. See notes in 8d for more
2090
-# details.
2091
-
2092
-test_expect_success '8c-setup: rename+modify/delete' '
2088
+# Note: It could easily be argued that the correct resolution here is
2089
+# y/{b,c,e}, CONFLICT(rename/delete: z/d -> y/d vs deleted)
2090
+# and that the modifed version of d should be present in y/ after
2091
+# the merge, just marked as conflicted. Indeed, I previously did
2092
+# argue that. But applying directory renames to the side of
2093
+# history where a file is merely modified results in spurious
2094
+# rename/rename(1to2) conflicts -- see testcase 9h. See also
2095
+# notes in 8d.
2096
+
2097
+test_expect_success '8c-setup: modify/delete or rename+modify/delete?' '
2098
test_create_repo 8c &&
2099
(
2100
cd 8c &&
@@ -2122,32 +2127,32 @@ test_expect_success '8c-setup: rename+modify/delete' '
2127
)
2128
'
2129
2125
-test_expect_success '8c-check: rename+modify/delete' '
2130
+test_expect_success '8c-check: modify/delete or rename+modify/delete' '
2131
(
2132
cd 8c &&
2133
2134
git checkout A^0 &&
2135
2136
test_must_fail git merge -s recursive B^0 >out &&
2132
- test_i18ngrep "CONFLICT (rename/delete).* z/d.*y/d" out &&
2137
+ test_i18ngrep "CONFLICT (modify/delete).* z/d" out &&
2138
2139
git ls-files -s >out &&
2135
- test_line_count = 4 out &&
2140
+ test_line_count = 5 out &&
2141
git ls-files -u >out &&
2137
- test_line_count = 1 out &&
2142
+ test_line_count = 2 out &&
2143
git ls-files -o >out &&
2144
test_line_count = 1 out &&
2145
2146
git rev-parse >actual \
2142
- :0:y/b :0:y/c :0:y/e :3:y/d &&
2147
+ :0:y/b :0:y/c :0:y/e :1:z/d :3:z/d &&
2148
git rev-parse >expect \
2144
- O:z/b O:z/c B:z/e B:z/d &&
2149
+ O:z/b O:z/c B:z/e O:z/d B:z/d &&
2150
test_cmp expect actual &&
2151
2147
- test_must_fail git rev-parse :1:y/d &&
2148
- test_must_fail git rev-parse :2:y/d &&
2149
- git ls-files -s y/d | grep ^100755 &&
2150
- test_path_is_file y/d
2152
+ test_must_fail git rev-parse :2:z/d &&
2153
+ git ls-files -s z/d | grep ^100755 &&
2154
+ test_path_is_file z/d &&
2155
+ test_path_is_missing y/d
2156
)
2157
'
2158
@@ -2161,16 +2166,6 @@ test_expect_success '8c-check: rename+modify/delete' '
2166
#
2167
# Note: It would also be somewhat reasonable to resolve this as
2168
# y/{b,c,e}, CONFLICT(rename/delete: x/d -> y/d or deleted)
2164
-# The logic being that the only difference between this testcase and 8c
2165
-# is that there is no modification to d. That suggests that instead of a
2166
-# rename/modify vs. delete conflict, we should just have a rename/delete
2167
-# conflict, otherwise we are being inconsistent.
2168
-#
2169
-# However...as far as consistency goes, we didn't report a conflict for
2170
-# path d_1 in testcase 5b due to a different file being in the way. So,
2171
-# we seem to be forced to have cases where users can change things
2172
-# slightly and get what they may perceive as inconsistent results. It
2173
-# would be nice to avoid that, but I'm not sure I see how.
2169
#
2170
# In this case, I'm leaning towards: commit A was the one that deleted z/d
2171
# and it did the rename of z to y, so the two "conflicts" (rename vs.
@@ -2915,7 +2910,7 @@ test_expect_success '9h-setup: Avoid dir rename on merely modified path' '
2910
)
2911
'
2912
2918
-test_expect_failure '9h-check: Avoid dir rename on merely modified path' '
2913
+test_expect_success '9h-check: Avoid dir rename on merely modified path' '
2914
(
2915
cd 9h &&
2916
@@ -3959,7 +3954,7 @@ test_expect_success '12c-setup: Moving one directory hierarchy into another w/ c
3954
)
3955
'
3956
3962
-test_expect_failure '12c-check: Moving one directory hierarchy into another w/ content merge' '
3957
+test_expect_success '12c-check: Moving one directory hierarchy into another w/ content merge' '
3958
(
3959
cd 12c &&
3960