Imported Upstream version 2.16.2
[platform/upstream/git.git] / t / t3030-merge-recursive.sh
index 82e1854..cdc38fe 100755 (executable)
@@ -263,7 +263,7 @@ test_expect_success 'setup 8' '
        test_ln_s_add e a &&
        test_tick &&
        git commit -m "rename a->e, symlink a->e" &&
-       oln=`printf e | git hash-object --stdin`
+       oln=$(printf e | git hash-object --stdin)
 '
 
 test_expect_success 'setup 9' '
@@ -575,13 +575,13 @@ test_expect_success 'merge removes empty directories' '
        test_must_fail test -d d
 '
 
-test_expect_failure 'merge-recursive simple w/submodule' '
+test_expect_success 'merge-recursive simple w/submodule' '
 
        git checkout submod &&
        git merge remove
 '
 
-test_expect_failure 'merge-recursive simple w/submodule result' '
+test_expect_success 'merge-recursive simple w/submodule result' '
 
        git ls-files -s >actual &&
        (
@@ -629,5 +629,103 @@ test_expect_failure 'merge-recursive rename vs. rename/symlink' '
        test_cmp expected actual
 '
 
+test_expect_success 'merging with triple rename across D/F conflict' '
+       git reset --hard HEAD &&
+       git checkout -b main &&
+       git rm -rf . &&
+
+       echo "just a file" >sub1 &&
+       mkdir -p sub2 &&
+       echo content1 >sub2/file1 &&
+       echo content2 >sub2/file2 &&
+       echo content3 >sub2/file3 &&
+       mkdir simple &&
+       echo base >simple/bar &&
+       git add -A &&
+       test_tick &&
+       git commit -m base &&
+
+       git checkout -b other &&
+       echo more >>simple/bar &&
+       test_tick &&
+       git commit -a -m changesimplefile &&
+
+       git checkout main &&
+       git rm sub1 &&
+       git mv sub2 sub1 &&
+       test_tick &&
+       git commit -m changefiletodir &&
+
+       test_tick &&
+       git merge other
+'
+
+test_expect_success 'merge-recursive remembers the names of all base trees' '
+       git reset --hard HEAD &&
+
+       # more trees than static slots used by oid_to_hex()
+       for commit in $c0 $c2 $c4 $c5 $c6 $c7
+       do
+               git rev-parse "$commit^{tree}"
+       done >trees &&
+
+       # ignore the return code -- it only fails because the input is weird
+       test_must_fail git -c merge.verbosity=5 merge-recursive $(cat trees) -- $c1 $c3 >out &&
+
+       # merge-recursive prints in reverse order, but we do not care
+       sort <trees >expect &&
+       sed -n "s/^virtual //p" out | sort >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success 'merge-recursive internal merge resolves to the sameness' '
+       git reset --hard HEAD &&
+
+       # We are going to create a history leading to two criss-cross
+       # branches A and B.  The common ancestor at the bottom, O0,
+       # has two child commits O1 and O2, both of which will be merge
+       # base between A and B, like so:
+       #
+       #       O1---A
+       #      /  \ /
+       #    O0    .
+       #      \  / \
+       #       O2---B
+       #
+       # The recently added "check to see if the index is different from
+       # the tree into which something else is getting merged" check must
+       # NOT kick in when an inner merge between O1 and O2 is made.  Both
+       # O1 and O2 happen to have the same tree as O0 in this test to
+       # trigger the bug---whether the inner merge is made by merging O2
+       # into O1 or O1 into O2, their common ancestor O0 and the branch
+       # being merged have the same tree.  We should not trigger the "is
+       # the index dirty?" check in this case.
+
+       echo "zero" >file &&
+       git add file &&
+       test_tick &&
+       git commit -m "O0" &&
+       O0=$(git rev-parse HEAD) &&
+
+       test_tick &&
+       git commit --allow-empty -m "O1" &&
+       O1=$(git rev-parse HEAD) &&
+
+       git reset --hard $O0 &&
+       test_tick &&
+       git commit --allow-empty -m "O2" &&
+       O2=$(git rev-parse HEAD) &&
+
+       test_tick &&
+       git merge -s ours $O1 &&
+       B=$(git rev-parse HEAD) &&
+
+       git reset --hard $O1 &&
+       test_tick &&
+       git merge -s ours $O2 &&
+       A=$(git rev-parse HEAD) &&
+
+       git merge $B
+'
 
 test_done