Code

Merge branch 'maint'
[git.git] / t / t5516-fetch-push.sh
index b0ff48816e91991b26d0158fe65ebd2e70450171..793ffc6600202431193887a12981105c099d40df 100755 (executable)
@@ -100,6 +100,23 @@ test_expect_success 'fetch with wildcard' '
        )
 '
 
+test_expect_success 'fetch with insteadOf' '
+       mk_empty &&
+       (
+               TRASH=$(pwd) &&
+               cd testrepo &&
+               git config url./$TRASH/.insteadOf trash/
+               git config remote.up.url trash/. &&
+               git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" &&
+               git fetch up &&
+
+               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
+               test "z$r" = "z$the_commit" &&
+
+               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+       )
+'
+
 test_expect_success 'push without wildcard' '
        mk_empty &&
 
@@ -126,6 +143,20 @@ test_expect_success 'push with wildcard' '
        )
 '
 
+test_expect_success 'push with insteadOf' '
+       mk_empty &&
+       TRASH=$(pwd) &&
+       git config url./$TRASH/.insteadOf trash/ &&
+       git push trash/testrepo refs/heads/master:refs/remotes/origin/master &&
+       (
+               cd testrepo &&
+               r=$(git show-ref -s --verify refs/remotes/origin/master) &&
+               test "z$r" = "z$the_commit" &&
+
+               test 1 = $(git for-each-ref refs/remotes/origin | wc -l)
+       )
+'
+
 test_expect_success 'push with matching heads' '
 
        mk_test heads/master &&
@@ -145,11 +176,21 @@ test_expect_success 'push with no ambiguity (1)' '
 test_expect_success 'push with no ambiguity (2)' '
 
        mk_test remotes/origin/master &&
-       git push testrepo master:master &&
+       git push testrepo master:origin/master &&
        check_push_result $the_commit remotes/origin/master
 
 '
 
+test_expect_success 'push with colon-less refspec, no ambiguity' '
+
+       mk_test heads/master heads/t/master &&
+       git branch -f t/master master &&
+       git push testrepo master &&
+       check_push_result $the_commit heads/master &&
+       check_push_result $the_first_commit heads/t/master
+
+'
+
 test_expect_success 'push with weak ambiguity (1)' '
 
        mk_test heads/master remotes/origin/master &&
@@ -261,12 +302,54 @@ test_expect_success 'push with HEAD nonexisting at remote' '
        check_push_result $the_commit heads/local
 '
 
+test_expect_success 'push with +HEAD' '
+
+       mk_test heads/master &&
+       git checkout master &&
+       git branch -D local &&
+       git checkout -b local &&
+       git push testrepo master local &&
+       check_push_result $the_commit heads/master &&
+       check_push_result $the_commit heads/local &&
+
+       # Without force rewinding should fail
+       git reset --hard HEAD^ &&
+       ! git push testrepo HEAD &&
+       check_push_result $the_commit heads/local &&
+
+       # With force rewinding should succeed
+       git push testrepo +HEAD &&
+       check_push_result $the_first_commit heads/local
+
+'
+
+test_expect_success 'push with config remote.*.push = HEAD' '
+
+       mk_test heads/local &&
+       git checkout master &&
+       git branch -f local $the_commit &&
+       (
+               cd testrepo &&
+               git checkout local &&
+               git reset --hard $the_first_commit
+       ) &&
+       git config remote.there.url testrepo &&
+       git config remote.there.push HEAD &&
+       git config branch.master.remote there &&
+       git push &&
+       check_push_result $the_commit heads/master &&
+       check_push_result $the_first_commit heads/local
+'
+
+# clean up the cruft left with the previous one
+git config --remove-section remote.there
+git config --remove-section branch.master
+
 test_expect_success 'push with dry-run' '
 
        mk_test heads/master &&
-       cd testrepo &&
-       old_commit=$(git show-ref -s --verify refs/heads/master) &&
-       cd .. &&
+       (cd testrepo &&
+        old_commit=$(git show-ref -s --verify refs/heads/master)) &&
        git push --dry-run testrepo &&
        check_push_result $old_commit heads/master
 '
@@ -274,28 +357,40 @@ test_expect_success 'push with dry-run' '
 test_expect_success 'push updates local refs' '
 
        rm -rf parent child &&
-       mkdir parent && cd parent && git init &&
-               echo one >foo && git add foo && git commit -m one &&
-       cd .. &&
-       git clone parent child && cd child &&
+       mkdir parent &&
+       (cd parent && git init &&
+               echo one >foo && git add foo && git commit -m one) &&
+       git clone parent child &&
+       (cd child &&
                echo two >foo && git commit -a -m two &&
                git push &&
-       test $(git rev-parse master) = $(git rev-parse remotes/origin/master)
+       test $(git rev-parse master) = $(git rev-parse remotes/origin/master))
 
 '
 
 test_expect_success 'push does not update local refs on failure' '
 
        rm -rf parent child &&
-       mkdir parent && cd parent && git init &&
+       mkdir parent &&
+       (cd parent && git init &&
                echo one >foo && git add foo && git commit -m one &&
                echo exit 1 >.git/hooks/pre-receive &&
-               chmod +x .git/hooks/pre-receive &&
-       cd .. &&
-       git clone parent child && cd child &&
-               echo two >foo && git commit -a -m two || exit 1
-               git push && exit 1
-       test $(git rev-parse master) != $(git rev-parse remotes/origin/master)
+               chmod +x .git/hooks/pre-receive) &&
+       git clone parent child &&
+       (cd child &&
+               echo two >foo && git commit -a -m two &&
+               ! git push &&
+               test $(git rev-parse master) != \
+                       $(git rev-parse remotes/origin/master))
+
+'
+
+test_expect_success 'allow deleting an invalid remote ref' '
+
+       pwd &&
+       rm -f testrepo/.git/objects/??/* &&
+       git push testrepo :refs/heads/master &&
+       (cd testrepo && ! git rev-parse --verify refs/heads/master)
 
 '