merge_content(): Check whether D/F conflicts are still present
If all the paths below some directory involved in a D/F conflict were not removed during the rest of the merge, then the contents of the file whose path conflicted needs to be recorded in file with an alternative filename. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Sep 20, 2010 at 02:29 UTC
4ab9a157d06956ce5a1060a28404cbade3039fa2
2 files changed
+24
-6
merge-recursive.c
+20
-2
@@ -1193,6 +1193,8 @@ static int merge_content(struct merge_options *o,
1193
const char *reason = "content";
1194
struct merge_file_info mfi;
1195
struct diff_filespec one, a, b;
1196
+ struct stat st;
1197
+ unsigned df_conflict_remains = 0;
1198
1199
if (!o_sha) {
1200
reason = "add/add";
@@ -1207,7 +1209,13 @@ static int merge_content(struct merge_options *o,
1209
b.mode = b_mode;
1210
1211
mfi = merge_file(o, &one, &a, &b, o->branch1, o->branch2);
1210
- if (mfi.clean && sha_eq(mfi.sha, a_sha) && mfi.mode == a.mode)
1212
+ if (df_rename_conflict_branch &&
1213
+ lstat(path, &st) == 0 && S_ISDIR(st.st_mode)) {
1214
+ df_conflict_remains = 1;
1215
+ }
1216
+
1217
+ if (mfi.clean && !df_conflict_remains &&
1218
+ sha_eq(mfi.sha, a_sha) && mfi.mode == a.mode)
1219
output(o, 3, "Skipped %s (merged same as existing)", path);
1220
else
1221
output(o, 2, "Auto-merging %s", path);
@@ -1219,7 +1227,17 @@ static int merge_content(struct merge_options *o,
1227
reason, path);
1228
}
1229
1222
- update_file(o, mfi.clean, mfi.sha, mfi.mode, path);
1230
+ if (df_conflict_remains) {
1231
+ const char *new_path;
1232
+ update_file_flags(o, mfi.sha, mfi.mode, path,
1233
+ o->call_depth || mfi.clean, 0);
1234
+ new_path = unique_path(o, path, df_rename_conflict_branch);
1235
+ mfi.clean = 0;
1236
+ output(o, 1, "Adding as %s instead", new_path);
1237
+ update_file_flags(o, mfi.sha, mfi.mode, new_path, 0, 1);
1238
+ } else {
1239
+ update_file(o, mfi.clean, mfi.sha, mfi.mode, path);
1240
+ }
1241
return mfi.clean;
1242
1243
}
t/t6022-merge-rename.sh
+4
-4
@@ -394,7 +394,7 @@ test_expect_success 'Rename+D/F conflict; renamed file merges + dir not in way'
394
test_cmp expected dir
395
'
396
397
-test_expect_failure 'Rename+D/F conflict; renamed file merges but dir in way' '
397
+test_expect_success 'Rename+D/F conflict; renamed file merges but dir in way' '
398
git reset --hard &&
399
rm -rf dir~* &&
400
git checkout -q renamed-file-has-no-conflicts^0 &&
@@ -415,7 +415,7 @@ test_expect_failure 'Rename+D/F conflict; renamed file merges but dir in way' '
415
test_cmp expected dir~HEAD
416
'
417
418
-test_expect_failure 'Same as previous, but merged other way' '
418
+test_expect_success 'Same as previous, but merged other way' '
419
git reset --hard &&
420
rm -rf dir~* &&
421
git checkout -q dir-in-way^0 &&
@@ -471,7 +471,7 @@ test_expect_success 'Rename+D/F conflict; renamed file cannot merge, dir not in
471
test_cmp expected dir
472
'
473
474
-test_expect_failure 'Rename+D/F conflict; renamed file cannot merge and dir in the way' '
474
+test_expect_success 'Rename+D/F conflict; renamed file cannot merge and dir in the way' '
475
modify s/dir-not-in-way/dir-in-way/ expected &&
476
477
git reset --hard &&
@@ -509,7 +509,7 @@ cat >expected <<\EOF &&
509
>>>>>>> renamed-file-has-conflicts
510
EOF
511
512
-test_expect_failure 'Same as previous, but merged other way' '
512
+test_expect_success 'Same as previous, but merged other way' '
513
git reset --hard &&
514
rm -rf dir~* &&
515
git checkout -q dir-in-way^0 &&