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 \
14 >out-$test_count 2>&1 &&
15 make_user_friendly_and_stable_output <out-$test_count >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 test_cmp_refs -C "$upstream" <<-EOF
38 <COMMIT-A> refs/heads/main
42 test_expect_success
"setup proc-receive hook (hook --die-read-version, $PROTOCOL/porcelain)" '
43 write_script "$upstream/hooks/proc-receive" <<-EOF
44 printf >&2 "# proc-receive hook\n"
45 test-tool proc-receive -v --die-read-version
49 # Refs of upstream : main(A)
50 # Refs of workbench: main(A) tags/v123
51 # git push : refs/for/main/topic(A)
52 test_expect_success
"proc-receive: bad protocol (hook --die-read-version, $PROTOCOL/porcelain)" '
53 test_must_fail git -C workbench push --porcelain origin \
54 HEAD:refs/for/main/topic \
55 >out-$test_count 2>&1 &&
56 filter_out_user_friendly_and_stable_output \
57 -e "/^To / { p; n; p; n; p; }" \
58 <out-$test_count >actual &&
60 To <URL/of/upstream.git>
61 ! HEAD:refs/for/main/topic [remote rejected] (fail to run proc-receive hook)
64 test_cmp expect actual &&
65 grep "remote: fatal: die with the --die-read-version option" out-$test_count &&
66 grep "remote: error: fail to negotiate version with proc-receive hook" out-$test_count &&
68 test_cmp_refs -C "$upstream" <<-EOF
69 <COMMIT-A> refs/heads/main
73 test_expect_success
"setup proc-receive hook (hook --die-write-version, $PROTOCOL/porcelain)" '
74 write_script "$upstream/hooks/proc-receive" <<-EOF
75 printf >&2 "# proc-receive hook\n"
76 test-tool proc-receive -v --die-write-version
80 # Refs of upstream : main(A)
81 # Refs of workbench: main(A) tags/v123
82 # git push : refs/for/main/topic(A)
83 test_expect_success
"proc-receive: bad protocol (hook --die-write-version, $PROTOCOL/porcelain)" '
84 test_must_fail git -C workbench push --porcelain origin \
85 HEAD:refs/for/main/topic \
86 >out-$test_count 2>&1 &&
87 filter_out_user_friendly_and_stable_output \
88 -e "/^To / { p; n; p; n; p; }" \
89 <out-$test_count >actual &&
91 To <URL/of/upstream.git>
92 ! HEAD:refs/for/main/topic [remote rejected] (fail to run proc-receive hook)
95 test_cmp expect actual &&
96 grep "remote: fatal: die with the --die-write-version option" out-$test_count &&
97 grep "remote: error: fail to negotiate version with proc-receive hook" out-$test_count &&
99 test_cmp_refs -C "$upstream" <<-EOF
100 <COMMIT-A> refs/heads/main
104 test_expect_success
"setup proc-receive hook (hook --die-read-commands, $PROTOCOL/porcelain)" '
105 write_script "$upstream/hooks/proc-receive" <<-EOF
106 printf >&2 "# proc-receive hook\n"
107 test-tool proc-receive -v --die-read-commands
111 # Refs of upstream : main(A)
112 # Refs of workbench: main(A) tags/v123
113 # git push : refs/for/main/topic(A)
114 test_expect_success
"proc-receive: bad protocol (hook --die-read-commands, $PROTOCOL/porcelain)" '
115 test_must_fail git -C workbench push --porcelain origin \
116 HEAD:refs/for/main/topic \
117 >out-$test_count 2>&1 &&
118 filter_out_user_friendly_and_stable_output \
119 -e "/^To / { p; n; p; n; p; }" \
120 <out-$test_count >actual &&
121 cat >expect <<-EOF &&
122 To <URL/of/upstream.git>
123 ! HEAD:refs/for/main/topic [remote rejected] (fail to run proc-receive hook)
126 test_cmp expect actual &&
127 grep "remote: fatal: die with the --die-read-commands option" out-$test_count &&
129 test_cmp_refs -C "$upstream" <<-EOF
130 <COMMIT-A> refs/heads/main
134 test_expect_success
"setup proc-receive hook (hook --die-read-push-options, $PROTOCOL/porcelain)" '
135 write_script "$upstream/hooks/proc-receive" <<-EOF
136 printf >&2 "# proc-receive hook\n"
137 test-tool proc-receive -v --die-read-push-options
141 # Refs of upstream : main(A)
142 # Refs of workbench: main(A) tags/v123
143 # git push : refs/for/main/topic(A)
144 test_expect_success
"proc-receive: bad protocol (hook --die-read-push-options, $PROTOCOL/porcelain)" '
145 git -C "$upstream" config receive.advertisePushOptions true &&
146 test_must_fail git -C workbench push --porcelain origin \
147 -o reviewers=user1,user2 \
148 HEAD:refs/for/main/topic \
149 >out-$test_count 2>&1 &&
150 filter_out_user_friendly_and_stable_output \
151 -e "/^To / { p; n; p; n; p; }" \
152 <out-$test_count >actual &&
153 cat >expect <<-EOF &&
154 To <URL/of/upstream.git>
155 ! HEAD:refs/for/main/topic [remote rejected] (fail to run proc-receive hook)
158 test_cmp expect actual &&
159 grep "remote: fatal: die with the --die-read-push-options option" out-$test_count &&
161 test_cmp_refs -C "$upstream" <<-EOF
162 <COMMIT-A> refs/heads/main
166 test_expect_success
"setup proc-receive hook (hook --die-write-report, $PROTOCOL/porcelain)" '
167 write_script "$upstream/hooks/proc-receive" <<-EOF
168 printf >&2 "# proc-receive hook\n"
169 test-tool proc-receive -v --die-write-report
173 # Refs of upstream : main(A)
174 # Refs of workbench: main(A) tags/v123
175 # git push : refs/for/main/topic(A)
176 test_expect_success
"proc-receive: bad protocol (hook --die-write-report, $PROTOCOL/porcelain)" '
177 test_must_fail git -C workbench push --porcelain origin \
178 HEAD:refs/for/main/topic \
179 >out-$test_count 2>&1 &&
180 filter_out_user_friendly_and_stable_output \
181 -e "/^To / { p; n; p; n; p; }" \
182 <out-$test_count >actual &&
183 cat >expect <<-EOF &&
184 To <URL/of/upstream.git>
185 ! HEAD:refs/for/main/topic [remote rejected] (fail to run proc-receive hook)
188 test_cmp expect actual &&
189 grep "remote: fatal: die with the --die-write-report option" out-$test_count &&
191 test_cmp_refs -C "$upstream" <<-EOF
192 <COMMIT-A> refs/heads/main
196 test_expect_success
"setup proc-receive hook (no report, $PROTOCOL/porcelain)" '
197 write_script "$upstream/hooks/proc-receive" <<-EOF
198 printf >&2 "# proc-receive hook\n"
199 test-tool proc-receive -v
203 # Refs of upstream : main(A)
204 # Refs of workbench: main(A) tags/v123
205 # git push : next(A) refs/for/main/topic(A)
206 test_expect_success
"proc-receive: bad protocol (no report, $PROTOCOL/porcelain)" '
207 test_must_fail git -C workbench push --porcelain origin \
208 HEAD:refs/heads/next \
209 HEAD:refs/for/main/topic >out-$test_count 2>&1 &&
210 make_user_friendly_and_stable_output <out-$test_count >actual &&
211 cat >expect <<-EOF &&
212 remote: # pre-receive hook
213 remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
214 remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
215 remote: # proc-receive hook
216 remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
217 remote: # post-receive hook
218 remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
219 To <URL/of/upstream.git>
220 * HEAD:refs/heads/next [new branch]
221 ! HEAD:refs/for/main/topic [remote rejected] (proc-receive failed to report status)
224 test_cmp expect actual &&
226 test_cmp_refs -C "$upstream" <<-EOF
227 <COMMIT-A> refs/heads/main
228 <COMMIT-A> refs/heads/next
232 # Refs of upstream : main(A) next(A)
233 # Refs of workbench: main(A) tags/v123
234 test_expect_success
"cleanup ($PROTOCOL/porcelain)" '
235 git -C "$upstream" update-ref -d refs/heads/next
238 test_expect_success
"setup proc-receive hook (no ref, $PROTOCOL/porcelain)" '
239 write_script "$upstream/hooks/proc-receive" <<-EOF
240 printf >&2 "# proc-receive hook\n"
241 test-tool proc-receive -v \
246 # Refs of upstream : main(A)
247 # Refs of workbench: main(A) tags/v123
248 # git push : refs/for/main/topic
249 test_expect_success
"proc-receive: bad protocol (no ref, $PROTOCOL/porcelain)" '
250 test_must_fail git -C workbench push --porcelain origin \
251 HEAD:refs/for/main/topic\
252 >out-$test_count 2>&1 &&
253 make_user_friendly_and_stable_output <out-$test_count >actual &&
254 cat >expect <<-EOF &&
255 remote: # pre-receive hook
256 remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
257 remote: # proc-receive hook
258 remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
259 remote: proc-receive> ok
260 remote: error: proc-receive reported incomplete status line: "ok"
261 To <URL/of/upstream.git>
262 ! HEAD:refs/for/main/topic [remote rejected] (proc-receive failed to report status)
265 test_cmp expect actual &&
267 test_cmp_refs -C "$upstream" <<-EOF
268 <COMMIT-A> refs/heads/main
272 test_expect_success
"setup proc-receive hook (unknown status, $PROTOCOL/porcelain)" '
273 write_script "$upstream/hooks/proc-receive" <<-EOF
274 printf >&2 "# proc-receive hook\n"
275 test-tool proc-receive -v \
276 -r "xx refs/for/main/topic"
280 # Refs of upstream : main(A)
281 # Refs of workbench: main(A) tags/v123
282 # git push : refs/for/main/topic
283 test_expect_success
"proc-receive: bad protocol (unknown status, $PROTOCOL/porcelain)" '
284 test_must_fail git -C workbench push --porcelain origin \
285 HEAD:refs/for/main/topic \
286 >out-$test_count 2>&1 &&
287 make_user_friendly_and_stable_output <out-$test_count >actual &&
288 cat >expect <<-EOF &&
289 remote: # pre-receive hook
290 remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
291 remote: # proc-receive hook
292 remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
293 remote: proc-receive> xx refs/for/main/topic
294 remote: error: proc-receive reported bad status "xx" on ref "refs/for/main/topic"
295 To <URL/of/upstream.git>
296 ! HEAD:refs/for/main/topic [remote rejected] (proc-receive failed to report status)
299 test_cmp expect actual &&
301 test_cmp_refs -C "$upstream" <<-EOF
302 <COMMIT-A> refs/heads/main