1 test_expect_success "setup proc-receive hook (unknown version, $PROTOCOL)" '
2 write_script "$upstream/hooks/proc-receive" <<-EOF
3 printf >&2 "# proc-receive hook\n"
4 test-tool proc-receive -v --version 2
8 # Refs of upstream : main(A)
9 # Refs of workbench: main(A) tags/v123
10 # git push : refs/for/main/topic(A)
11 test_expect_success "proc-receive: bad protocol (unknown version, $PROTOCOL)" '
12 test_must_fail git -C workbench push origin \
13 HEAD:refs/for/main/topic \
15 make_user_friendly_and_stable_output <out >actual &&
17 # Check status report for git-push
19 -e "/^To / { p; n; p; }" \
20 <actual >actual-report &&
22 To <URL/of/upstream.git>
23 ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook)
25 test_cmp expect actual-report &&
27 # Check error message from "receive-pack", but ignore unstable fatal error
28 # message ("remote: fatal: the remote end hung up unexpectedly") which
29 # is different from the remote HTTP server with different locale settings.
30 grep "^remote: error:" <actual >actual-error &&
32 remote: error: proc-receive version "2" is not supported
34 test_cmp expect actual-error &&
36 git -C "$upstream" show-ref >out &&
37 make_user_friendly_and_stable_output <out >actual &&
39 <COMMIT-A> refs/heads/main
41 test_cmp expect actual
44 test_expect_success "setup proc-receive hook (hook --die-version, $PROTOCOL)" '
45 write_script "$upstream/hooks/proc-receive" <<-EOF
46 printf >&2 "# proc-receive hook\n"
47 test-tool proc-receive -v --die-version
51 # Refs of upstream : main(A)
52 # Refs of workbench: main(A) tags/v123
53 # git push : refs/for/main/topic(A)
54 test_expect_success "proc-receive: bad protocol (hook --die-version, $PROTOCOL)" '
55 test_must_fail git -C workbench push origin \
56 HEAD:refs/for/main/topic \
58 make_user_friendly_and_stable_output <out >actual &&
61 remote: # pre-receive hook
62 remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
63 remote: # proc-receive hook
64 remote: fatal: bad protocol version: 1
65 remote: error: proc-receive version "0" is not supported
66 To <URL/of/upstream.git>
67 ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook)
69 test_cmp expect actual &&
71 git -C "$upstream" show-ref >out &&
72 make_user_friendly_and_stable_output <out >actual &&
74 <COMMIT-A> refs/heads/main
76 test_cmp expect actual
79 test_expect_success "setup proc-receive hook (hook --die-readline, $PROTOCOL)" '
80 write_script "$upstream/hooks/proc-receive" <<-EOF
81 printf >&2 "# proc-receive hook\n"
82 test-tool proc-receive -v --die-readline
86 # Refs of upstream : main(A)
87 # Refs of workbench: main(A) tags/v123
88 # git push : refs/for/main/topic(A)
89 test_expect_success "proc-receive: bad protocol (hook --die-readline, $PROTOCOL)" '
90 test_must_fail git -C workbench push origin \
91 HEAD:refs/for/main/topic \
93 make_user_friendly_and_stable_output <out >actual &&
95 grep "remote: fatal: protocol error: expected \"old new ref\", got \"<ZERO-OID> <COMMIT-A> refs/for/main/topic\"" actual &&
97 git -C "$upstream" show-ref >out &&
98 make_user_friendly_and_stable_output <out >actual &&
100 <COMMIT-A> refs/heads/main
102 test_cmp expect actual
105 test_expect_success "setup proc-receive hook (no report, $PROTOCOL)" '
106 write_script "$upstream/hooks/proc-receive" <<-EOF
107 printf >&2 "# proc-receive hook\n"
108 test-tool proc-receive -v
112 # Refs of upstream : main(A)
113 # Refs of workbench: main(A) tags/v123
114 # git push : next(A) refs/for/main/topic(A)
115 test_expect_success "proc-receive: bad protocol (no report, $PROTOCOL)" '
116 test_must_fail git -C workbench push origin \
117 HEAD:refs/heads/next \
118 HEAD:refs/for/main/topic >out 2>&1 &&
119 make_user_friendly_and_stable_output <out >actual &&
120 cat >expect <<-EOF &&
121 remote: # pre-receive hook
122 remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
123 remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
124 remote: # proc-receive hook
125 remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
126 remote: # post-receive hook
127 remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
128 To <URL/of/upstream.git>
129 * [new branch] HEAD -> next
130 ! [remote rejected] HEAD -> refs/for/main/topic (proc-receive failed to report status)
132 test_cmp expect actual &&
133 git -C "$upstream" show-ref >out &&
134 make_user_friendly_and_stable_output <out >actual &&
135 cat >expect <<-EOF &&
136 <COMMIT-A> refs/heads/main
137 <COMMIT-A> refs/heads/next
139 test_cmp expect actual
142 # Refs of upstream : main(A) next(A)
143 # Refs of workbench: main(A) tags/v123
144 test_expect_success "cleanup ($PROTOCOL)" '
145 git -C "$upstream" update-ref -d refs/heads/next
149 test_expect_success "setup proc-receive hook (no ref, $PROTOCOL)" '
150 write_script "$upstream/hooks/proc-receive" <<-EOF
151 printf >&2 "# proc-receive hook\n"
152 test-tool proc-receive -v \
157 # Refs of upstream : main(A)
158 # Refs of workbench: main(A) tags/v123
159 # git push : refs/for/main/topic
160 test_expect_success "proc-receive: bad protocol (no ref, $PROTOCOL)" '
161 test_must_fail git -C workbench push origin \
162 HEAD:refs/for/main/topic\
164 make_user_friendly_and_stable_output <out >actual &&
165 cat >expect <<-EOF &&
166 remote: # pre-receive hook
167 remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
168 remote: # proc-receive hook
169 remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
170 remote: proc-receive> ok
171 remote: error: proc-receive reported incomplete status line: "ok"
172 To <URL/of/upstream.git>
173 ! [remote rejected] HEAD -> refs/for/main/topic (proc-receive failed to report status)
175 test_cmp expect actual &&
176 git -C "$upstream" show-ref >out &&
177 make_user_friendly_and_stable_output <out >actual &&
178 cat >expect <<-EOF &&
179 <COMMIT-A> refs/heads/main
181 test_cmp expect actual
184 test_expect_success "setup proc-receive hook (unknown status, $PROTOCOL)" '
185 write_script "$upstream/hooks/proc-receive" <<-EOF
186 printf >&2 "# proc-receive hook\n"
187 test-tool proc-receive -v \
188 -r "xx refs/for/main/topic"
192 # Refs of upstream : main(A)
193 # Refs of workbench: main(A) tags/v123
194 # git push : refs/for/main/topic
195 test_expect_success "proc-receive: bad protocol (unknown status, $PROTOCOL)" '
196 test_must_fail git -C workbench push origin \
197 HEAD:refs/for/main/topic \
199 make_user_friendly_and_stable_output <out >actual &&
200 cat >expect <<-EOF &&
201 remote: # pre-receive hook
202 remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
203 remote: # proc-receive hook
204 remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
205 remote: proc-receive> xx refs/for/main/topic
206 remote: error: proc-receive reported bad status "xx" on ref "refs/for/main/topic"
207 To <URL/of/upstream.git>
208 ! [remote rejected] HEAD -> refs/for/main/topic (proc-receive failed to report status)
210 test_cmp expect actual &&
211 git -C "$upstream" show-ref >out &&
212 make_user_friendly_and_stable_output <out >actual &&
213 cat >expect <<-EOF &&
214 <COMMIT-A> refs/heads/main
216 test_cmp expect actual