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