Code

t5516: test update of local refs on push
[git.git] / t / t5516-fetch-push.sh
index 08d58e1c8c8d61d50c97b48d795ac1a574d56035..86f9b5346a0d7d8807d8c37c063690540873813a 100755 (executable)
@@ -11,7 +11,8 @@ mk_empty () {
        mkdir testrepo &&
        (
                cd testrepo &&
-               git init
+               git init &&
+               mv .git/hooks .git/hooks-disabled
        )
 }
 
@@ -226,7 +227,7 @@ test_expect_success 'push with colon-less refspec (3)' '
        git branch -f frotz master &&
        git push testrepo frotz &&
        check_push_result $the_commit heads/frotz &&
-       test "$( cd testrepo && git show-ref | wc -l )" = 1
+       test 1 = $( cd testrepo && git show-ref | wc -l )
 '
 
 test_expect_success 'push with colon-less refspec (4)' '
@@ -239,7 +240,45 @@ test_expect_success 'push with colon-less refspec (4)' '
        git tag -f frotz &&
        git push testrepo frotz &&
        check_push_result $the_commit tags/frotz &&
-       test "$( cd testrepo && git show-ref | wc -l )" = 1
+       test 1 = $( cd testrepo && git show-ref | wc -l )
+
+'
+
+test_expect_success 'push with dry-run' '
+
+       mk_test heads/master &&
+       cd testrepo &&
+       old_commit=$(git show-ref -s --verify refs/heads/master) &&
+       cd .. &&
+       git push --dry-run testrepo &&
+       check_push_result $old_commit heads/master
+'
+
+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 &&
+               echo two >foo && git commit -a -m two &&
+               git push &&
+       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 &&
+               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)
 
 '