]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5411/test-0013-bad-protocol.sh
Merge branch 'jc/do-not-just-explain-but-update-your-patch'
[thirdparty/git.git] / t / t5411 / test-0013-bad-protocol.sh
CommitLineData
15d3af5e
JX
1test_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
5 EOF
6'
7
a9568dba
JS
8# Refs of upstream : main(A)
9# Refs of workbench: main(A) tags/v123
10# git push : refs/for/main/topic(A)
15d3af5e
JX
11test_expect_success "proc-receive: bad protocol (unknown version, $PROTOCOL)" '
12 test_must_fail git -C workbench push origin \
a9568dba 13 HEAD:refs/for/main/topic \
15d3af5e
JX
14 >out 2>&1 &&
15 make_user_friendly_and_stable_output <out >actual &&
16
17 # Check status report for git-push
18 sed -n \
f65003b4
JX
19 -e "/^To / { p; }" \
20 -e "/^ ! / { p; }" \
15d3af5e
JX
21 <actual >actual-report &&
22 cat >expect <<-EOF &&
23 To <URL/of/upstream.git>
a9568dba 24 ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook)
15d3af5e
JX
25 EOF
26 test_cmp expect actual-report &&
27
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 &&
32 cat >expect <<-EOF &&
33 remote: error: proc-receive version "2" is not supported
34 EOF
35 test_cmp expect actual-error &&
36
37 git -C "$upstream" show-ref >out &&
38 make_user_friendly_and_stable_output <out >actual &&
39 cat >expect <<-EOF &&
a9568dba 40 <COMMIT-A> refs/heads/main
15d3af5e
JX
41 EOF
42 test_cmp expect actual
43'
44
f65003b4 45test_expect_success "setup proc-receive hook (hook --die-read-version, $PROTOCOL)" '
15d3af5e
JX
46 write_script "$upstream/hooks/proc-receive" <<-EOF
47 printf >&2 "# proc-receive hook\n"
f65003b4 48 test-tool proc-receive -v --die-read-version
15d3af5e
JX
49 EOF
50'
51
a9568dba
JS
52# Refs of upstream : main(A)
53# Refs of workbench: main(A) tags/v123
54# git push : refs/for/main/topic(A)
f65003b4 55test_expect_success "proc-receive: bad protocol (hook --die-read-version, $PROTOCOL)" '
15d3af5e 56 test_must_fail git -C workbench push origin \
a9568dba 57 HEAD:refs/for/main/topic \
15d3af5e 58 >out 2>&1 &&
f65003b4
JX
59 filter_out_user_friendly_and_stable_output \
60 -e "/^To / { p; }" \
61 -e "/^ ! / { p; }" \
62 <out >actual &&
63 cat >expect <<-EOF &&
64 To <URL/of/upstream.git>
65 ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook)
66 EOF
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 &&
70
71 git -C "$upstream" show-ref >out &&
15d3af5e 72 make_user_friendly_and_stable_output <out >actual &&
f65003b4
JX
73 cat >expect <<-EOF &&
74 <COMMIT-A> refs/heads/main
75 EOF
76 test_cmp expect actual
77'
78
79test_expect_success "setup proc-receive hook (hook --die-write-version, $PROTOCOL)" '
80 write_script "$upstream/hooks/proc-receive" <<-EOF
81 printf >&2 "# proc-receive hook\n"
82 test-tool proc-receive -v --die-write-version
83 EOF
84'
15d3af5e 85
f65003b4
JX
86# Refs of upstream : main(A)
87# Refs of workbench: main(A) tags/v123
88# git push : refs/for/main/topic(A)
89test_expect_success "proc-receive: bad protocol (hook --die-write-version, $PROTOCOL)" '
90 test_must_fail git -C workbench push origin \
91 HEAD:refs/for/main/topic \
92 >out 2>&1 &&
93 filter_out_user_friendly_and_stable_output \
94 -e "/^To / { p; }" \
95 -e "/^ ! / { p; }" \
96 <out >actual &&
97 cat >expect <<-EOF &&
98 To <URL/of/upstream.git>
99 ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook)
100 EOF
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 &&
104
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
109 EOF
110 test_cmp expect actual
111'
112
113test_expect_success "setup proc-receive hook (hook --die-read-commands, $PROTOCOL)" '
114 write_script "$upstream/hooks/proc-receive" <<-EOF
115 printf >&2 "# proc-receive hook\n"
116 test-tool proc-receive -v --die-read-commands
117 EOF
118'
119
120# Refs of upstream : main(A)
121# Refs of workbench: main(A) tags/v123
122# git push : refs/for/main/topic(A)
123test_expect_success "proc-receive: bad protocol (hook --die-read-commands, $PROTOCOL)" '
124 test_must_fail git -C workbench push origin \
125 HEAD:refs/for/main/topic \
126 >out 2>&1 &&
127 filter_out_user_friendly_and_stable_output \
128 -e "/^To / { p; }" \
129 -e "/^ ! / { p; }" \
130 <out >actual &&
15d3af5e 131 cat >expect <<-EOF &&
15d3af5e 132 To <URL/of/upstream.git>
a9568dba 133 ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook)
15d3af5e
JX
134 EOF
135 test_cmp expect actual &&
f65003b4 136 grep "remote: fatal: die with the --die-read-commands option" out &&
15d3af5e
JX
137
138 git -C "$upstream" show-ref >out &&
139 make_user_friendly_and_stable_output <out >actual &&
140 cat >expect <<-EOF &&
a9568dba 141 <COMMIT-A> refs/heads/main
15d3af5e
JX
142 EOF
143 test_cmp expect actual
144'
145
f65003b4 146test_expect_success "setup proc-receive hook (hook --die-read-push-options, $PROTOCOL)" '
15d3af5e
JX
147 write_script "$upstream/hooks/proc-receive" <<-EOF
148 printf >&2 "# proc-receive hook\n"
f65003b4 149 test-tool proc-receive -v --die-read-push-options
15d3af5e
JX
150 EOF
151'
152
a9568dba
JS
153# Refs of upstream : main(A)
154# Refs of workbench: main(A) tags/v123
155# git push : refs/for/main/topic(A)
f65003b4
JX
156test_expect_success "proc-receive: bad protocol (hook --die-read-push-options, $PROTOCOL)" '
157 git -C "$upstream" config receive.advertisePushOptions true &&
15d3af5e 158 test_must_fail git -C workbench push origin \
f65003b4 159 -o reviewers=user1,user2 \
a9568dba 160 HEAD:refs/for/main/topic \
15d3af5e 161 >out 2>&1 &&
f65003b4
JX
162 filter_out_user_friendly_and_stable_output \
163 -e "/^To / { p; }" \
164 -e "/^ ! / { p; }" \
165 <out >actual &&
166 cat >expect <<-EOF &&
167 To <URL/of/upstream.git>
168 ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook)
169 EOF
170 test_cmp expect actual &&
171 grep "remote: fatal: die with the --die-read-push-options option" out &&
172
173 git -C "$upstream" show-ref >out &&
15d3af5e 174 make_user_friendly_and_stable_output <out >actual &&
f65003b4
JX
175 cat >expect <<-EOF &&
176 <COMMIT-A> refs/heads/main
177 EOF
178 test_cmp expect actual
179'
180
181test_expect_success "setup proc-receive hook (hook --die-write-report, $PROTOCOL)" '
182 write_script "$upstream/hooks/proc-receive" <<-EOF
183 printf >&2 "# proc-receive hook\n"
184 test-tool proc-receive -v --die-write-report
185 EOF
186'
15d3af5e 187
f65003b4
JX
188# Refs of upstream : main(A)
189# Refs of workbench: main(A) tags/v123
190# git push : refs/for/main/topic(A)
191test_expect_success "proc-receive: bad protocol (hook --die-write-report, $PROTOCOL)" '
192 test_must_fail git -C workbench push origin \
193 HEAD:refs/for/main/topic \
194 >out 2>&1 &&
195 filter_out_user_friendly_and_stable_output \
196 -e "/^To / { p; }" \
197 -e "/^ ! / { p; }" \
198 <out >actual &&
199 cat >expect <<-EOF &&
200 To <URL/of/upstream.git>
201 ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook)
202 EOF
203 test_cmp expect actual &&
204 grep "remote: fatal: die with the --die-write-report option" out &&
15d3af5e
JX
205
206 git -C "$upstream" show-ref >out &&
207 make_user_friendly_and_stable_output <out >actual &&
208 cat >expect <<-EOF &&
a9568dba 209 <COMMIT-A> refs/heads/main
15d3af5e
JX
210 EOF
211 test_cmp expect actual
212'
213
214test_expect_success "setup proc-receive hook (no report, $PROTOCOL)" '
215 write_script "$upstream/hooks/proc-receive" <<-EOF
216 printf >&2 "# proc-receive hook\n"
217 test-tool proc-receive -v
218 EOF
219'
220
a9568dba
JS
221# Refs of upstream : main(A)
222# Refs of workbench: main(A) tags/v123
223# git push : next(A) refs/for/main/topic(A)
15d3af5e
JX
224test_expect_success "proc-receive: bad protocol (no report, $PROTOCOL)" '
225 test_must_fail git -C workbench push origin \
226 HEAD:refs/heads/next \
a9568dba 227 HEAD:refs/for/main/topic >out 2>&1 &&
15d3af5e
JX
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
a9568dba 232 remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
15d3af5e 233 remote: # proc-receive hook
a9568dba 234 remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
15d3af5e
JX
235 remote: # post-receive hook
236 remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
237 To <URL/of/upstream.git>
238 * [new branch] HEAD -> next
a9568dba 239 ! [remote rejected] HEAD -> refs/for/main/topic (proc-receive failed to report status)
15d3af5e
JX
240 EOF
241 test_cmp expect actual &&
f65003b4 242
15d3af5e
JX
243 git -C "$upstream" show-ref >out &&
244 make_user_friendly_and_stable_output <out >actual &&
245 cat >expect <<-EOF &&
a9568dba 246 <COMMIT-A> refs/heads/main
15d3af5e
JX
247 <COMMIT-A> refs/heads/next
248 EOF
249 test_cmp expect actual
250'
251
a9568dba
JS
252# Refs of upstream : main(A) next(A)
253# Refs of workbench: main(A) tags/v123
15d3af5e
JX
254test_expect_success "cleanup ($PROTOCOL)" '
255 git -C "$upstream" update-ref -d refs/heads/next
256
257'
258
259test_expect_success "setup proc-receive hook (no ref, $PROTOCOL)" '
260 write_script "$upstream/hooks/proc-receive" <<-EOF
261 printf >&2 "# proc-receive hook\n"
262 test-tool proc-receive -v \
263 -r "ok"
264 EOF
265'
266
a9568dba
JS
267# Refs of upstream : main(A)
268# Refs of workbench: main(A) tags/v123
269# git push : refs/for/main/topic
15d3af5e
JX
270test_expect_success "proc-receive: bad protocol (no ref, $PROTOCOL)" '
271 test_must_fail git -C workbench push origin \
a9568dba 272 HEAD:refs/for/main/topic\
15d3af5e
JX
273 >out 2>&1 &&
274 make_user_friendly_and_stable_output <out >actual &&
275 cat >expect <<-EOF &&
276 remote: # pre-receive hook
a9568dba 277 remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
15d3af5e 278 remote: # proc-receive hook
a9568dba 279 remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
15d3af5e
JX
280 remote: proc-receive> ok
281 remote: error: proc-receive reported incomplete status line: "ok"
282 To <URL/of/upstream.git>
a9568dba 283 ! [remote rejected] HEAD -> refs/for/main/topic (proc-receive failed to report status)
15d3af5e
JX
284 EOF
285 test_cmp expect actual &&
f65003b4 286
15d3af5e
JX
287 git -C "$upstream" show-ref >out &&
288 make_user_friendly_and_stable_output <out >actual &&
289 cat >expect <<-EOF &&
a9568dba 290 <COMMIT-A> refs/heads/main
15d3af5e
JX
291 EOF
292 test_cmp expect actual
293'
294
295test_expect_success "setup proc-receive hook (unknown status, $PROTOCOL)" '
296 write_script "$upstream/hooks/proc-receive" <<-EOF
297 printf >&2 "# proc-receive hook\n"
298 test-tool proc-receive -v \
a9568dba 299 -r "xx refs/for/main/topic"
15d3af5e
JX
300 EOF
301'
302
a9568dba
JS
303# Refs of upstream : main(A)
304# Refs of workbench: main(A) tags/v123
305# git push : refs/for/main/topic
15d3af5e
JX
306test_expect_success "proc-receive: bad protocol (unknown status, $PROTOCOL)" '
307 test_must_fail git -C workbench push origin \
a9568dba 308 HEAD:refs/for/main/topic \
15d3af5e
JX
309 >out 2>&1 &&
310 make_user_friendly_and_stable_output <out >actual &&
311 cat >expect <<-EOF &&
312 remote: # pre-receive hook
a9568dba 313 remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
15d3af5e 314 remote: # proc-receive hook
a9568dba
JS
315 remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
316 remote: proc-receive> xx refs/for/main/topic
317 remote: error: proc-receive reported bad status "xx" on ref "refs/for/main/topic"
15d3af5e 318 To <URL/of/upstream.git>
a9568dba 319 ! [remote rejected] HEAD -> refs/for/main/topic (proc-receive failed to report status)
15d3af5e
JX
320 EOF
321 test_cmp expect actual &&
f65003b4 322
15d3af5e
JX
323 git -C "$upstream" show-ref >out &&
324 make_user_friendly_and_stable_output <out >actual &&
325 cat >expect <<-EOF &&
a9568dba 326 <COMMIT-A> refs/heads/main
15d3af5e
JX
327 EOF
328 test_cmp expect actual
329'