t7501: add tests for --amend --signoff
[git.git] / t / t5571-pre-push-hook.sh
blob448134c4bf72bd5f3a4c2287e59f6f2a1f3f074b
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_PASSES_SANITIZE_LEAK=true
8 . ./test-lib.sh
10 test_expect_success 'setup' '
11 test_hook pre-push <<-\EOF &&
12 cat >actual
13 EOF
15 git config push.default upstream &&
16 git init --bare repo1 &&
17 git remote add parent1 repo1 &&
18 test_commit one &&
19 cat >expect <<-EOF &&
20 HEAD $(git rev-parse HEAD) refs/heads/foreign $(test_oid zero)
21 EOF
23 test_when_finished "rm actual" &&
24 git push parent1 HEAD:foreign &&
25 test_cmp expect actual
28 COMMIT1="$(git rev-parse HEAD)"
29 export COMMIT1
31 test_expect_success 'push with failing hook' '
32 test_hook pre-push <<-\EOF &&
33 cat >actual &&
34 exit 1
35 EOF
37 test_commit two &&
38 cat >expect <<-EOF &&
39 HEAD $(git rev-parse HEAD) refs/heads/main $(test_oid zero)
40 EOF
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)"
53 export COMMIT2
55 test_expect_success 'push with hook' '
56 test_hook --setup pre-push <<-\EOF &&
57 echo "$1" >actual
58 echo "$2" >>actual
59 cat >>actual
60 EOF
62 cat >expect <<-EOF &&
63 parent1
64 repo1
65 refs/heads/main $COMMIT2 refs/heads/foreign $COMMIT1
66 EOF
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 &&
74 test_commit three
77 COMMIT3="$(git rev-parse HEAD)"
78 export COMMIT3
80 test_expect_success 'push to default' '
81 cat >expect <<-EOF &&
82 parent1
83 repo1
84 refs/heads/other $COMMIT3 refs/heads/foreign $COMMIT2
85 EOF
86 git push &&
87 test_cmp expect actual
90 test_expect_success 'push non-branches' '
91 cat >expect <<-EOF &&
92 parent1
93 repo1
94 refs/tags/one $COMMIT1 refs/tags/tag1 $ZERO_OID
95 HEAD~ $COMMIT2 refs/heads/prev $ZERO_OID
96 EOF
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 &&
104 parent1
105 repo1
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 &&
115 repo1
116 repo1
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' '
126 nr=1000 &&
127 while test $nr -lt 2000
129 nr=$(( $nr + 1 )) &&
130 echo "create refs/heads/b/$nr $COMMIT3" || return 1
131 done
132 } | git update-ref --stdin
135 test_expect_success 'sigpipe does not cause pre-push hook failure' '
136 test_hook --clobber pre-push <<-\EOF &&
137 exit 0
139 git push parent1 "refs/heads/b/*:refs/heads/b/*"
142 test_done