t5583: fix shebang line
[alt-git.git] / t / t5571-pre-push-hook.sh
bloba11b20e378223ea30242e70d5befcfeed889a2ed
1 #!/bin/sh
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-lib.sh
9 test_expect_success 'setup' '
10 test_hook pre-push <<-\EOF &&
11 cat >actual
12 EOF
14 git config push.default upstream &&
15 git init --bare repo1 &&
16 git remote add parent1 repo1 &&
17 test_commit one &&
18 cat >expect <<-EOF &&
19 HEAD $(git rev-parse HEAD) refs/heads/foreign $(test_oid zero)
20 EOF
22 test_when_finished "rm actual" &&
23 git push parent1 HEAD:foreign &&
24 test_cmp expect actual
27 COMMIT1="$(git rev-parse HEAD)"
28 export COMMIT1
30 test_expect_success 'push with failing hook' '
31 test_hook pre-push <<-\EOF &&
32 cat >actual &&
33 exit 1
34 EOF
36 test_commit two &&
37 cat >expect <<-EOF &&
38 HEAD $(git rev-parse HEAD) refs/heads/main $(test_oid zero)
39 EOF
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)"
52 export COMMIT2
54 test_expect_success 'push with hook' '
55 test_hook --setup pre-push <<-\EOF &&
56 echo "$1" >actual
57 echo "$2" >>actual
58 cat >>actual
59 EOF
61 cat >expect <<-EOF &&
62 parent1
63 repo1
64 refs/heads/main $COMMIT2 refs/heads/foreign $COMMIT1
65 EOF
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 &&
73 test_commit three
76 COMMIT3="$(git rev-parse HEAD)"
77 export COMMIT3
79 test_expect_success 'push to default' '
80 cat >expect <<-EOF &&
81 parent1
82 repo1
83 refs/heads/other $COMMIT3 refs/heads/foreign $COMMIT2
84 EOF
85 git push &&
86 test_cmp expect actual
89 test_expect_success 'push non-branches' '
90 cat >expect <<-EOF &&
91 parent1
92 repo1
93 refs/tags/one $COMMIT1 refs/tags/tag1 $ZERO_OID
94 HEAD~ $COMMIT2 refs/heads/prev $ZERO_OID
95 EOF
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 &&
103 parent1
104 repo1
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 &&
114 repo1
115 repo1
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' '
125 nr=1000 &&
126 while test $nr -lt 2000
128 nr=$(( $nr + 1 )) &&
129 echo "create refs/heads/b/$nr $COMMIT3" || return 1
130 done
131 } | git update-ref --stdin
134 test_expect_success 'sigpipe does not cause pre-push hook failure' '
135 test_hook --clobber pre-push <<-\EOF &&
136 exit 0
138 git push parent1 "refs/heads/b/*:refs/heads/b/*"
141 test_done