Skip to content

Commit 20fbf7d

Browse files
committed
Merge branch 'en/merge-directory-renames-fix'
Recent code restructuring of merge-recursive engine introduced a regression dealing with rename/add conflict. * en/merge-directory-renames-fix: merge-recursive: restore accidentally dropped setting of path
2 parents 74583d8 + 481de8a commit 20fbf7d

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
@@ -1660,6 +1660,7 @@ static int handle_rename_add(struct merge_options *opt,
16601660
c->path, add_branch);
16611661

16621662
prev_path_desc = xstrfmt("version of %s from %s", path, a->path);
1663+
ci->ren1->src_entry->stages[other_stage].path = a->path;
16631664
if (merge_mode_and_contents(opt, a, c,
16641665
&ci->ren1->src_entry->stages[other_stage],
16651666
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)