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