3 test_description
='check pre-push hooks'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9 # Setup hook that always succeeds
10 HOOKDIR
="$(git rev-parse --git-dir)/hooks"
11 HOOK
="$HOOKDIR/pre-push"
13 write_script
"$HOOK" <<EOF
18 test_expect_success
'setup' '
19 git config push.default upstream &&
20 git init --bare repo1 &&
21 git remote add parent1 repo1 &&
23 git push parent1 HEAD:foreign
25 write_script
"$HOOK" <<EOF
30 COMMIT1
="$(git rev-parse HEAD)"
33 test_expect_success
'push with failing hook' '
35 test_must_fail git push parent1 HEAD
38 test_expect_success
'--no-verify bypasses hook' '
39 git push --no-verify parent1 HEAD
42 COMMIT2
="$(git rev-parse HEAD)"
45 write_script
"$HOOK" <<'EOF'
54 refs/heads/main $COMMIT2 refs/heads/foreign $COMMIT1
57 test_expect_success
'push with hook' '
58 git push parent1 main:foreign &&
62 test_expect_success
'add a branch' '
63 git checkout -b other parent1/foreign &&
67 COMMIT3
="$(git rev-parse HEAD)"
73 refs/heads/other $COMMIT3 refs/heads/foreign $COMMIT2
76 test_expect_success
'push to default' '
84 refs/tags/one $COMMIT1 refs/tags/tag1 $ZERO_OID
85 HEAD~ $COMMIT2 refs/heads/prev $ZERO_OID
88 test_expect_success
'push non-branches' '
89 git push parent1 one:tag1 HEAD~:refs/heads/prev &&
96 (delete) $ZERO_OID refs/heads/prev $COMMIT2
99 test_expect_success
'push delete' '
100 git push parent1 :prev &&
107 HEAD $COMMIT3 refs/heads/other $ZERO_OID
110 test_expect_success
'push to URL' '
111 git push repo1 HEAD &&
115 test_expect_success
'set up many-ref tests' '
118 while test $nr -lt 2000
121 echo "create refs/heads/b/$nr $COMMIT3"
123 } | git update-ref --stdin
126 test_expect_success
'sigpipe does not cause pre-push hook failure' '
127 echo "exit 0" | write_script "$HOOK" &&
128 git push parent1 "refs/heads/b/*:refs/heads/b/*"