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