@matheusbsbs / matheus-bagliano / commits / d5af51053c
Fork 0

RE: [PATCH] Avoid rename/add conflict when contents are identical

>Due to this this (and maybe all the tests) need to depend on the >SYMLINKS prereq. Here's a third attempt with no use of symlinks in the test: Skip the entire rename/add conflict case if the file added on the other branch has the same contents as the file being renamed. This avoids giving the user an extra copy of the same file and presenting a conflict that is confusing and pointless. A simple test of this case has been added in t/t3030-merge-recursive.sh. Signed-off-by: Ken Schalk <ken.schalk@intel.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Schalk, Ken committed Sep 1, 2010 at 13:15 UTC d5af51053cd060d7a4893f030626b04351554d1b
2 files changed +41
merge-recursive.c
+6
@@ -955,6 +955,12 @@ static int process_renames(struct merge_options *o,
955 ren1->pair->two : NULL,
956 branch1 == o->branch1 ?
957 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);
964 } else if (!sha_eq(dst_other.sha1, null_sha1)) {
965 const char *new_path;
966 clean_merge = 0;
t/t3030-merge-recursive.sh
+35
@@ -23,6 +23,8 @@ test_expect_success 'setup 1' '
23 git branch df-3 &&
24 git branch remove &&
25 git branch submod &&
26 + git branch copy &&
27 + git branch rename &&
28
29 echo hello >>a &&
30 cp a d/e &&
@@ -248,6 +250,22 @@ test_expect_success 'setup 7' '
250 git commit -m "make d/ a submodule"
251 '
252
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 +
269 test_expect_success 'merge-recursive simple' '
270
271 rm -fr [abcd] &&
@@ -580,4 +598,21 @@ test_expect_failure 'merge-recursive simple w/submodule result' '
598 test_cmp expected actual
599 '
600
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 +
618 test_done