]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5411/test-0013-bad-protocol.sh
t5411: new helper filter_out_user_friendly_and_stable_output
[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 \
19 -e "/^To / { p; n; p; }" \
20 <actual >actual-report &&
21 cat >expect <<-EOF &&
22 To <URL/of/upstream.git>
a9568dba 23 ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook)
15d3af5e
JX
24 EOF
25 test_cmp expect actual-report &&
26
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 &&
31 cat >expect <<-EOF &&
32 remote: error: proc-receive version "2" is not supported
33 EOF
34 test_cmp expect actual-error &&
35
36 git -C "$upstream" show-ref >out &&
37 make_user_friendly_and_stable_output <out >actual &&
38 cat >expect <<-EOF &&
a9568dba 39 <COMMIT-A> refs/heads/main
15d3af5e
JX
40 EOF
41 test_cmp expect actual
42'
43
44test_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
48 EOF
49'
50
a9568dba
JS
51# Refs of upstream : main(A)
52# Refs of workbench: main(A) tags/v123
53# git push : refs/for/main/topic(A)
15d3af5e
JX
54test_expect_success "proc-receive: bad protocol (hook --die-version, $PROTOCOL)" '
55 test_must_fail git -C workbench push origin \
a9568dba 56 HEAD:refs/for/main/topic \
15d3af5e
JX
57 >out 2>&1 &&
58 make_user_friendly_and_stable_output <out >actual &&
59
60 cat >expect <<-EOF &&
61 remote: # pre-receive hook
a9568dba 62 remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
15d3af5e
JX
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>
a9568dba 67 ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook)
15d3af5e
JX
68 EOF
69 test_cmp expect actual &&
70
71 git -C "$upstream" show-ref >out &&
72 make_user_friendly_and_stable_output <out >actual &&
73 cat >expect <<-EOF &&
a9568dba 74 <COMMIT-A> refs/heads/main
15d3af5e
JX
75 EOF
76 test_cmp expect actual
77'
78
79test_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
83 EOF
84'
85
a9568dba
JS
86# Refs of upstream : main(A)
87# Refs of workbench: main(A) tags/v123
88# git push : refs/for/main/topic(A)
15d3af5e
JX
89test_expect_success "proc-receive: bad protocol (hook --die-readline, $PROTOCOL)" '
90 test_must_fail git -C workbench push origin \
a9568dba 91 HEAD:refs/for/main/topic \
15d3af5e
JX
92 >out 2>&1 &&
93 make_user_friendly_and_stable_output <out >actual &&
94
a9568dba 95 grep "remote: fatal: protocol error: expected \"old new ref\", got \"<ZERO-OID> <COMMIT-A> refs/for/main/topic\"" actual &&
15d3af5e
JX
96
97 git -C "$upstream" show-ref >out &&
98 make_user_friendly_and_stable_output <out >actual &&
99 cat >expect <<-EOF &&
a9568dba 100 <COMMIT-A> refs/heads/main
15d3af5e
JX
101 EOF
102 test_cmp expect actual
103'
104
105test_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
109 EOF
110'
111
a9568dba
JS
112# Refs of upstream : main(A)
113# Refs of workbench: main(A) tags/v123
114# git push : next(A) refs/for/main/topic(A)
15d3af5e
JX
115test_expect_success "proc-receive: bad protocol (no report, $PROTOCOL)" '
116 test_must_fail git -C workbench push origin \
117 HEAD:refs/heads/next \
a9568dba 118 HEAD:refs/for/main/topic >out 2>&1 &&
15d3af5e
JX
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
a9568dba 123 remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
15d3af5e 124 remote: # proc-receive hook
a9568dba 125 remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
15d3af5e
JX
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
a9568dba 130 ! [remote rejected] HEAD -> refs/for/main/topic (proc-receive failed to report status)
15d3af5e
JX
131 EOF
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 &&
a9568dba 136 <COMMIT-A> refs/heads/main
15d3af5e
JX
137 <COMMIT-A> refs/heads/next
138 EOF
139 test_cmp expect actual
140'
141
a9568dba
JS
142# Refs of upstream : main(A) next(A)
143# Refs of workbench: main(A) tags/v123
15d3af5e
JX
144test_expect_success "cleanup ($PROTOCOL)" '
145 git -C "$upstream" update-ref -d refs/heads/next
146
147'
148
149test_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 \
153 -r "ok"
154 EOF
155'
156
a9568dba
JS
157# Refs of upstream : main(A)
158# Refs of workbench: main(A) tags/v123
159# git push : refs/for/main/topic
15d3af5e
JX
160test_expect_success "proc-receive: bad protocol (no ref, $PROTOCOL)" '
161 test_must_fail git -C workbench push origin \
a9568dba 162 HEAD:refs/for/main/topic\
15d3af5e
JX
163 >out 2>&1 &&
164 make_user_friendly_and_stable_output <out >actual &&
165 cat >expect <<-EOF &&
166 remote: # pre-receive hook
a9568dba 167 remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
15d3af5e 168 remote: # proc-receive hook
a9568dba 169 remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
15d3af5e
JX
170 remote: proc-receive> ok
171 remote: error: proc-receive reported incomplete status line: "ok"
172 To <URL/of/upstream.git>
a9568dba 173 ! [remote rejected] HEAD -> refs/for/main/topic (proc-receive failed to report status)
15d3af5e
JX
174 EOF
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 &&
a9568dba 179 <COMMIT-A> refs/heads/main
15d3af5e
JX
180 EOF
181 test_cmp expect actual
182'
183
184test_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 \
a9568dba 188 -r "xx refs/for/main/topic"
15d3af5e
JX
189 EOF
190'
191
a9568dba
JS
192# Refs of upstream : main(A)
193# Refs of workbench: main(A) tags/v123
194# git push : refs/for/main/topic
15d3af5e
JX
195test_expect_success "proc-receive: bad protocol (unknown status, $PROTOCOL)" '
196 test_must_fail git -C workbench push origin \
a9568dba 197 HEAD:refs/for/main/topic \
15d3af5e
JX
198 >out 2>&1 &&
199 make_user_friendly_and_stable_output <out >actual &&
200 cat >expect <<-EOF &&
201 remote: # pre-receive hook
a9568dba 202 remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
15d3af5e 203 remote: # proc-receive hook
a9568dba
JS
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"
15d3af5e 207 To <URL/of/upstream.git>
a9568dba 208 ! [remote rejected] HEAD -> refs/for/main/topic (proc-receive failed to report status)
15d3af5e
JX
209 EOF
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 &&
a9568dba 214 <COMMIT-A> refs/heads/main
15d3af5e
JX
215 EOF
216 test_cmp expect actual
217'