1 test_expect_success "setup proc-receive hook (unknown version, $PROTOCOL/porcelain)" '
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/porcelain)" '
12 test_must_fail git -C workbench push --porcelain 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; n; p; }" \
20 <actual >actual-report &&
22 To <URL/of/upstream.git>
23 ! HEAD:refs/for/main/topic [remote rejected] (fail to run proc-receive hook)
26 test_cmp expect actual-report &&
28 # Check error message from "receive-pack", but ignore unstable fatal error
29 # message ("remote: fatal: the remote end hung up unexpectedly") which
30 # is different from the remote HTTP server with different locale settings.
31 grep "^remote: error:" <actual >actual-error &&
33 remote: error: proc-receive version "2" is not supported
35 test_cmp expect actual-error &&
37 git -C "$upstream" show-ref >out &&
38 make_user_friendly_and_stable_output <out >actual &&
40 <COMMIT-A> refs/heads/main
42 test_cmp expect actual
45 test_expect_success "setup proc-receive hook (hook --die-read-version, $PROTOCOL/porcelain)" '
46 write_script "$upstream/hooks/proc-receive" <<-EOF
47 printf >&2 "# proc-receive hook\n"
48 test-tool proc-receive -v --die-read-version
52 # Refs of upstream : main(A)
53 # Refs of workbench: main(A) tags/v123
54 # git push : refs/for/main/topic(A)
55 test_expect_success "proc-receive: bad protocol (hook --die-read-version, $PROTOCOL/porcelain)" '
56 test_must_fail git -C workbench push --porcelain origin \
57 HEAD:refs/for/main/topic \
59 filter_out_user_friendly_and_stable_output \
60 -e "/^To / { p; n; p; n; p; }" \
63 To <URL/of/upstream.git>
64 ! HEAD:refs/for/main/topic [remote rejected] (fail to run proc-receive hook)
67 test_cmp expect actual &&
68 grep "remote: fatal: die with the --die-read-version option" out &&
69 grep "remote: error: fail to negotiate version with proc-receive hook" out &&
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-write-version, $PROTOCOL/porcelain)" '
80 write_script "$upstream/hooks/proc-receive" <<-EOF
81 printf >&2 "# proc-receive hook\n"
82 test-tool proc-receive -v --die-write-version
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-write-version, $PROTOCOL/porcelain)" '
90 test_must_fail git -C workbench push --porcelain origin \
91 HEAD:refs/for/main/topic \
93 filter_out_user_friendly_and_stable_output \
94 -e "/^To / { p; n; p; n; p; }" \
97 To <URL/of/upstream.git>
98 ! HEAD:refs/for/main/topic [remote rejected] (fail to run proc-receive hook)
101 test_cmp expect actual &&
102 grep "remote: fatal: die with the --die-write-version option" out &&
103 grep "remote: error: fail to negotiate version with proc-receive hook" out &&
105 git -C "$upstream" show-ref >out &&
106 make_user_friendly_and_stable_output <out >actual &&
107 cat >expect <<-EOF &&
108 <COMMIT-A> refs/heads/main
110 test_cmp expect actual
113 test_expect_success "setup proc-receive hook (hook --die-read-commands, $PROTOCOL/porcelain)" '
114 write_script "$upstream/hooks/proc-receive" <<-EOF
115 printf >&2 "# proc-receive hook\n"
116 test-tool proc-receive -v --die-read-commands
120 # Refs of upstream : main(A)
121 # Refs of workbench: main(A) tags/v123
122 # git push : refs/for/main/topic(A)
123 test_expect_success "proc-receive: bad protocol (hook --die-read-commands, $PROTOCOL/porcelain)" '
124 test_must_fail git -C workbench push --porcelain origin \
125 HEAD:refs/for/main/topic \
127 filter_out_user_friendly_and_stable_output \
128 -e "/^To / { p; n; p; n; p; }" \
130 cat >expect <<-EOF &&
131 To <URL/of/upstream.git>
132 ! HEAD:refs/for/main/topic [remote rejected] (fail to run proc-receive hook)
135 test_cmp expect actual &&
136 grep "remote: fatal: die with the --die-read-commands option" out &&
138 git -C "$upstream" show-ref >out &&
139 make_user_friendly_and_stable_output <out >actual &&
140 cat >expect <<-EOF &&
141 <COMMIT-A> refs/heads/main
143 test_cmp expect actual
146 test_expect_success "setup proc-receive hook (hook --die-read-push-options, $PROTOCOL/porcelain)" '
147 write_script "$upstream/hooks/proc-receive" <<-EOF
148 printf >&2 "# proc-receive hook\n"
149 test-tool proc-receive -v --die-read-push-options
153 # Refs of upstream : main(A)
154 # Refs of workbench: main(A) tags/v123
155 # git push : refs/for/main/topic(A)
156 test_expect_success "proc-receive: bad protocol (hook --die-read-push-options, $PROTOCOL/porcelain)" '
157 git -C "$upstream" config receive.advertisePushOptions true &&
158 test_must_fail git -C workbench push --porcelain origin \
159 -o reviewers=user1,user2 \
160 HEAD:refs/for/main/topic \
162 filter_out_user_friendly_and_stable_output \
163 -e "/^To / { p; n; p; n; p; }" \
165 cat >expect <<-EOF &&
166 To <URL/of/upstream.git>
167 ! HEAD:refs/for/main/topic [remote rejected] (fail to run proc-receive hook)
170 test_cmp expect actual &&
171 grep "remote: fatal: die with the --die-read-push-options option" out &&
173 git -C "$upstream" show-ref >out &&
174 make_user_friendly_and_stable_output <out >actual &&
175 cat >expect <<-EOF &&
176 <COMMIT-A> refs/heads/main
178 test_cmp expect actual
181 test_expect_success "setup proc-receive hook (hook --die-write-report, $PROTOCOL/porcelain)" '
182 write_script "$upstream/hooks/proc-receive" <<-EOF
183 printf >&2 "# proc-receive hook\n"
184 test-tool proc-receive -v --die-write-report
188 # Refs of upstream : main(A)
189 # Refs of workbench: main(A) tags/v123
190 # git push : refs/for/main/topic(A)
191 test_expect_success "proc-receive: bad protocol (hook --die-write-report, $PROTOCOL/porcelain)" '
192 test_must_fail git -C workbench push --porcelain origin \
193 HEAD:refs/for/main/topic \
195 filter_out_user_friendly_and_stable_output \
196 -e "/^To / { p; n; p; n; p; }" \
198 cat >expect <<-EOF &&
199 To <URL/of/upstream.git>
200 ! HEAD:refs/for/main/topic [remote rejected] (fail to run proc-receive hook)
203 test_cmp expect actual &&
204 grep "remote: fatal: die with the --die-write-report option" out &&
206 git -C "$upstream" show-ref >out &&
207 make_user_friendly_and_stable_output <out >actual &&
208 cat >expect <<-EOF &&
209 <COMMIT-A> refs/heads/main
211 test_cmp expect actual
214 test_expect_success "setup proc-receive hook (no report, $PROTOCOL/porcelain)" '
215 write_script "$upstream/hooks/proc-receive" <<-EOF
216 printf >&2 "# proc-receive hook\n"
217 test-tool proc-receive -v
221 # Refs of upstream : main(A)
222 # Refs of workbench: main(A) tags/v123
223 # git push : next(A) refs/for/main/topic(A)
224 test_expect_success "proc-receive: bad protocol (no report, $PROTOCOL/porcelain)" '
225 test_must_fail git -C workbench push --porcelain origin \
226 HEAD:refs/heads/next \
227 HEAD:refs/for/main/topic >out 2>&1 &&
228 make_user_friendly_and_stable_output <out >actual &&
229 cat >expect <<-EOF &&
230 remote: # pre-receive hook
231 remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
232 remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
233 remote: # proc-receive hook
234 remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
235 remote: # post-receive hook
236 remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
237 To <URL/of/upstream.git>
238 * HEAD:refs/heads/next [new branch]
239 ! HEAD:refs/for/main/topic [remote rejected] (proc-receive failed to report status)
242 test_cmp expect actual &&
244 git -C "$upstream" show-ref >out &&
245 make_user_friendly_and_stable_output <out >actual &&
246 cat >expect <<-EOF &&
247 <COMMIT-A> refs/heads/main
248 <COMMIT-A> refs/heads/next
250 test_cmp expect actual
253 # Refs of upstream : main(A) next(A)
254 # Refs of workbench: main(A) tags/v123
255 test_expect_success "cleanup ($PROTOCOL/porcelain)" '
256 git -C "$upstream" update-ref -d refs/heads/next
259 test_expect_success "setup proc-receive hook (no ref, $PROTOCOL/porcelain)" '
260 write_script "$upstream/hooks/proc-receive" <<-EOF
261 printf >&2 "# proc-receive hook\n"
262 test-tool proc-receive -v \
267 # Refs of upstream : main(A)
268 # Refs of workbench: main(A) tags/v123
269 # git push : refs/for/main/topic
270 test_expect_success "proc-receive: bad protocol (no ref, $PROTOCOL/porcelain)" '
271 test_must_fail git -C workbench push --porcelain origin \
272 HEAD:refs/for/main/topic\
274 make_user_friendly_and_stable_output <out >actual &&
275 cat >expect <<-EOF &&
276 remote: # pre-receive hook
277 remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
278 remote: # proc-receive hook
279 remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
280 remote: proc-receive> ok
281 remote: error: proc-receive reported incomplete status line: "ok"
282 To <URL/of/upstream.git>
283 ! HEAD:refs/for/main/topic [remote rejected] (proc-receive failed to report status)
286 test_cmp expect actual &&
288 git -C "$upstream" show-ref >out &&
289 make_user_friendly_and_stable_output <out >actual &&
290 cat >expect <<-EOF &&
291 <COMMIT-A> refs/heads/main
293 test_cmp expect actual
296 test_expect_success "setup proc-receive hook (unknown status, $PROTOCOL/porcelain)" '
297 write_script "$upstream/hooks/proc-receive" <<-EOF
298 printf >&2 "# proc-receive hook\n"
299 test-tool proc-receive -v \
300 -r "xx refs/for/main/topic"
304 # Refs of upstream : main(A)
305 # Refs of workbench: main(A) tags/v123
306 # git push : refs/for/main/topic
307 test_expect_success "proc-receive: bad protocol (unknown status, $PROTOCOL/porcelain)" '
308 test_must_fail git -C workbench push --porcelain origin \
309 HEAD:refs/for/main/topic \
311 make_user_friendly_and_stable_output <out >actual &&
312 cat >expect <<-EOF &&
313 remote: # pre-receive hook
314 remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
315 remote: # proc-receive hook
316 remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
317 remote: proc-receive> xx refs/for/main/topic
318 remote: error: proc-receive reported bad status "xx" on ref "refs/for/main/topic"
319 To <URL/of/upstream.git>
320 ! HEAD:refs/for/main/topic [remote rejected] (proc-receive failed to report status)
323 test_cmp expect actual &&
325 git -C "$upstream" show-ref >out &&
326 make_user_friendly_and_stable_output <out >actual &&
327 cat >expect <<-EOF &&
328 <COMMIT-A> refs/heads/main
330 test_cmp expect actual