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