]>
Commit | Line | Data |
---|---|---|
ec55559f AS |
1 | #!/bin/sh |
2 | ||
3 | test_description='check pre-push hooks' | |
028cb644 | 4 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
5 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
6 | ||
20debfb2 | 7 | TEST_PASSES_SANITIZE_LEAK=true |
ec55559f AS |
8 | . ./test-lib.sh |
9 | ||
ec55559f | 10 | test_expect_success 'setup' ' |
66865d12 ÆAB |
11 | test_hook pre-push <<-\EOF && |
12 | cat >actual | |
13 | EOF | |
14 | ||
ec55559f AS |
15 | git config push.default upstream && |
16 | git init --bare repo1 && | |
17 | git remote add parent1 repo1 && | |
18 | test_commit one && | |
bbd837f0 ÆAB |
19 | cat >expect <<-EOF && |
20 | HEAD $(git rev-parse HEAD) refs/heads/foreign $(test_oid zero) | |
21 | EOF | |
22 | ||
23 | test_when_finished "rm actual" && | |
24 | git push parent1 HEAD:foreign && | |
25 | test_cmp expect actual | |
ec55559f | 26 | ' |
ec55559f AS |
27 | |
28 | COMMIT1="$(git rev-parse HEAD)" | |
29 | export COMMIT1 | |
30 | ||
31 | test_expect_success 'push with failing hook' ' | |
66865d12 ÆAB |
32 | test_hook pre-push <<-\EOF && |
33 | cat >actual && | |
34 | exit 1 | |
35 | EOF | |
36 | ||
ec55559f | 37 | test_commit two && |
bbd837f0 ÆAB |
38 | cat >expect <<-EOF && |
39 | HEAD $(git rev-parse HEAD) refs/heads/main $(test_oid zero) | |
40 | EOF | |
41 | ||
42 | test_when_finished "rm actual" && | |
43 | test_must_fail git push parent1 HEAD && | |
44 | test_cmp expect actual | |
ec55559f AS |
45 | ' |
46 | ||
47 | test_expect_success '--no-verify bypasses hook' ' | |
bbd837f0 ÆAB |
48 | git push --no-verify parent1 HEAD && |
49 | test_path_is_missing actual | |
ec55559f AS |
50 | ' |
51 | ||
52 | COMMIT2="$(git rev-parse HEAD)" | |
53 | export COMMIT2 | |
54 | ||
ec55559f | 55 | test_expect_success 'push with hook' ' |
66865d12 ÆAB |
56 | test_hook --setup pre-push <<-\EOF && |
57 | echo "$1" >actual | |
58 | echo "$2" >>actual | |
59 | cat >>actual | |
60 | EOF | |
61 | ||
44540157 ÆAB |
62 | cat >expect <<-EOF && |
63 | parent1 | |
64 | repo1 | |
65 | refs/heads/main $COMMIT2 refs/heads/foreign $COMMIT1 | |
66 | EOF | |
67 | ||
028cb644 | 68 | git push parent1 main:foreign && |
44540157 | 69 | test_cmp expect actual |
ec55559f AS |
70 | ' |
71 | ||
72 | test_expect_success 'add a branch' ' | |
73 | git checkout -b other parent1/foreign && | |
74 | test_commit three | |
75 | ' | |
76 | ||
77 | COMMIT3="$(git rev-parse HEAD)" | |
78 | export COMMIT3 | |
79 | ||
ec55559f | 80 | test_expect_success 'push to default' ' |
44540157 ÆAB |
81 | cat >expect <<-EOF && |
82 | parent1 | |
83 | repo1 | |
84 | refs/heads/other $COMMIT3 refs/heads/foreign $COMMIT2 | |
85 | EOF | |
ec55559f | 86 | git push && |
44540157 | 87 | test_cmp expect actual |
ec55559f AS |
88 | ' |
89 | ||
ec55559f | 90 | test_expect_success 'push non-branches' ' |
44540157 ÆAB |
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 | |
97 | ||
ec55559f | 98 | git push parent1 one:tag1 HEAD~:refs/heads/prev && |
44540157 | 99 | test_cmp expect actual |
ec55559f AS |
100 | ' |
101 | ||
ec55559f | 102 | test_expect_success 'push delete' ' |
44540157 ÆAB |
103 | cat >expect <<-EOF && |
104 | parent1 | |
105 | repo1 | |
106 | (delete) $ZERO_OID refs/heads/prev $COMMIT2 | |
107 | EOF | |
108 | ||
ec55559f | 109 | git push parent1 :prev && |
44540157 | 110 | test_cmp expect actual |
ec55559f AS |
111 | ' |
112 | ||
ec55559f | 113 | test_expect_success 'push to URL' ' |
44540157 ÆAB |
114 | cat >expect <<-EOF && |
115 | repo1 | |
116 | repo1 | |
117 | HEAD $COMMIT3 refs/heads/other $ZERO_OID | |
118 | EOF | |
119 | ||
ec55559f | 120 | git push repo1 HEAD && |
44540157 | 121 | test_cmp expect actual |
ec55559f AS |
122 | ' |
123 | ||
af65f68c CB |
124 | test_expect_success 'set up many-ref tests' ' |
125 | { | |
7abcbcb7 | 126 | nr=1000 && |
af65f68c CB |
127 | while test $nr -lt 2000 |
128 | do | |
74d2f569 | 129 | nr=$(( $nr + 1 )) && |
d0fd9931 | 130 | echo "create refs/heads/b/$nr $COMMIT3" || return 1 |
af65f68c CB |
131 | done |
132 | } | git update-ref --stdin | |
133 | ' | |
134 | ||
135 | test_expect_success 'sigpipe does not cause pre-push hook failure' ' | |
66865d12 ÆAB |
136 | test_hook --clobber pre-push <<-\EOF && |
137 | exit 0 | |
138 | EOF | |
af65f68c CB |
139 | git push parent1 "refs/heads/b/*:refs/heads/b/*" |
140 | ' | |
ec55559f AS |
141 | |
142 | test_done |