Skip to content

Commit 84a08a4

Browse files
newrengitster
authored andcommitted
handle_delete_modify(): 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 4ab9a15 commit 84a08a4

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

merge-recursive.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,25 +1164,29 @@ static int blob_unchanged(const unsigned char *o_sha,
11641164

11651165
static void handle_delete_modify(struct merge_options *o,
11661166
const char *path,
1167+
const char *new_path,
11671168
unsigned char *a_sha, int a_mode,
11681169
unsigned char *b_sha, int b_mode)
11691170
{
11701171
if (!a_sha) {
11711172
output(o, 1, "CONFLICT (delete/modify): %s deleted in %s "
1172-
"and modified in %s. Version %s of %s left in tree.",
1173+
"and modified in %s. Version %s of %s left in tree%s%s.",
11731174
path, o->branch1,
1174-
o->branch2, o->branch2, path);
1175-
update_file(o, 0, b_sha, b_mode, path);
1175+
o->branch2, o->branch2, path,
1176+
path == new_path ? "" : " at ",
1177+
path == new_path ? "" : new_path);
1178+
update_file(o, 0, b_sha, b_mode, new_path);
11761179
} else {
11771180
output(o, 1, "CONFLICT (delete/modify): %s deleted in %s "
1178-
"and modified in %s. Version %s of %s left in tree.",
1181+
"and modified in %s. Version %s of %s left in tree%s%s.",
11791182
path, o->branch2,
1180-
o->branch1, o->branch1, path);
1181-
update_file(o, 0, a_sha, a_mode, path);
1183+
o->branch1, o->branch1, path,
1184+
path == new_path ? "" : " at ",
1185+
path == new_path ? "" : new_path);
1186+
update_file(o, 0, a_sha, a_mode, new_path);
11821187
}
11831188
}
11841189

1185-
11861190
static int merge_content(struct merge_options *o,
11871191
const char *path,
11881192
unsigned char *o_sha, int o_mode,
@@ -1281,7 +1285,7 @@ static int process_entry(struct merge_options *o,
12811285
} else {
12821286
/* Deleted in one and changed in the other */
12831287
clean_merge = 0;
1284-
handle_delete_modify(o, path,
1288+
handle_delete_modify(o, path, path,
12851289
a_sha, a_mode, b_sha, b_mode);
12861290
}
12871291

@@ -1398,8 +1402,11 @@ static int process_df_entry(struct merge_options *o,
13981402
}
13991403
} else if (o_sha && (!a_sha || !b_sha)) {
14001404
/* Modify/delete; deleted side may have put a directory in the way */
1405+
const char *new_path = path;
1406+
if (lstat(path, &st) == 0 && S_ISDIR(st.st_mode))
1407+
new_path = unique_path(o, path, a_sha ? o->branch1 : o->branch2);
14011408
clean_merge = 0;
1402-
handle_delete_modify(o, path,
1409+
handle_delete_modify(o, path, new_path,
14031410
a_sha, a_mode, b_sha, b_mode);
14041411
} else if (!o_sha && !!a_sha != !!b_sha) {
14051412
/* directory -> (directory, file) */

t/t6020-merge-df.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ test_expect_success 'setup modify/delete + directory/file conflict' '
7171
git commit -m deleted
7272
'
7373

74-
test_expect_failure 'modify/delete + directory/file conflict' '
74+
test_expect_success 'modify/delete + directory/file conflict' '
7575
git checkout delete^0 &&
7676
test_must_fail git merge modify &&
7777

0 commit comments

Comments
 (0)