Skip to content

Commit 9f0ccb5

Browse files
committed
Merge branch 'ks/recursive-rename-add-identical'
* ks/recursive-rename-add-identical: RE: [PATCH] Avoid rename/add conflict when contents are identical
2 parents 12644fa + d5af510 commit 9f0ccb5

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

merge-recursive.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,12 @@ static int process_renames(struct merge_options *o,
955955
ren1->pair->two : NULL,
956956
branch1 == o->branch1 ?
957957
NULL : ren1->pair->two, 1);
958+
} else if ((dst_other.mode == ren1->pair->two->mode) &&
959+
sha_eq(dst_other.sha1, ren1->pair->two->sha1)) {
960+
/* Added file on the other side
961+
identical to the file being
962+
renamed: clean merge */
963+
update_file(o, 1, ren1->pair->two->sha1, ren1->pair->two->mode, ren1_dst);
958964
} else if (!sha_eq(dst_other.sha1, null_sha1)) {
959965
const char *new_path;
960966
clean_merge = 0;

t/t3030-merge-recursive.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ test_expect_success 'setup 1' '
2323
git branch df-3 &&
2424
git branch remove &&
2525
git branch submod &&
26+
git branch copy &&
27+
git branch rename &&
2628
2729
echo hello >>a &&
2830
cp a d/e &&
@@ -248,6 +250,22 @@ test_expect_success 'setup 7' '
248250
git commit -m "make d/ a submodule"
249251
'
250252

253+
test_expect_success 'setup 8' '
254+
git checkout rename &&
255+
git mv a e &&
256+
git add e &&
257+
test_tick &&
258+
git commit -m "rename a->e"
259+
'
260+
261+
test_expect_success 'setup 9' '
262+
git checkout copy &&
263+
cp a e &&
264+
git add e &&
265+
test_tick &&
266+
git commit -m "copy a->e"
267+
'
268+
251269
test_expect_success 'merge-recursive simple' '
252270
253271
rm -fr [abcd] &&
@@ -580,4 +598,21 @@ test_expect_failure 'merge-recursive simple w/submodule result' '
580598
test_cmp expected actual
581599
'
582600

601+
test_expect_success 'merge-recursive copy vs. rename' '
602+
git checkout -f copy &&
603+
git merge rename &&
604+
( git ls-tree -r HEAD && git ls-files -s ) >actual &&
605+
(
606+
echo "100644 blob $o0 b"
607+
echo "100644 blob $o0 c"
608+
echo "100644 blob $o0 d/e"
609+
echo "100644 blob $o0 e"
610+
echo "100644 $o0 0 b"
611+
echo "100644 $o0 0 c"
612+
echo "100644 $o0 0 d/e"
613+
echo "100644 $o0 0 e"
614+
) >expected &&
615+
test_cmp expected actual
616+
'
617+
583618
test_done

0 commit comments

Comments
 (0)