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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>The logic seems to be clear enough.  Could you write a test script instead
>of description in the commit log message, so that future changes to the
>codebase won't break this improvement?

Here's a revised patch which fixes a problem with the earlier one and includes a test (where Ævar Bjarmason suggested it):

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@xxxxxxxxx>
---
 merge-recursive.c          |    6 ++++++
 t/t3030-merge-recursive.sh |   40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/merge-recursive.c b/merge-recursive.c
index fb6aa4a..a2fba84 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -955,6 +955,12 @@ static int process_renames(struct merge_options *o,
                                                        ren1->pair->two : NULL,
                                                        branch1 == o->branch1 ?
                                                        NULL : ren1->pair->two, 1);
+                       } else if ((dst_other.mode == ren1->pair->two->mode) &&
+                                  sha_eq(dst_other.sha1, ren1->pair->two->sha1)) {
+                               /* Added file on the other side
+                                  identical to the file being
+                                  renamed: clean merge */
+                               update_file(o, 1, ren1->pair->two->sha1, ren1->pair->two->mode, ren1_dst);
                        } else if (!sha_eq(dst_other.sha1, null_sha1)) {
                                const char *new_path;
                                clean_merge = 0;
diff --git a/t/t3030-merge-recursive.sh b/t/t3030-merge-recursive.sh
index d541544..6436582 100755
--- a/t/t3030-merge-recursive.sh
+++ b/t/t3030-merge-recursive.sh
@@ -23,6 +23,8 @@ test_expect_success 'setup 1' '
        git branch df-3 &&
        git branch remove &&
        git branch submod &&
+       git branch mv &&
+       git branch mv-ln &&

        echo hello >>a &&
        cp a d/e &&
@@ -248,6 +250,25 @@ test_expect_success 'setup 7' '
        git commit -m "make d/ a submodule"
 '

+test_expect_success 'setup 8' '
+
+       git checkout mv-ln &&
+       git mv a e &&
+       ln -s e a &&
+       git add a e &&
+       test_tick &&
+       git commit -m "rename a->e, symlink a->e"
+'
+
+test_expect_success 'setup 9' '
+
+       git checkout mv &&
+       git mv a e &&
+       git add e &&
+       test_tick &&
+       git commit -m "rename a->e"
+'
+
 test_expect_success 'merge-recursive simple' '

        rm -fr [abcd] &&
@@ -580,4 +601,23 @@ test_expect_failure 'merge-recursive simple w/submodule result' '
        test_cmp expected actual
 '

+test_expect_success 'merge-recursive rename vs. rename/symlink' '
+
+       git checkout -f mv &&
+       git merge mv-ln &&
+       ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
+       (
+               echo "100644 blob $o0   b"
+               echo "100644 blob $o0   c"
+               echo "100644 blob $o0   d/e"
+               echo "100644 blob $o0   e"
+               echo "100644 $o0 0      b"
+               echo "100644 $o0 0      c"
+               echo "100644 $o0 0      d/e"
+               echo "100644 $o0 0      e"
+       ) >expected &&
+       test_cmp expected actual
+'
+
+
 test_done
--
1.7.0
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]