3 test_description
='check pre-push hooks'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7 TEST_PASSES_SANITIZE_LEAK
=true
10 test_expect_success
'setup' '
11 test_hook pre-push <<-\EOF &&
15 git config push.default upstream &&
16 git init --bare repo1 &&
17 git remote add parent1 repo1 &&
20 HEAD $(git rev-parse HEAD) refs/heads/foreign $(test_oid zero)
23 test_when_finished "rm actual" &&
24 git push parent1 HEAD:foreign &&
25 test_cmp expect actual
28 COMMIT1
="$(git rev-parse HEAD)"
31 test_expect_success
'push with failing hook' '
32 test_hook pre-push <<-\EOF &&
39 HEAD $(git rev-parse HEAD) refs/heads/main $(test_oid zero)
42 test_when_finished "rm actual" &&
43 test_must_fail git push parent1 HEAD &&
44 test_cmp expect actual
47 test_expect_success
'--no-verify bypasses hook' '
48 git push --no-verify parent1 HEAD &&
49 test_path_is_missing actual
52 COMMIT2
="$(git rev-parse HEAD)"
55 test_expect_success
'push with hook' '
56 test_hook --setup pre-push <<-\EOF &&
65 refs/heads/main $COMMIT2 refs/heads/foreign $COMMIT1
68 git push parent1 main:foreign &&
69 test_cmp expect actual
72 test_expect_success
'add a branch' '
73 git checkout -b other parent1/foreign &&
77 COMMIT3
="$(git rev-parse HEAD)"
80 test_expect_success
'push to default' '
84 refs/heads/other $COMMIT3 refs/heads/foreign $COMMIT2
87 test_cmp expect actual
90 test_expect_success
'push non-branches' '
94 refs/tags/one $COMMIT1 refs/tags/tag1 $ZERO_OID
95 HEAD~ $COMMIT2 refs/heads/prev $ZERO_OID
98 git push parent1 one:tag1 HEAD~:refs/heads/prev &&
99 test_cmp expect actual
102 test_expect_success
'push delete' '
103 cat >expect <<-EOF &&
106 (delete) $ZERO_OID refs/heads/prev $COMMIT2
109 git push parent1 :prev &&
110 test_cmp expect actual
113 test_expect_success
'push to URL' '
114 cat >expect <<-EOF &&
117 HEAD $COMMIT3 refs/heads/other $ZERO_OID
120 git push repo1 HEAD &&
121 test_cmp expect actual
124 test_expect_success
'set up many-ref tests' '
127 while test $nr -lt 2000
130 echo "create refs/heads/b/$nr $COMMIT3" || return 1
132 } | git update-ref --stdin
135 test_expect_success
'sigpipe does not cause pre-push hook failure' '
136 test_hook --clobber pre-push <<-\EOF &&
139 git push parent1 "refs/heads/b/*:refs/heads/b/*"