Merge branch 'ab/mediawiki-fixes'
[git] / t / t5411 / test-0014-bad-protocol--porcelain.sh
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
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/porcelain)" '
12         test_must_fail git -C workbench push --porcelain 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; n; p; }" \
20                 <actual >actual-report &&
21         cat >expect <<-EOF &&
22         To <URL/of/upstream.git>
23         !    HEAD:refs/for/master/topic    [remote rejected] (fail to run proc-receive hook)
24         Done
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 &&
40         <COMMIT-A> refs/heads/master
41         EOF
42         test_cmp expect actual
43 '
44
45 test_expect_success "setup proc-receive hook (no report, $PROTOCOL/porcelain)" '
46         write_script "$upstream/hooks/proc-receive" <<-EOF
47         printf >&2 "# proc-receive hook\n"
48         test-tool proc-receive -v
49         EOF
50 '
51
52 # Refs of upstream : master(A)
53 # Refs of workbench: master(A)  tags/v123
54 # git push         :                       next(A)  refs/for/master/topic(A)
55 test_expect_success "proc-receive: bad protocol (no report, $PROTOCOL/porcelain)" '
56         test_must_fail git -C workbench push --porcelain origin \
57                 HEAD:refs/heads/next \
58                 HEAD:refs/for/master/topic >out 2>&1 &&
59         make_user_friendly_and_stable_output <out >actual &&
60         cat >expect <<-EOF &&
61         remote: # pre-receive hook
62         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
63         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
64         remote: # proc-receive hook
65         remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
66         remote: # post-receive hook
67         remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
68         To <URL/of/upstream.git>
69         *    HEAD:refs/heads/next    [new branch]
70         !    HEAD:refs/for/master/topic    [remote rejected] (proc-receive failed to report status)
71         Done
72         EOF
73         test_cmp expect actual &&
74         git -C "$upstream" show-ref >out &&
75         make_user_friendly_and_stable_output <out >actual &&
76         cat >expect <<-EOF &&
77         <COMMIT-A> refs/heads/master
78         <COMMIT-A> refs/heads/next
79         EOF
80         test_cmp expect actual
81 '
82
83 # Refs of upstream : master(A)             next(A)
84 # Refs of workbench: master(A)  tags/v123
85 test_expect_success "cleanup ($PROTOCOL/porcelain)" '
86         git -C "$upstream" update-ref -d refs/heads/next
87
88 '
89
90 test_expect_success "setup proc-receive hook (no ref, $PROTOCOL/porcelain)" '
91         write_script "$upstream/hooks/proc-receive" <<-EOF
92         printf >&2 "# proc-receive hook\n"
93         test-tool proc-receive -v \
94                 -r "ok"
95         EOF
96 '
97
98 # Refs of upstream : master(A)
99 # Refs of workbench: master(A)  tags/v123
100 # git push         :                       refs/for/master/topic
101 test_expect_success "proc-receive: bad protocol (no ref, $PROTOCOL/porcelain)" '
102         test_must_fail git -C workbench push --porcelain origin \
103                 HEAD:refs/for/master/topic\
104                 >out 2>&1 &&
105         make_user_friendly_and_stable_output <out >actual &&
106         cat >expect <<-EOF &&
107         remote: # pre-receive hook
108         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
109         remote: # proc-receive hook
110         remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
111         remote: proc-receive> ok
112         remote: error: proc-receive reported incomplete status line: "ok"
113         To <URL/of/upstream.git>
114         !    HEAD:refs/for/master/topic    [remote rejected] (proc-receive failed to report status)
115         Done
116         EOF
117         test_cmp expect actual &&
118         git -C "$upstream" show-ref >out &&
119         make_user_friendly_and_stable_output <out >actual &&
120         cat >expect <<-EOF &&
121         <COMMIT-A> refs/heads/master
122         EOF
123         test_cmp expect actual
124 '
125
126 test_expect_success "setup proc-receive hook (unknown status, $PROTOCOL/porcelain)" '
127         write_script "$upstream/hooks/proc-receive" <<-EOF
128         printf >&2 "# proc-receive hook\n"
129         test-tool proc-receive -v \
130                 -r "xx refs/for/master/topic"
131         EOF
132 '
133
134 # Refs of upstream : master(A)
135 # Refs of workbench: master(A)  tags/v123
136 # git push         :                       refs/for/master/topic
137 test_expect_success "proc-receive: bad protocol (unknown status, $PROTOCOL/porcelain)" '
138         test_must_fail git -C workbench push --porcelain origin \
139                         HEAD:refs/for/master/topic \
140                         >out 2>&1 &&
141         make_user_friendly_and_stable_output <out >actual &&
142         cat >expect <<-EOF &&
143         remote: # pre-receive hook
144         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
145         remote: # proc-receive hook
146         remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
147         remote: proc-receive> xx refs/for/master/topic
148         remote: error: proc-receive reported bad status "xx" on ref "refs/for/master/topic"
149         To <URL/of/upstream.git>
150         !    HEAD:refs/for/master/topic    [remote rejected] (proc-receive failed to report status)
151         Done
152         EOF
153         test_cmp expect actual &&
154         git -C "$upstream" show-ref >out &&
155         make_user_friendly_and_stable_output <out >actual &&
156         cat >expect <<-EOF &&
157         <COMMIT-A> refs/heads/master
158         EOF
159         test_cmp expect actual
160 '