Merge branch 'da/vs-build-iconv-fix'
[git] / t / t5411 / test-0027-push-options--porcelain.sh
1 test_expect_success "setup proc-receive hook and disable push-options ($PROTOCOL/porcelain)" '
2         git -C "$upstream" config receive.advertisePushOptions false &&
3         write_script "$upstream/hooks/proc-receive" <<-EOF
4         printf >&2 "# proc-receive hook\n"
5         test-tool proc-receive -v \
6                 -r "ok refs/for/main/topic"
7         EOF
8 '
9
10 # Refs of upstream : main(A)
11 # Refs of workbench: main(A)  tags/v123
12 # git push -o ...  :                       refs/for/main/topic
13 test_expect_success "proc-receive: not support push options ($PROTOCOL/porcelain)" '
14         test_must_fail git -C workbench push \
15                 --porcelain \
16                 -o issue=123 \
17                 -o reviewer=user1 \
18                 origin \
19                 HEAD:refs/for/main/topic \
20                 >out 2>&1 &&
21         make_user_friendly_and_stable_output <out >actual &&
22         test_i18ngrep "fatal: the receiving end does not support push options" \
23                 actual &&
24         git -C "$upstream" show-ref >out &&
25         make_user_friendly_and_stable_output <out >actual &&
26         cat >expect <<-EOF &&
27         <COMMIT-A> refs/heads/main
28         EOF
29         test_cmp expect actual
30 '
31
32 test_expect_success "enable push options ($PROTOCOL/porcelain)" '
33         git -C "$upstream" config receive.advertisePushOptions true
34 '
35
36 test_expect_success "setup version=0 for proc-receive hook ($PROTOCOL/porcelain)" '
37         write_script "$upstream/hooks/proc-receive" <<-EOF
38         printf >&2 "# proc-receive hook\n"
39         test-tool proc-receive -v \
40                 --version 0 \
41                 -r "ok refs/for/main/topic"
42         EOF
43 '
44
45 # Refs of upstream : main(A)
46 # Refs of workbench: main(A)  tags/v123
47 # git push -o ...  :                       next(A)  refs/for/main/topic
48 test_expect_success "proc-receive: ignore push-options for version 0 ($PROTOCOL/porcelain)" '
49         git -C workbench push \
50                 --porcelain \
51                 --atomic \
52                 -o issue=123 \
53                 -o reviewer=user1 \
54                 origin \
55                 HEAD:refs/heads/next \
56                 HEAD:refs/for/main/topic \
57                 >out 2>&1 &&
58         make_user_friendly_and_stable_output <out >actual &&
59         cat >expect <<-EOF &&
60         remote: # pre-receive hook
61         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
62         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
63         remote: # proc-receive hook
64         remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
65         remote: proc-receive> ok refs/for/main/topic
66         remote: # post-receive hook
67         remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
68         remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
69         To <URL/of/upstream.git>
70         *    HEAD:refs/heads/next    [new branch]
71         *    HEAD:refs/for/main/topic    [new reference]
72         Done
73         EOF
74         test_cmp expect actual &&
75         git -C "$upstream" show-ref >out &&
76         make_user_friendly_and_stable_output <out >actual &&
77         cat >expect <<-EOF &&
78         <COMMIT-A> refs/heads/main
79         <COMMIT-A> refs/heads/next
80         EOF
81         test_cmp expect actual
82 '
83
84 test_expect_success "restore proc-receive hook ($PROTOCOL/porcelain)" '
85         write_script "$upstream/hooks/proc-receive" <<-EOF
86         printf >&2 "# proc-receive hook\n"
87         test-tool proc-receive -v \
88                 -r "ok refs/for/main/topic"
89         EOF
90 '
91
92 # Refs of upstream : main(A)             next(A)
93 # Refs of workbench: main(A)  tags/v123
94 test_expect_success "cleanup ($PROTOCOL/porcelain)" '
95         git -C "$upstream" update-ref -d refs/heads/next
96 '
97
98 # Refs of upstream : main(A)
99 # Refs of workbench: main(A)  tags/v123
100 # git push -o ...  :                       next(A)  refs/for/main/topic
101 test_expect_success "proc-receive: push with options ($PROTOCOL/porcelain)" '
102         git -C workbench push \
103                 --porcelain \
104                 --atomic \
105                 -o issue=123 \
106                 -o reviewer=user1 \
107                 origin \
108                 HEAD:refs/heads/next \
109                 HEAD:refs/for/main/topic \
110                 >out 2>&1 &&
111         make_user_friendly_and_stable_output <out >actual &&
112         cat >expect <<-EOF &&
113         remote: # pre-receive hook
114         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
115         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
116         remote: # proc-receive hook
117         remote: proc-receive: atomic push_options
118         remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
119         remote: proc-receive< issue=123
120         remote: proc-receive< reviewer=user1
121         remote: proc-receive> ok refs/for/main/topic
122         remote: # post-receive hook
123         remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
124         remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
125         To <URL/of/upstream.git>
126         *    HEAD:refs/heads/next    [new branch]
127         *    HEAD:refs/for/main/topic    [new reference]
128         Done
129         EOF
130         test_cmp expect actual &&
131         git -C "$upstream" show-ref >out &&
132         make_user_friendly_and_stable_output <out >actual &&
133         cat >expect <<-EOF &&
134         <COMMIT-A> refs/heads/main
135         <COMMIT-A> refs/heads/next
136         EOF
137         test_cmp expect actual
138 '
139
140 # Refs of upstream : main(A)             next(A)
141 # Refs of workbench: main(A)  tags/v123
142 test_expect_success "cleanup ($PROTOCOL/porcelain)" '
143         git -C "$upstream" update-ref -d refs/heads/next
144 '