]> git.ipfire.org Git - thirdparty/git.git/commitdiff
merge-recursive: restore accidentally dropped setting of path
authorElijah Newren <newren@gmail.com>
Tue, 4 Jun 2019 20:27:50 +0000 (13:27 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 5 Jun 2019 16:30:40 +0000 (09:30 -0700)
In commit 8daec1df03de ("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 <behumphreys@atlassian.com>
Based-on-patch-by: SZEDER Gábor <szeder.dev@gmail.com>
Tested-by: Ben Humphreys <behumphreys@atlassian.com>
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
merge-recursive.c
t/t6042-merge-rename-corner-cases.sh

index 36af441faa0b562222853c27128b5a23de99e551..917b9229eb8695d93f78e355a8e702fe101ea76e 100644 (file)
@@ -1655,6 +1655,7 @@ static int handle_rename_add(struct merge_options *opt,
               c->path, add_branch);
 
        prev_path_desc = xstrfmt("version of %s from %s", path, a->path);
+       ci->ren1->src_entry->stages[other_stage].path = a->path;
        if (merge_mode_and_contents(opt, a, c,
                                    &ci->ren1->src_entry->stages[other_stage],
                                    prev_path_desc,
index 09dfa8bd92b51e7a90fcd01f07c62a6fdf65a528..c5b57f40c3d127cffda505f9ffe91effffafb135 100755 (executable)
@@ -411,6 +411,122 @@ test_expect_success 'disappearing dir in rename/directory conflict handled' '
        )
 '
 
+# Test for basic rename/add-dest conflict, with rename needing content merge:
+#   Commit O: a
+#   Commit A: rename a->b, modifying b too
+#   Commit B: modify a, add different b
+
+test_expect_success 'setup rename-with-content-merge vs. add' '
+       test_create_repo rename-with-content-merge-and-add &&
+       (
+               cd rename-with-content-merge-and-add &&
+
+               test_seq 1 5 >a &&
+               git add a &&
+               git commit -m O &&
+               git tag O &&
+
+               git checkout -b A O &&
+               git mv a b &&
+               test_seq 0 5 >b &&
+               git add b &&
+               git commit -m A &&
+
+               git checkout -b B O &&
+               echo 6 >>a &&
+               echo hello world >b &&
+               git add a b &&
+               git commit -m B
+       )
+'
+
+test_expect_success 'handle rename-with-content-merge vs. add' '
+       (
+               cd rename-with-content-merge-and-add &&
+
+               git checkout A^0 &&
+
+               test_must_fail git merge -s recursive B^0 >out &&
+               test_i18ngrep "CONFLICT (rename/add)" out &&
+
+               git ls-files -s >out &&
+               test_line_count = 2 out &&
+               git ls-files -u >out &&
+               test_line_count = 2 out &&
+               # Also, make sure both unmerged entries are for "b"
+               git ls-files -u b >out &&
+               test_line_count = 2 out &&
+               git ls-files -o >out &&
+               test_line_count = 1 out &&
+
+               test_path_is_missing a &&
+               test_path_is_file b &&
+
+               test_seq 0 6 >tmp &&
+               git hash-object tmp >expect &&
+               git rev-parse B:b >>expect &&
+               git rev-parse >actual  \
+                       :2:b    :3:b   &&
+               test_cmp expect actual &&
+
+               # Test that the two-way merge in b is as expected
+               git cat-file -p :2:b >>ours &&
+               git cat-file -p :3:b >>theirs &&
+               >empty &&
+               test_must_fail git merge-file \
+                       -L "HEAD" \
+                       -L "" \
+                       -L "B^0" \
+                       ours empty theirs &&
+               test_cmp ours b
+       )
+'
+
+test_expect_success 'handle rename-with-content-merge vs. add, merge other way' '
+       (
+               cd rename-with-content-merge-and-add &&
+
+               git reset --hard &&
+               git clean -fdx &&
+
+               git checkout B^0 &&
+
+               test_must_fail git merge -s recursive A^0 >out &&
+               test_i18ngrep "CONFLICT (rename/add)" out &&
+
+               git ls-files -s >out &&
+               test_line_count = 2 out &&
+               git ls-files -u >out &&
+               test_line_count = 2 out &&
+               # Also, make sure both unmerged entries are for "b"
+               git ls-files -u b >out &&
+               test_line_count = 2 out &&
+               git ls-files -o >out &&
+               test_line_count = 1 out &&
+
+               test_path_is_missing a &&
+               test_path_is_file b &&
+
+               test_seq 0 6 >tmp &&
+               git rev-parse B:b >expect &&
+               git hash-object tmp >>expect &&
+               git rev-parse >actual  \
+                       :2:b    :3:b   &&
+               test_cmp expect actual &&
+
+               # Test that the two-way merge in b is as expected
+               git cat-file -p :2:b >>ours &&
+               git cat-file -p :3:b >>theirs &&
+               >empty &&
+               test_must_fail git merge-file \
+                       -L "HEAD" \
+                       -L "" \
+                       -L "A^0" \
+                       ours empty theirs &&
+               test_cmp ours b
+       )
+'
+
 # Test for all kinds of things that can go wrong with rename/rename (2to1):
 #   Commit A: new files: a & b
 #   Commit B: rename a->c, modify b