Skip to content

Commit 481de8a

Browse files
newrengitster
authored andcommitted
merge-recursive: restore accidentally dropped setting of path
In commit 8daec1d ("merge-recursive: switch from (oid,mode) pairs to a diff_filespec", 2019-04-05), we actually switched from (oid,mode,path) triplets to a diff_filespec -- but most callsites in the patch only needed to worry about oid and mode so the commit message focused on that. The oversight in the commit message apparently spilled over to the code as well; one of the dozen or so callsites accidentally dropped the setting of the path in the conversion. Restore the path setting in that location. Also, this pointed out that our testsuite was lacking a good rename/add test, at least one that involved the need for merge content with the rename. Add such a test, and since rename/add vs. add/rename could possibly be important, redo the merge the opposite direction to make sure we don't have issues with the direction of the merge. These testcases failed before restoring the setting of path, but with the paths appropriately set the testcases both pass. Reported-by: Ben Humphreys <[email protected]> Based-on-patch-by: SZEDER Gábor <[email protected]> Tested-by: Ben Humphreys <[email protected]> Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8c8e5bd commit 481de8a

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed

merge-recursive.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,7 @@ static int handle_rename_add(struct merge_options *opt,
16551655
c->path, add_branch);
16561656

16571657
prev_path_desc = xstrfmt("version of %s from %s", path, a->path);
1658+
ci->ren1->src_entry->stages[other_stage].path = a->path;
16581659
if (merge_mode_and_contents(opt, a, c,
16591660
&ci->ren1->src_entry->stages[other_stage],
16601661
prev_path_desc,

t/t6042-merge-rename-corner-cases.sh

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,122 @@ test_expect_success 'disappearing dir in rename/directory conflict handled' '
411411
)
412412
'
413413

414+
# Test for basic rename/add-dest conflict, with rename needing content merge:
415+
# Commit O: a
416+
# Commit A: rename a->b, modifying b too
417+
# Commit B: modify a, add different b
418+
419+
test_expect_success 'setup rename-with-content-merge vs. add' '
420+
test_create_repo rename-with-content-merge-and-add &&
421+
(
422+
cd rename-with-content-merge-and-add &&
423+
424+
test_seq 1 5 >a &&
425+
git add a &&
426+
git commit -m O &&
427+
git tag O &&
428+
429+
git checkout -b A O &&
430+
git mv a b &&
431+
test_seq 0 5 >b &&
432+
git add b &&
433+
git commit -m A &&
434+
435+
git checkout -b B O &&
436+
echo 6 >>a &&
437+
echo hello world >b &&
438+
git add a b &&
439+
git commit -m B
440+
)
441+
'
442+
443+
test_expect_success 'handle rename-with-content-merge vs. add' '
444+
(
445+
cd rename-with-content-merge-and-add &&
446+
447+
git checkout A^0 &&
448+
449+
test_must_fail git merge -s recursive B^0 >out &&
450+
test_i18ngrep "CONFLICT (rename/add)" out &&
451+
452+
git ls-files -s >out &&
453+
test_line_count = 2 out &&
454+
git ls-files -u >out &&
455+
test_line_count = 2 out &&
456+
# Also, make sure both unmerged entries are for "b"
457+
git ls-files -u b >out &&
458+
test_line_count = 2 out &&
459+
git ls-files -o >out &&
460+
test_line_count = 1 out &&
461+
462+
test_path_is_missing a &&
463+
test_path_is_file b &&
464+
465+
test_seq 0 6 >tmp &&
466+
git hash-object tmp >expect &&
467+
git rev-parse B:b >>expect &&
468+
git rev-parse >actual \
469+
:2:b :3:b &&
470+
test_cmp expect actual &&
471+
472+
# Test that the two-way merge in b is as expected
473+
git cat-file -p :2:b >>ours &&
474+
git cat-file -p :3:b >>theirs &&
475+
>empty &&
476+
test_must_fail git merge-file \
477+
-L "HEAD" \
478+
-L "" \
479+
-L "B^0" \
480+
ours empty theirs &&
481+
test_cmp ours b
482+
)
483+
'
484+
485+
test_expect_success 'handle rename-with-content-merge vs. add, merge other way' '
486+
(
487+
cd rename-with-content-merge-and-add &&
488+
489+
git reset --hard &&
490+
git clean -fdx &&
491+
492+
git checkout B^0 &&
493+
494+
test_must_fail git merge -s recursive A^0 >out &&
495+
test_i18ngrep "CONFLICT (rename/add)" out &&
496+
497+
git ls-files -s >out &&
498+
test_line_count = 2 out &&
499+
git ls-files -u >out &&
500+
test_line_count = 2 out &&
501+
# Also, make sure both unmerged entries are for "b"
502+
git ls-files -u b >out &&
503+
test_line_count = 2 out &&
504+
git ls-files -o >out &&
505+
test_line_count = 1 out &&
506+
507+
test_path_is_missing a &&
508+
test_path_is_file b &&
509+
510+
test_seq 0 6 >tmp &&
511+
git rev-parse B:b >expect &&
512+
git hash-object tmp >>expect &&
513+
git rev-parse >actual \
514+
:2:b :3:b &&
515+
test_cmp expect actual &&
516+
517+
# Test that the two-way merge in b is as expected
518+
git cat-file -p :2:b >>ours &&
519+
git cat-file -p :3:b >>theirs &&
520+
>empty &&
521+
test_must_fail git merge-file \
522+
-L "HEAD" \
523+
-L "" \
524+
-L "A^0" \
525+
ours empty theirs &&
526+
test_cmp ours b
527+
)
528+
'
529+
414530
# Test for all kinds of things that can go wrong with rename/rename (2to1):
415531
# Commit A: new files: a & b
416532
# Commit B: rename a->c, modify b

0 commit comments

Comments
 (0)