Merge remote-tracking branch 'paulus/master' into pm/gitk-update
[git] / t / t5411 / test-0013-bad-protocol.sh
1 test_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
8 # Refs of upstream : master(A)
9 # Refs of workbench: master(A)  tags/v123
10 # git push         :                       refs/for/master/topic(A)
11 test_expect_success "proc-receive: bad protocol (unknown version, $PROTOCOL)" '
12         test_must_fail git -C workbench push origin \
13                 HEAD:refs/for/master/topic \
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>
23          ! [remote rejected] HEAD -> refs/for/master/topic (fail to run proc-receive hook)
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 &&
39         <COMMIT-A> refs/heads/master
40         EOF
41         test_cmp expect actual
42 '
43
44 test_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
51 # Refs of upstream : master(A)
52 # Refs of workbench: master(A)  tags/v123
53 # git push         :                       refs/for/master/topic(A)
54 test_expect_success "proc-receive: bad protocol (hook --die-version, $PROTOCOL)" '
55         test_must_fail git -C workbench push origin \
56                 HEAD:refs/for/master/topic \
57                 >out 2>&1 &&
58         make_user_friendly_and_stable_output <out >actual &&
59
60         cat >expect <<-EOF &&
61         remote: # pre-receive hook
62         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
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>
67          ! [remote rejected] HEAD -> refs/for/master/topic (fail to run proc-receive hook)
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 &&
74         <COMMIT-A> refs/heads/master
75         EOF
76         test_cmp expect actual
77 '
78
79 test_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
86 # Refs of upstream : master(A)
87 # Refs of workbench: master(A)  tags/v123
88 # git push         :                       refs/for/master/topic(A)
89 test_expect_success "proc-receive: bad protocol (hook --die-readline, $PROTOCOL)" '
90         test_must_fail git -C workbench push origin \
91                 HEAD:refs/for/master/topic \
92                 >out 2>&1 &&
93         make_user_friendly_and_stable_output <out >actual &&
94
95         grep "remote: fatal: protocol error: expected \"old new ref\", got \"<ZERO-OID> <COMMIT-A> refs/for/master/topic\"" actual &&
96
97         git -C "$upstream" show-ref >out &&
98         make_user_friendly_and_stable_output <out >actual &&
99         cat >expect <<-EOF &&
100         <COMMIT-A> refs/heads/master
101         EOF
102         test_cmp expect actual
103 '
104
105 test_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
112 # Refs of upstream : master(A)
113 # Refs of workbench: master(A)  tags/v123
114 # git push         :                       next(A)  refs/for/master/topic(A)
115 test_expect_success "proc-receive: bad protocol (no report, $PROTOCOL)" '
116         test_must_fail git -C workbench push origin \
117                 HEAD:refs/heads/next \
118                 HEAD:refs/for/master/topic >out 2>&1 &&
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
123         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
124         remote: # proc-receive hook
125         remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
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
130          ! [remote rejected] HEAD -> refs/for/master/topic (proc-receive failed to report status)
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 &&
136         <COMMIT-A> refs/heads/master
137         <COMMIT-A> refs/heads/next
138         EOF
139         test_cmp expect actual
140 '
141
142 # Refs of upstream : master(A)             next(A)
143 # Refs of workbench: master(A)  tags/v123
144 test_expect_success "cleanup ($PROTOCOL)" '
145         git -C "$upstream" update-ref -d refs/heads/next
146
147 '
148
149 test_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
157 # Refs of upstream : master(A)
158 # Refs of workbench: master(A)  tags/v123
159 # git push         :                       refs/for/master/topic
160 test_expect_success "proc-receive: bad protocol (no ref, $PROTOCOL)" '
161         test_must_fail git -C workbench push origin \
162                 HEAD:refs/for/master/topic\
163                 >out 2>&1 &&
164         make_user_friendly_and_stable_output <out >actual &&
165         cat >expect <<-EOF &&
166         remote: # pre-receive hook
167         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
168         remote: # proc-receive hook
169         remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
170         remote: proc-receive> ok
171         remote: error: proc-receive reported incomplete status line: "ok"
172         To <URL/of/upstream.git>
173          ! [remote rejected] HEAD -> refs/for/master/topic (proc-receive failed to report status)
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 &&
179         <COMMIT-A> refs/heads/master
180         EOF
181         test_cmp expect actual
182 '
183
184 test_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 \
188                 -r "xx refs/for/master/topic"
189         EOF
190 '
191
192 # Refs of upstream : master(A)
193 # Refs of workbench: master(A)  tags/v123
194 # git push         :                       refs/for/master/topic
195 test_expect_success "proc-receive: bad protocol (unknown status, $PROTOCOL)" '
196         test_must_fail git -C workbench push origin \
197                         HEAD:refs/for/master/topic \
198                         >out 2>&1 &&
199         make_user_friendly_and_stable_output <out >actual &&
200         cat >expect <<-EOF &&
201         remote: # pre-receive hook
202         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
203         remote: # proc-receive hook
204         remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
205         remote: proc-receive> xx refs/for/master/topic
206         remote: error: proc-receive reported bad status "xx" on ref "refs/for/master/topic"
207         To <URL/of/upstream.git>
208          ! [remote rejected] HEAD -> refs/for/master/topic (proc-receive failed to report status)
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 &&
214         <COMMIT-A> refs/heads/master
215         EOF
216         test_cmp expect actual
217 '