Code

Merge branch 'maint-1.6.4' into maint
[git.git] / t / t5516-fetch-push.sh
index f9e878022a93657a8b8d81339670f4d910392755..6889a53cf9bdea0aff88789f954ddf31d1eec010 100755 (executable)
@@ -39,6 +39,11 @@ mk_test () {
        )
 }
 
+mk_child() {
+       rm -rf "$1" &&
+       git clone testrepo "$1"
+}
+
 check_push_result () {
        (
                cd testrepo &&
@@ -117,6 +122,23 @@ test_expect_success 'fetch with insteadOf' '
        )
 '
 
+test_expect_success 'fetch with pushInsteadOf (should not rewrite)' '
+       mk_empty &&
+       (
+               TRASH=$(pwd)/ &&
+               cd testrepo &&
+               git config "url.trash/.pushInsteadOf" "$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 &&
 
@@ -157,6 +179,36 @@ test_expect_success 'push with insteadOf' '
        )
 '
 
+test_expect_success 'push with pushInsteadOf' '
+       mk_empty &&
+       TRASH="$(pwd)/" &&
+       git config "url.$TRASH.pushInsteadOf" 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 pushInsteadOf and explicit pushurl (pushInsteadOf should not rewrite)' '
+       mk_empty &&
+       TRASH="$(pwd)/" &&
+       git config "url.trash2/.pushInsteadOf" trash/ &&
+       git config remote.r.url trash/wrong &&
+       git config remote.r.pushurl "$TRASH/testrepo" &&
+       git push r 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 &&
@@ -414,6 +466,19 @@ test_expect_success 'push with config remote.*.push = HEAD' '
 git config --remove-section remote.there
 git config --remove-section branch.master
 
+test_expect_success 'push with config remote.*.pushurl' '
+
+       mk_test heads/master &&
+       git checkout master &&
+       git config remote.there.url test2repo &&
+       git config remote.there.pushurl testrepo &&
+       git push there &&
+       check_push_result $the_commit heads/master
+'
+
+# clean up the cruft left with the previous one
+git config --remove-section remote.there
+
 test_expect_success 'push with dry-run' '
 
        mk_test heads/master &&
@@ -425,13 +490,10 @@ 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) &&
-       git clone parent child &&
+       mk_test heads/master &&
+       mk_child child &&
        (cd child &&
-               echo two >foo && git commit -a -m two &&
+               git pull .. master &&
                git push &&
        test $(git rev-parse master) = $(git rev-parse remotes/origin/master))
 
@@ -439,15 +501,10 @@ test_expect_success 'push updates local refs' '
 
 test_expect_success 'push updates up-to-date local refs' '
 
-       rm -rf parent child &&
-       mkdir parent &&
-       (cd parent && git init &&
-               echo one >foo && git add foo && git commit -m one) &&
-       git clone parent child1 &&
-       git clone parent child2 &&
-       (cd child1 &&
-               echo two >foo && git commit -a -m two &&
-               git push) &&
+       mk_test heads/master &&
+       mk_child child1 &&
+       mk_child child2 &&
+       (cd child1 && git pull .. master && git push) &&
        (cd child2 &&
                git pull ../child1 master &&
                git push &&
@@ -457,11 +514,8 @@ test_expect_success 'push updates up-to-date local refs' '
 
 test_expect_success 'push preserves up-to-date packed refs' '
 
-       rm -rf parent child &&
-       mkdir parent &&
-       (cd parent && git init &&
-               echo one >foo && git add foo && git commit -m one) &&
-       git clone parent child &&
+       mk_test heads/master &&
+       mk_child child &&
        (cd child &&
                git push &&
        ! test -f .git/refs/remotes/origin/master)
@@ -470,15 +524,13 @@ test_expect_success 'push preserves up-to-date packed refs' '
 
 test_expect_success 'push does not update local refs on failure' '
 
-       rm -rf parent child &&
-       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) &&
-       git clone parent child &&
+       mk_test heads/master &&
+       mk_child child &&
+       mkdir testrepo/.git/hooks &&
+       echo exit 1 >testrepo/.git/hooks/pre-receive &&
+       chmod +x testrepo/.git/hooks/pre-receive &&
        (cd child &&
-               echo two >foo && git commit -a -m two &&
+               git pull .. master
                test_must_fail git push &&
                test $(git rev-parse master) != \
                        $(git rev-parse remotes/origin/master))
@@ -487,13 +539,50 @@ test_expect_success 'push does not update local refs on failure' '
 
 test_expect_success 'allow deleting an invalid remote ref' '
 
-       pwd &&
+       mk_test heads/master &&
        rm -f testrepo/.git/objects/??/* &&
        git push testrepo :refs/heads/master &&
        (cd testrepo && test_must_fail git rev-parse --verify refs/heads/master)
 
 '
 
+test_expect_success 'warn on push to HEAD of non-bare repository' '
+       mk_test heads/master
+       (cd testrepo &&
+               git checkout master &&
+               git config receive.denyCurrentBranch warn) &&
+       git push testrepo master 2>stderr &&
+       grep "warning: updating the current branch" stderr
+'
+
+test_expect_success 'deny push to HEAD of non-bare repository' '
+       mk_test heads/master
+       (cd testrepo &&
+               git checkout master &&
+               git config receive.denyCurrentBranch true) &&
+       test_must_fail git push testrepo master
+'
+
+test_expect_success 'allow push to HEAD of bare repository (bare)' '
+       mk_test heads/master
+       (cd testrepo &&
+               git checkout master &&
+               git config receive.denyCurrentBranch true &&
+               git config core.bare true) &&
+       git push testrepo master 2>stderr &&
+       ! grep "warning: updating the current branch" stderr
+'
+
+test_expect_success 'allow push to HEAD of non-bare repository (config)' '
+       mk_test heads/master
+       (cd testrepo &&
+               git checkout master &&
+               git config receive.denyCurrentBranch false
+       ) &&
+       git push testrepo master 2>stderr &&
+       ! grep "warning: updating the current branch" stderr
+'
+
 test_expect_success 'fetch with branches' '
        mk_empty &&
        git branch second $the_first_commit &&