Merge branch 'al/ref-filter-merged-and-no-merged'
[git] / t / t5411 / test-0033-report-with-options--porcelain.sh
1 test_expect_success "setup proc-receive hook (option without matching ok, $PROTOCOL/porcelain)" '
2         write_script "$upstream/hooks/proc-receive" <<-EOF
3         printf >&2 "# proc-receive hook\n"
4         test-tool proc-receive -v \
5                 -r "option refname refs/pull/123/head" \
6                 -r "option old-oid $B"
7         EOF
8 '
9
10 # Refs of upstream : master(A)
11 # Refs of workbench: master(A)  tags/v123
12 # git push         :                       refs/for/next/topic(A)  refs/for/a/b/c/topic(A)  refs/for/master/topic(A)
13 test_expect_success "proc-receive: report option without matching ok ($PROTOCOL/porcelain)" '
14         test_must_fail git -C workbench push --porcelain origin \
15                 HEAD:refs/for/master/topic \
16                 >out 2>&1 &&
17         make_user_friendly_and_stable_output <out >actual &&
18         cat >expect <<-EOF &&
19         remote: # pre-receive hook
20         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
21         remote: # proc-receive hook
22         remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
23         remote: proc-receive> option refname refs/pull/123/head
24         remote: proc-receive> option old-oid <COMMIT-B>
25         remote: error: proc-receive reported "option" without a matching "ok/ng" directive
26         To <URL/of/upstream.git>
27         !    HEAD:refs/for/master/topic    [remote rejected] (proc-receive failed to report status)
28         Done
29         EOF
30         test_cmp expect actual
31 '
32
33 test_expect_success "setup proc-receive hook (option refname, $PROTOCOL/porcelain)" '
34         write_script "$upstream/hooks/proc-receive" <<-EOF
35         printf >&2 "# proc-receive hook\n"
36         test-tool proc-receive -v \
37                 -r "ok refs/for/master/topic" \
38                 -r "option refname refs/pull/123/head"
39         EOF
40 '
41
42 # Refs of upstream : master(A)
43 # Refs of workbench: master(A)  tags/v123
44 # git push         :                       refs/for/next/topic(A)  refs/for/a/b/c/topic(A)  refs/for/master/topic(A)
45 test_expect_success "proc-receive: report option refname ($PROTOCOL/porcelain)" '
46         git -C workbench push --porcelain origin \
47                 HEAD:refs/for/master/topic \
48                 >out 2>&1 &&
49         make_user_friendly_and_stable_output <out >actual &&
50         cat >expect <<-EOF &&
51         remote: # pre-receive hook
52         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
53         remote: # proc-receive hook
54         remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
55         remote: proc-receive> ok refs/for/master/topic
56         remote: proc-receive> option refname refs/pull/123/head
57         remote: # post-receive hook
58         remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
59         To <URL/of/upstream.git>
60         *    HEAD:refs/pull/123/head    [new reference]
61         Done
62         EOF
63         test_cmp expect actual
64 '
65
66 test_expect_success "setup proc-receive hook (option refname and forced-update, $PROTOCOL/porcelain)" '
67         write_script "$upstream/hooks/proc-receive" <<-EOF
68         printf >&2 "# proc-receive hook\n"
69         test-tool proc-receive -v \
70                 -r "ok refs/for/master/topic" \
71                 -r "option refname refs/pull/123/head" \
72                 -r "option forced-update"
73         EOF
74 '
75
76 # Refs of upstream : master(A)
77 # Refs of workbench: master(A)  tags/v123
78 # git push         :                       refs/for/next/topic(A)  refs/for/a/b/c/topic(A)  refs/for/master/topic(A)
79 test_expect_success "proc-receive: report option refname and forced-update ($PROTOCOL/porcelain)" '
80         git -C workbench push --porcelain origin \
81                 HEAD:refs/for/master/topic \
82                 >out 2>&1 &&
83         make_user_friendly_and_stable_output <out >actual &&
84         cat >expect <<-EOF &&
85         remote: # pre-receive hook
86         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
87         remote: # proc-receive hook
88         remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
89         remote: proc-receive> ok refs/for/master/topic
90         remote: proc-receive> option refname refs/pull/123/head
91         remote: proc-receive> option forced-update
92         remote: # post-receive hook
93         remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
94         To <URL/of/upstream.git>
95         *    HEAD:refs/pull/123/head    [new reference]
96         Done
97         EOF
98         test_cmp expect actual
99 '
100
101 test_expect_success "setup proc-receive hook (option refname and old-oid, $PROTOCOL/porcelain)" '
102         write_script "$upstream/hooks/proc-receive" <<-EOF
103         printf >&2 "# proc-receive hook\n"
104         test-tool proc-receive -v \
105                 -r "ok refs/for/master/topic" \
106                 -r "option refname refs/pull/123/head" \
107                 -r "option old-oid $B"
108         EOF
109 '
110
111 # Refs of upstream : master(A)
112 # Refs of workbench: master(A)  tags/v123
113 # git push         :                       refs/for/next/topic(A)  refs/for/a/b/c/topic(A)  refs/for/master/topic(A)
114 test_expect_success "proc-receive: report option refname and old-oid ($PROTOCOL/porcelain)" '
115         git -C workbench push --porcelain origin \
116                 HEAD:refs/for/master/topic \
117                 >out 2>&1 &&
118         make_user_friendly_and_stable_output <out >actual &&
119         cat >expect <<-EOF &&
120         remote: # pre-receive hook
121         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
122         remote: # proc-receive hook
123         remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
124         remote: proc-receive> ok refs/for/master/topic
125         remote: proc-receive> option refname refs/pull/123/head
126         remote: proc-receive> option old-oid <COMMIT-B>
127         remote: # post-receive hook
128         remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/123/head
129         To <URL/of/upstream.git>
130              HEAD:refs/pull/123/head    <OID-B>..<OID-A>
131         Done
132         EOF
133         test_cmp expect actual
134 '
135
136 test_expect_success "setup proc-receive hook (option old-oid, $PROTOCOL/porcelain)" '
137         write_script "$upstream/hooks/proc-receive" <<-EOF
138         printf >&2 "# proc-receive hook\n"
139         test-tool proc-receive -v \
140                 -r "ok refs/for/master/topic" \
141                 -r "option old-oid $B"
142         EOF
143 '
144
145 # Refs of upstream : master(A)
146 # Refs of workbench: master(A)  tags/v123
147 # git push         :                       refs/for/next/topic(A)  refs/for/a/b/c/topic(A)  refs/for/master/topic(A)
148 test_expect_success "proc-receive: report option old-oid ($PROTOCOL/porcelain)" '
149         git -C workbench push --porcelain origin \
150                 HEAD:refs/for/master/topic \
151                 >out 2>&1 &&
152         make_user_friendly_and_stable_output <out >actual &&
153         cat >expect <<-EOF &&
154         remote: # pre-receive hook
155         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
156         remote: # proc-receive hook
157         remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
158         remote: proc-receive> ok refs/for/master/topic
159         remote: proc-receive> option old-oid <COMMIT-B>
160         remote: # post-receive hook
161         remote: post-receive< <COMMIT-B> <COMMIT-A> refs/for/master/topic
162         To <URL/of/upstream.git>
163              HEAD:refs/for/master/topic    <OID-B>..<OID-A>
164         Done
165         EOF
166         test_cmp expect actual
167 '
168
169 test_expect_success "setup proc-receive hook (option old-oid and new-oid, $PROTOCOL/porcelain)" '
170         write_script "$upstream/hooks/proc-receive" <<-EOF
171         printf >&2 "# proc-receive hook\n"
172         test-tool proc-receive -v \
173                 -r "ok refs/for/master/topic" \
174                 -r "option old-oid $A" \
175                 -r "option new-oid $B"
176         EOF
177 '
178
179 # Refs of upstream : master(A)
180 # Refs of workbench: master(A)  tags/v123
181 # git push         :                       refs/for/next/topic(A)  refs/for/a/b/c/topic(A)  refs/for/master/topic(A)
182 test_expect_success "proc-receive: report option old-oid and new-oid ($PROTOCOL/porcelain)" '
183         git -C workbench push --porcelain origin \
184                 HEAD:refs/for/master/topic \
185                 >out 2>&1 &&
186         make_user_friendly_and_stable_output <out >actual &&
187         cat >expect <<-EOF &&
188         remote: # pre-receive hook
189         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
190         remote: # proc-receive hook
191         remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
192         remote: proc-receive> ok refs/for/master/topic
193         remote: proc-receive> option old-oid <COMMIT-A>
194         remote: proc-receive> option new-oid <COMMIT-B>
195         remote: # post-receive hook
196         remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
197         To <URL/of/upstream.git>
198              HEAD:refs/for/master/topic    <OID-A>..<OID-B>
199         Done
200         EOF
201         test_cmp expect actual
202 '
203
204 test_expect_success "setup proc-receive hook (report with multiple rewrites, $PROTOCOL/porcelain)" '
205         write_script "$upstream/hooks/proc-receive" <<-EOF
206         printf >&2 "# proc-receive hook\n"
207         test-tool proc-receive -v \
208                 -r "ok refs/for/a/b/c/topic" \
209                 -r "ok refs/for/next/topic" \
210                 -r "option refname refs/pull/123/head" \
211                 -r "ok refs/for/master/topic" \
212                 -r "option refname refs/pull/124/head" \
213                 -r "option old-oid $B" \
214                 -r "option forced-update" \
215                 -r "option new-oid $A"
216
217         EOF
218 '
219
220 # Refs of upstream : master(A)
221 # Refs of workbench: master(A)  tags/v123
222 # git push         :                       refs/for/next/topic(A)  refs/for/a/b/c/topic(A)  refs/for/master/topic(A)
223 test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL/porcelain)" '
224         git -C workbench push --porcelain origin \
225                 HEAD:refs/for/next/topic \
226                 HEAD:refs/for/a/b/c/topic \
227                 HEAD:refs/for/master/topic \
228                 >out 2>&1 &&
229         make_user_friendly_and_stable_output <out >actual &&
230         cat >expect <<-EOF &&
231         remote: # pre-receive hook
232         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
233         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
234         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
235         remote: # proc-receive hook
236         remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
237         remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
238         remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
239         remote: proc-receive> ok refs/for/a/b/c/topic
240         remote: proc-receive> ok refs/for/next/topic
241         remote: proc-receive> option refname refs/pull/123/head
242         remote: proc-receive> ok refs/for/master/topic
243         remote: proc-receive> option refname refs/pull/124/head
244         remote: proc-receive> option old-oid <COMMIT-B>
245         remote: proc-receive> option forced-update
246         remote: proc-receive> option new-oid <COMMIT-A>
247         remote: # post-receive hook
248         remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
249         remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
250         remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/124/head
251         To <URL/of/upstream.git>
252         *    HEAD:refs/pull/123/head    [new reference]
253         *    HEAD:refs/for/a/b/c/topic    [new reference]
254         +    HEAD:refs/pull/124/head    <OID-B>...<OID-A> (forced update)
255         Done
256         EOF
257         test_cmp expect actual &&
258
259         git -C "$upstream" show-ref >out &&
260         make_user_friendly_and_stable_output <out >actual &&
261         cat >expect <<-EOF &&
262         <COMMIT-A> refs/heads/master
263         EOF
264         test_cmp expect actual
265 '