The second batch
[git] / t / t5411 / test-0037-report-multi-rewrite-for-one-ref--porcelain.sh
1 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 1st rewrite, $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 "ok refs/for/main/topic" \
6                 -r "option old-oid $A" \
7                 -r "option new-oid $B" \
8                 -r "ok refs/for/main/topic" \
9                 -r "option refname refs/changes/24/124/1" \
10                 -r "option old-oid $ZERO_OID" \
11                 -r "option new-oid $A" \
12                 -r "ok refs/for/main/topic" \
13                 -r "option refname refs/changes/25/125/1" \
14                 -r "option old-oid $A" \
15                 -r "option new-oid $B"
16         EOF
17 '
18
19 # Refs of upstream : main(A)
20 # Refs of workbench: main(A)  tags/v123
21 # git push         :                       refs/for/main/topic(A)
22 test_expect_success "proc-receive: multiple rewrite for one ref, no refname for the 1st rewrite ($PROTOCOL/porcelain)" '
23         git -C workbench push --porcelain origin \
24                 HEAD:refs/for/main/topic \
25                 >out 2>&1 &&
26         make_user_friendly_and_stable_output <out >actual &&
27         cat >expect <<-EOF &&
28         remote: # pre-receive hook
29         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
30         remote: # proc-receive hook
31         remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
32         remote: proc-receive> ok refs/for/main/topic
33         remote: proc-receive> option old-oid <COMMIT-A>
34         remote: proc-receive> option new-oid <COMMIT-B>
35         remote: proc-receive> ok refs/for/main/topic
36         remote: proc-receive> option refname refs/changes/24/124/1
37         remote: proc-receive> option old-oid <ZERO-OID>
38         remote: proc-receive> option new-oid <COMMIT-A>
39         remote: proc-receive> ok refs/for/main/topic
40         remote: proc-receive> option refname refs/changes/25/125/1
41         remote: proc-receive> option old-oid <COMMIT-A>
42         remote: proc-receive> option new-oid <COMMIT-B>
43         remote: # post-receive hook
44         remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/main/topic
45         remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1
46         remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/25/125/1
47         To <URL/of/upstream.git>
48              HEAD:refs/for/main/topic    <OID-A>..<OID-B>
49         *    HEAD:refs/changes/24/124/1    [new reference]
50              HEAD:refs/changes/25/125/1    <OID-A>..<OID-B>
51         Done
52         EOF
53         test_cmp expect actual &&
54
55         test_cmp_refs -C "$upstream" <<-EOF
56         <COMMIT-A> refs/heads/main
57         EOF
58 '
59
60 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 2nd rewrite, $PROTOCOL/porcelain)" '
61         write_script "$upstream/hooks/proc-receive" <<-EOF
62         printf >&2 "# proc-receive hook\n"
63         test-tool proc-receive -v \
64                 -r "ok refs/for/main/topic" \
65                 -r "option refname refs/changes/24/124/1" \
66                 -r "option old-oid $ZERO_OID" \
67                 -r "option new-oid $A" \
68                 -r "ok refs/for/main/topic" \
69                 -r "option old-oid $A" \
70                 -r "option new-oid $B" \
71                 -r "ok refs/for/main/topic" \
72                 -r "option refname refs/changes/25/125/1" \
73                 -r "option old-oid $B" \
74                 -r "option new-oid $A" \
75                 -r "option forced-update"
76         EOF
77 '
78
79 # Refs of upstream : main(A)
80 # Refs of workbench: main(A)  tags/v123
81 # git push         :                       refs/for/main/topic(A)
82 test_expect_success "proc-receive: multiple rewrites for one ref, no refname for the 2nd rewrite ($PROTOCOL/porcelain)" '
83         git -C workbench push --porcelain origin \
84                 HEAD:refs/for/main/topic \
85                 >out 2>&1 &&
86         make_user_friendly_and_stable_output <out >actual &&
87         cat >expect <<-EOF &&
88         remote: # pre-receive hook
89         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
90         remote: # proc-receive hook
91         remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
92         remote: proc-receive> ok refs/for/main/topic
93         remote: proc-receive> option refname refs/changes/24/124/1
94         remote: proc-receive> option old-oid <ZERO-OID>
95         remote: proc-receive> option new-oid <COMMIT-A>
96         remote: proc-receive> ok refs/for/main/topic
97         remote: proc-receive> option old-oid <COMMIT-A>
98         remote: proc-receive> option new-oid <COMMIT-B>
99         remote: proc-receive> ok refs/for/main/topic
100         remote: proc-receive> option refname refs/changes/25/125/1
101         remote: proc-receive> option old-oid <COMMIT-B>
102         remote: proc-receive> option new-oid <COMMIT-A>
103         remote: proc-receive> option forced-update
104         remote: # post-receive hook
105         remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1
106         remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/main/topic
107         remote: post-receive< <COMMIT-B> <COMMIT-A> refs/changes/25/125/1
108         To <URL/of/upstream.git>
109         *    HEAD:refs/changes/24/124/1    [new reference]
110              HEAD:refs/for/main/topic    <OID-A>..<OID-B>
111         +    HEAD:refs/changes/25/125/1    <OID-B>...<OID-A> (forced update)
112         Done
113         EOF
114         test_cmp expect actual &&
115
116         test_cmp_refs -C "$upstream" <<-EOF
117         <COMMIT-A> refs/heads/main
118         EOF
119 '
120
121 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, $PROTOCOL/porcelain)" '
122         write_script "$upstream/hooks/proc-receive" <<-EOF
123         printf >&2 "# proc-receive hook\n"
124         test-tool proc-receive -v \
125                 -r "ok refs/for/main/topic" \
126                 -r "option refname refs/changes/23/123/1" \
127                 -r "ok refs/for/main/topic" \
128                 -r "option refname refs/changes/24/124/2" \
129                 -r "option old-oid $A" \
130                 -r "option new-oid $B"
131         EOF
132 '
133
134 # Refs of upstream : main(A)
135 # Refs of workbench: main(A)  tags/v123
136 # git push         :                       refs/for/main/topic(A)
137 test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL/porcelain)" '
138         git -C workbench push --porcelain origin \
139                 HEAD:refs/for/main/topic \
140                 >out 2>&1 &&
141         make_user_friendly_and_stable_output <out >actual &&
142         cat >expect <<-EOF &&
143         remote: # pre-receive hook
144         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
145         remote: # proc-receive hook
146         remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
147         remote: proc-receive> ok refs/for/main/topic
148         remote: proc-receive> option refname refs/changes/23/123/1
149         remote: proc-receive> ok refs/for/main/topic
150         remote: proc-receive> option refname refs/changes/24/124/2
151         remote: proc-receive> option old-oid <COMMIT-A>
152         remote: proc-receive> option new-oid <COMMIT-B>
153         remote: # post-receive hook
154         remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/23/123/1
155         remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/24/124/2
156         To <URL/of/upstream.git>
157         *    HEAD:refs/changes/23/123/1    [new reference]
158              HEAD:refs/changes/24/124/2    <OID-A>..<OID-B>
159         Done
160         EOF
161         test_cmp expect actual &&
162
163         test_cmp_refs -C "$upstream" <<-EOF
164         <COMMIT-A> refs/heads/main
165         EOF
166 '