3 test_description='check pre-push hooks'
6 # Setup hook that always succeeds
7 HOOKDIR="$(git rev-parse --git-dir)/hooks"
8 HOOK="$HOOKDIR/pre-push"
10 write_script "$HOOK" <<EOF
15 test_expect_success 'setup' '
16 git config push.default upstream &&
17 git init --bare repo1 &&
18 git remote add parent1 repo1 &&
20 git push parent1 HEAD:foreign
22 write_script "$HOOK" <<EOF
27 COMMIT1="$(git rev-parse HEAD)"
30 test_expect_success 'push with failing hook' '
32 test_must_fail git push parent1 HEAD
35 test_expect_success '--no-verify bypasses hook' '
36 git push --no-verify parent1 HEAD
39 COMMIT2="$(git rev-parse HEAD)"
42 write_script "$HOOK" <<'EOF'
51 refs/heads/master $COMMIT2 refs/heads/foreign $COMMIT1
54 test_expect_success 'push with hook' '
55 git push parent1 master:foreign &&
59 test_expect_success 'add a branch' '
60 git checkout -b other parent1/foreign &&
64 COMMIT3="$(git rev-parse HEAD)"
70 refs/heads/other $COMMIT3 refs/heads/foreign $COMMIT2
73 test_expect_success 'push to default' '
81 refs/tags/one $COMMIT1 refs/tags/tag1 $ZERO_OID
82 HEAD~ $COMMIT2 refs/heads/prev $ZERO_OID
85 test_expect_success 'push non-branches' '
86 git push parent1 one:tag1 HEAD~:refs/heads/prev &&
93 (delete) $ZERO_OID refs/heads/prev $COMMIT2
96 test_expect_success 'push delete' '
97 git push parent1 :prev &&
104 HEAD $COMMIT3 refs/heads/other $ZERO_OID
107 test_expect_success 'push to URL' '
108 git push repo1 HEAD &&
112 test_expect_success 'set up many-ref tests' '
115 while test $nr -lt 2000
118 echo "create refs/heads/b/$nr $COMMIT3"
120 } | git update-ref --stdin
123 test_expect_success 'sigpipe does not cause pre-push hook failure' '
124 echo "exit 0" | write_script "$HOOK" &&
125 git push parent1 "refs/heads/b/*:refs/heads/b/*"