Skip to content

Commit ff8e25e

Browse files
committed
Merge branch 'en/merge-cleanup-more'
Further clean-up of merge-recursive machinery. * en/merge-cleanup-more: merge-recursive: avoid showing conflicts with merge branch before HEAD merge-recursive: improve auto-merging messages with path collisions
2 parents d582ea2 + 4f44545 commit ff8e25e

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

merge-recursive.c

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,26 @@ static inline void setup_rename_conflict_info(enum rename_type rename_type,
228228
struct stage_data *src_entry1,
229229
struct stage_data *src_entry2)
230230
{
231-
struct rename_conflict_info *ci = xcalloc(1, sizeof(struct rename_conflict_info));
231+
struct rename_conflict_info *ci;
232+
233+
/*
234+
* When we have two renames involved, it's easiest to get the
235+
* correct things into stage 2 and 3, and to make sure that the
236+
* content merge puts HEAD before the other branch if we just
237+
* ensure that branch1 == o->branch1. So, simply flip arguments
238+
* around if we don't have that.
239+
*/
240+
if (dst_entry2 && branch1 != o->branch1) {
241+
setup_rename_conflict_info(rename_type,
242+
pair2, pair1,
243+
branch2, branch1,
244+
dst_entry2, dst_entry1,
245+
o,
246+
src_entry2, src_entry1);
247+
return;
248+
}
249+
250+
ci = xcalloc(1, sizeof(struct rename_conflict_info));
232251
ci->rename_type = rename_type;
233252
ci->pair1 = pair1;
234253
ci->branch1 = branch1;
@@ -1284,6 +1303,17 @@ static int merge_mode_and_contents(struct merge_options *o,
12841303
const char *branch2,
12851304
struct merge_file_info *result)
12861305
{
1306+
if (o->branch1 != branch1) {
1307+
/*
1308+
* It's weird getting a reverse merge with HEAD on the bottom
1309+
* side of the conflict markers and the other branch on the
1310+
* top. Fix that.
1311+
*/
1312+
return merge_mode_and_contents(o, one, b, a,
1313+
filename,
1314+
branch2, branch1, result);
1315+
}
1316+
12871317
result->merge = 0;
12881318
result->clean = 1;
12891319

@@ -1675,8 +1705,8 @@ static int handle_rename_rename_2to1(struct merge_options *o,
16751705
remove_file(o, 1, a->path, o->call_depth || would_lose_untracked(a->path));
16761706
remove_file(o, 1, b->path, o->call_depth || would_lose_untracked(b->path));
16771707

1678-
path_side_1_desc = xstrfmt("%s (was %s)", path, a->path);
1679-
path_side_2_desc = xstrfmt("%s (was %s)", path, b->path);
1708+
path_side_1_desc = xstrfmt("version of %s from %s", path, a->path);
1709+
path_side_2_desc = xstrfmt("version of %s from %s", path, b->path);
16801710
if (merge_mode_and_contents(o, a, c1, &ci->ren1_other, path_side_1_desc,
16811711
o->branch1, o->branch2, &mfi_c1) ||
16821712
merge_mode_and_contents(o, b, &ci->ren2_other, c2, path_side_2_desc,

t/t6036-recursive-corner-cases.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,13 @@ test_expect_success 'git detects differently handled merges conflict' '
230230
:2:new_a :3:new_a &&
231231
test_cmp expect actual &&
232232
233-
git cat-file -p B:new_a >ours &&
234-
git cat-file -p C:new_a >theirs &&
233+
git cat-file -p C:new_a >ours &&
234+
git cat-file -p B:new_a >theirs &&
235235
>empty &&
236236
test_must_fail git merge-file \
237-
-L "Temporary merge branch 2" \
238-
-L "" \
239237
-L "Temporary merge branch 1" \
238+
-L "" \
239+
-L "Temporary merge branch 2" \
240240
ours empty theirs &&
241241
sed -e "s/^\([<=>]\)/\1\1\1/" ours >expect &&
242242
git cat-file -p :1:new_a >actual &&

0 commit comments

Comments
 (0)