3 test_description
='check pre-push hooks'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9 test_expect_success
'setup' '
10 test_hook pre-push <<-\EOF &&
14 git config push.default upstream &&
15 git init --bare repo1 &&
16 git remote add parent1 repo1 &&
19 HEAD $(git rev-parse HEAD) refs/heads/foreign $(test_oid zero)
22 test_when_finished "rm actual" &&
23 git push parent1 HEAD:foreign &&
24 test_cmp expect actual
27 COMMIT1
="$(git rev-parse HEAD)"
30 test_expect_success
'push with failing hook' '
31 test_hook pre-push <<-\EOF &&
38 HEAD $(git rev-parse HEAD) refs/heads/main $(test_oid zero)
41 test_when_finished "rm actual" &&
42 test_must_fail git push parent1 HEAD &&
43 test_cmp expect actual
46 test_expect_success
'--no-verify bypasses hook' '
47 git push --no-verify parent1 HEAD &&
48 test_path_is_missing actual
51 COMMIT2
="$(git rev-parse HEAD)"
54 test_expect_success
'push with hook' '
55 test_hook --setup pre-push <<-\EOF &&
64 refs/heads/main $COMMIT2 refs/heads/foreign $COMMIT1
67 git push parent1 main:foreign &&
68 test_cmp expect actual
71 test_expect_success
'add a branch' '
72 git checkout -b other parent1/foreign &&
76 COMMIT3
="$(git rev-parse HEAD)"
79 test_expect_success
'push to default' '
83 refs/heads/other $COMMIT3 refs/heads/foreign $COMMIT2
86 test_cmp expect actual
89 test_expect_success
'push non-branches' '
93 refs/tags/one $COMMIT1 refs/tags/tag1 $ZERO_OID
94 HEAD~ $COMMIT2 refs/heads/prev $ZERO_OID
97 git push parent1 one:tag1 HEAD~:refs/heads/prev &&
98 test_cmp expect actual
101 test_expect_success
'push delete' '
102 cat >expect <<-EOF &&
105 (delete) $ZERO_OID refs/heads/prev $COMMIT2
108 git push parent1 :prev &&
109 test_cmp expect actual
112 test_expect_success
'push to URL' '
113 cat >expect <<-EOF &&
116 HEAD $COMMIT3 refs/heads/other $ZERO_OID
119 git push repo1 HEAD &&
120 test_cmp expect actual
123 test_expect_success
'set up many-ref tests' '
126 while test $nr -lt 2000
129 echo "create refs/heads/b/$nr $COMMIT3" || return 1
131 } | git update-ref --stdin
134 test_expect_success
'sigpipe does not cause pre-push hook failure' '
135 test_hook --clobber pre-push <<-\EOF &&
138 git push parent1 "refs/heads/b/*:refs/heads/b/*"