Imported Upstream version 2.13.1
[platform/upstream/git.git] / t / t5531-deep-submodule-push.sh
index 198ce84..23c533e 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-test_description='unpack-objects'
+test_description='test push with submodules'
 
 . ./test-lib.sh
 
@@ -27,7 +27,7 @@ test_expect_success setup '
        )
 '
 
-test_expect_success push '
+test_expect_success 'push works with recorded gitlink' '
        (
                cd work &&
                git push ../pub.git master
@@ -427,7 +427,104 @@ test_expect_success 'push unpushable submodule recursively fails' '
                cd submodule.git &&
                git rev-parse master >../actual
        ) &&
+       test_when_finished git -C work reset --hard master^ &&
        test_cmp expected actual
 '
 
+test_expect_success 'push --dry-run does not recursively update submodules' '
+       (
+               cd work/gar/bage &&
+               git checkout master &&
+               git rev-parse master >../../../expected_submodule &&
+               > junk9 &&
+               git add junk9 &&
+               git commit -m "Ninth junk" &&
+
+               # Go up to 'work' directory
+               cd ../.. &&
+               git checkout master &&
+               git rev-parse master >../expected_pub &&
+               git add gar/bage &&
+               git commit -m "Ninth commit for gar/bage" &&
+               git push --dry-run --recurse-submodules=on-demand ../pub.git master
+       ) &&
+       git -C submodule.git rev-parse master >actual_submodule &&
+       git -C pub.git rev-parse master >actual_pub &&
+       test_cmp expected_pub actual_pub &&
+       test_cmp expected_submodule actual_submodule
+'
+
+test_expect_success 'push --dry-run does not recursively update submodules' '
+       git -C work push --dry-run --recurse-submodules=only ../pub.git master &&
+
+       git -C submodule.git rev-parse master >actual_submodule &&
+       git -C pub.git rev-parse master >actual_pub &&
+       test_cmp expected_pub actual_pub &&
+       test_cmp expected_submodule actual_submodule
+'
+
+test_expect_success 'push only unpushed submodules recursively' '
+       git -C work/gar/bage rev-parse master >expected_submodule &&
+       git -C pub.git rev-parse master >expected_pub &&
+
+       git -C work push --recurse-submodules=only ../pub.git master &&
+
+       git -C submodule.git rev-parse master >actual_submodule &&
+       git -C pub.git rev-parse master >actual_pub &&
+       test_cmp expected_submodule actual_submodule &&
+       test_cmp expected_pub actual_pub
+'
+
+test_expect_success 'push propagating the remotes name to a submodule' '
+       git -C work remote add origin ../pub.git &&
+       git -C work remote add pub ../pub.git &&
+
+       > work/gar/bage/junk10 &&
+       git -C work/gar/bage add junk10 &&
+       git -C work/gar/bage commit -m "Tenth junk" &&
+       git -C work add gar/bage &&
+       git -C work commit -m "Tenth junk added to gar/bage" &&
+
+       # Fails when submodule does not have a matching remote
+       test_must_fail git -C work push --recurse-submodules=on-demand pub master &&
+       # Succeeds when submodules has matching remote and refspec
+       git -C work push --recurse-submodules=on-demand origin master &&
+
+       git -C submodule.git rev-parse master >actual_submodule &&
+       git -C pub.git rev-parse master >actual_pub &&
+       git -C work/gar/bage rev-parse master >expected_submodule &&
+       git -C work rev-parse master >expected_pub &&
+       test_cmp expected_submodule actual_submodule &&
+       test_cmp expected_pub actual_pub
+'
+
+test_expect_success 'push propagating refspec to a submodule' '
+       > work/gar/bage/junk11 &&
+       git -C work/gar/bage add junk11 &&
+       git -C work/gar/bage commit -m "Eleventh junk" &&
+
+       git -C work checkout branch2 &&
+       git -C work add gar/bage &&
+       git -C work commit -m "updating gar/bage in branch2" &&
+
+       # Fails when submodule does not have a matching branch
+       test_must_fail git -C work push --recurse-submodules=on-demand origin branch2 &&
+       # Fails when refspec includes an object id
+       test_must_fail git -C work push --recurse-submodules=on-demand origin \
+               "$(git -C work rev-parse branch2):refs/heads/branch2" &&
+       # Fails when refspec includes 'HEAD' as it is unsupported at this time
+       test_must_fail git -C work push --recurse-submodules=on-demand origin \
+               HEAD:refs/heads/branch2 &&
+
+       git -C work/gar/bage branch branch2 master &&
+       git -C work push --recurse-submodules=on-demand origin branch2 &&
+
+       git -C submodule.git rev-parse branch2 >actual_submodule &&
+       git -C pub.git rev-parse branch2 >actual_pub &&
+       git -C work/gar/bage rev-parse branch2 >expected_submodule &&
+       git -C work rev-parse branch2 >expected_pub &&
+       test_cmp expected_submodule actual_submodule &&
+       test_cmp expected_pub actual_pub
+'
+
 test_done