Skip to content

Commit 4ab9a15

Browse files
newrengitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2adc7dc commit 4ab9a15

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

merge-recursive.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,8 @@ static int merge_content(struct merge_options *o,
11931193
const char *reason = "content";
11941194
struct merge_file_info mfi;
11951195
struct diff_filespec one, a, b;
1196+
struct stat st;
1197+
unsigned df_conflict_remains = 0;
11961198

11971199
if (!o_sha) {
11981200
reason = "add/add";
@@ -1207,7 +1209,13 @@ static int merge_content(struct merge_options *o,
12071209
b.mode = b_mode;
12081210

12091211
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)
12111219
output(o, 3, "Skipped %s (merged same as existing)", path);
12121220
else
12131221
output(o, 2, "Auto-merging %s", path);
@@ -1219,7 +1227,17 @@ static int merge_content(struct merge_options *o,
12191227
reason, path);
12201228
}
12211229

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+
}
12231241
return mfi.clean;
12241242

12251243
}

t/t6022-merge-rename.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ test_expect_success 'Rename+D/F conflict; renamed file merges + dir not in way'
394394
test_cmp expected dir
395395
'
396396

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' '
398398
git reset --hard &&
399399
rm -rf dir~* &&
400400
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' '
415415
test_cmp expected dir~HEAD
416416
'
417417

418-
test_expect_failure 'Same as previous, but merged other way' '
418+
test_expect_success 'Same as previous, but merged other way' '
419419
git reset --hard &&
420420
rm -rf dir~* &&
421421
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
471471
test_cmp expected dir
472472
'
473473

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' '
475475
modify s/dir-not-in-way/dir-in-way/ expected &&
476476
477477
git reset --hard &&
@@ -509,7 +509,7 @@ cat >expected <<\EOF &&
509509
>>>>>>> renamed-file-has-conflicts
510510
EOF
511511

512-
test_expect_failure 'Same as previous, but merged other way' '
512+
test_expect_success 'Same as previous, but merged other way' '
513513
git reset --hard &&
514514
rm -rf dir~* &&
515515
git checkout -q dir-in-way^0 &&

0 commit comments

Comments
 (0)