Merge branch 'rs/pack-write-hashwrite-simplify'
[git] / t / t5411 / test-0036-report-multi-rewrite-for-one-ref.sh
1 test_expect_success "setup git config for remote-tracking of special refs" '
2         (
3                 cd workbench &&
4                 if ! git config --get-all remote.origin.fetch | grep refs/for/
5                 then
6                         git config --add remote.origin.fetch \
7                                 "+refs/for/*:refs/t/for/*" &&
8                         git config --add remote.origin.fetch \
9                                 "+refs/pull/*:refs/t/pull/*" &&
10                         git config --add remote.origin.fetch \
11                                 "+refs/changes/*:refs/t/changes/*"
12                 fi
13         )
14 '
15
16 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 1st rewrite, $PROTOCOL)" '
17         write_script "$upstream/hooks/proc-receive" <<-EOF
18         printf >&2 "# proc-receive hook\n"
19         test-tool proc-receive -v \
20                 -r "ok refs/for/main/topic" \
21                 -r "option old-oid $A" \
22                 -r "option new-oid $B" \
23                 -r "ok refs/for/main/topic" \
24                 -r "option refname refs/changes/24/124/1" \
25                 -r "option old-oid $ZERO_OID" \
26                 -r "option new-oid $A" \
27                 -r "ok refs/for/main/topic" \
28                 -r "option refname refs/changes/25/125/1" \
29                 -r "option old-oid $A" \
30                 -r "option new-oid $B"
31         EOF
32 '
33
34 # Refs of upstream : main(A)
35 # Refs of workbench: main(A)  tags/v123
36 # git push         :                       refs/for/main/topic(A)
37 test_expect_success "proc-receive: multiple rewrite for one ref, no refname for the 1st rewrite ($PROTOCOL)" '
38         git -C workbench push origin \
39                 HEAD:refs/for/main/topic \
40                 >out 2>&1 &&
41         make_user_friendly_and_stable_output <out >actual &&
42         cat >expect <<-EOF &&
43         remote: # pre-receive hook
44         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
45         remote: # proc-receive hook
46         remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
47         remote: proc-receive> ok refs/for/main/topic
48         remote: proc-receive> option old-oid <COMMIT-A>
49         remote: proc-receive> option new-oid <COMMIT-B>
50         remote: proc-receive> ok refs/for/main/topic
51         remote: proc-receive> option refname refs/changes/24/124/1
52         remote: proc-receive> option old-oid <ZERO-OID>
53         remote: proc-receive> option new-oid <COMMIT-A>
54         remote: proc-receive> ok refs/for/main/topic
55         remote: proc-receive> option refname refs/changes/25/125/1
56         remote: proc-receive> option old-oid <COMMIT-A>
57         remote: proc-receive> option new-oid <COMMIT-B>
58         remote: # post-receive hook
59         remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/main/topic
60         remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1
61         remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/25/125/1
62         To <URL/of/upstream.git>
63          <OID-A>..<OID-B> HEAD -> refs/for/main/topic
64          * [new reference] HEAD -> refs/changes/24/124/1
65          <OID-A>..<OID-B> HEAD -> refs/changes/25/125/1
66         EOF
67         test_cmp expect actual &&
68         git -C "$upstream" show-ref >out &&
69         make_user_friendly_and_stable_output <out >actual &&
70         cat >expect <<-EOF &&
71         <COMMIT-A> refs/heads/main
72         EOF
73         test_cmp expect actual
74 '
75
76 test_expect_success "proc-receive: check remote-tracking #1 ($PROTOCOL)" '
77         git -C workbench show-ref |
78                 grep -v -e refs/remotes -e refs/heads -e refs/tags >out &&
79         make_user_friendly_and_stable_output <out >actual &&
80         cat >expect <<-EOF &&
81         <COMMIT-A> refs/t/changes/24/124/1
82         <COMMIT-B> refs/t/changes/25/125/1
83         <COMMIT-B> refs/t/for/main/topic
84         EOF
85         test_cmp expect actual &&
86         git -C workbench update-ref -d refs/t/for/main/topic &&
87         git -C workbench update-ref -d refs/t/changes/24/124/1 &&
88         git -C workbench update-ref -d refs/t/changes/25/125/1
89 '
90
91 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 2nd rewrite, $PROTOCOL)" '
92         write_script "$upstream/hooks/proc-receive" <<-EOF
93         printf >&2 "# proc-receive hook\n"
94         test-tool proc-receive -v \
95                 -r "ok refs/for/main/topic" \
96                 -r "option refname refs/changes/24/124/1" \
97                 -r "option old-oid $ZERO_OID" \
98                 -r "option new-oid $A" \
99                 -r "ok refs/for/main/topic" \
100                 -r "option old-oid $A" \
101                 -r "option new-oid $B" \
102                 -r "ok refs/for/main/topic" \
103                 -r "option refname refs/changes/25/125/1" \
104                 -r "option old-oid $B" \
105                 -r "option new-oid $A" \
106                 -r "option forced-update"
107         EOF
108 '
109
110 # Refs of upstream : main(A)
111 # Refs of workbench: main(A)  tags/v123
112 # git push         :                       refs/for/main/topic(A)
113 test_expect_success "proc-receive: multiple rewrites for one ref, no refname for the 2nd rewrite ($PROTOCOL)" '
114         git -C workbench push origin \
115                 HEAD:refs/for/main/topic \
116                 >out 2>&1 &&
117         make_user_friendly_and_stable_output <out >actual &&
118         cat >expect <<-EOF &&
119         remote: # pre-receive hook
120         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
121         remote: # proc-receive hook
122         remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
123         remote: proc-receive> ok refs/for/main/topic
124         remote: proc-receive> option refname refs/changes/24/124/1
125         remote: proc-receive> option old-oid <ZERO-OID>
126         remote: proc-receive> option new-oid <COMMIT-A>
127         remote: proc-receive> ok refs/for/main/topic
128         remote: proc-receive> option old-oid <COMMIT-A>
129         remote: proc-receive> option new-oid <COMMIT-B>
130         remote: proc-receive> ok refs/for/main/topic
131         remote: proc-receive> option refname refs/changes/25/125/1
132         remote: proc-receive> option old-oid <COMMIT-B>
133         remote: proc-receive> option new-oid <COMMIT-A>
134         remote: proc-receive> option forced-update
135         remote: # post-receive hook
136         remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1
137         remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/main/topic
138         remote: post-receive< <COMMIT-B> <COMMIT-A> refs/changes/25/125/1
139         To <URL/of/upstream.git>
140          * [new reference] HEAD -> refs/changes/24/124/1
141          <OID-A>..<OID-B> HEAD -> refs/for/main/topic
142          + <OID-B>...<OID-A> HEAD -> refs/changes/25/125/1 (forced update)
143         EOF
144         test_cmp expect actual &&
145         git -C "$upstream" show-ref >out &&
146         make_user_friendly_and_stable_output <out >actual &&
147         cat >expect <<-EOF &&
148         <COMMIT-A> refs/heads/main
149         EOF
150         test_cmp expect actual
151 '
152
153 test_expect_success "proc-receive: check remote-tracking #2 ($PROTOCOL)" '
154         git -C workbench show-ref |
155                 grep -v -e refs/remotes -e refs/heads -e refs/tags >out &&
156         make_user_friendly_and_stable_output <out >actual &&
157         cat >expect <<-EOF &&
158         <COMMIT-A> refs/t/changes/24/124/1
159         <COMMIT-A> refs/t/changes/25/125/1
160         <COMMIT-B> refs/t/for/main/topic
161         EOF
162         test_cmp expect actual &&
163         git -C workbench update-ref -d refs/t/for/main/topic &&
164         git -C workbench update-ref -d refs/t/changes/24/124/1 &&
165         git -C workbench update-ref -d refs/t/changes/25/125/1
166 '
167
168 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, $PROTOCOL)" '
169         write_script "$upstream/hooks/proc-receive" <<-EOF
170         printf >&2 "# proc-receive hook\n"
171         test-tool proc-receive -v \
172                 -r "ok refs/for/main/topic" \
173                 -r "option refname refs/changes/23/123/1" \
174                 -r "ok refs/for/main/topic" \
175                 -r "option refname refs/changes/24/124/2" \
176                 -r "option old-oid $A" \
177                 -r "option new-oid $B"
178         EOF
179 '
180
181 # Refs of upstream : main(A)
182 # Refs of workbench: main(A)  tags/v123
183 # git push         :                       refs/for/main/topic(A)
184 test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL)" '
185         git -C workbench push origin \
186                 HEAD:refs/for/main/topic \
187                 >out 2>&1 &&
188         make_user_friendly_and_stable_output <out >actual &&
189         cat >expect <<-EOF &&
190         remote: # pre-receive hook
191         remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
192         remote: # proc-receive hook
193         remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
194         remote: proc-receive> ok refs/for/main/topic
195         remote: proc-receive> option refname refs/changes/23/123/1
196         remote: proc-receive> ok refs/for/main/topic
197         remote: proc-receive> option refname refs/changes/24/124/2
198         remote: proc-receive> option old-oid <COMMIT-A>
199         remote: proc-receive> option new-oid <COMMIT-B>
200         remote: # post-receive hook
201         remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/23/123/1
202         remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/24/124/2
203         To <URL/of/upstream.git>
204          * [new reference] HEAD -> refs/changes/23/123/1
205          <OID-A>..<OID-B> HEAD -> refs/changes/24/124/2
206         EOF
207         test_cmp expect actual &&
208         git -C "$upstream" show-ref >out &&
209         make_user_friendly_and_stable_output <out >actual &&
210         cat >expect <<-EOF &&
211         <COMMIT-A> refs/heads/main
212         EOF
213         test_cmp expect actual
214 '
215
216 test_expect_success "proc-receive: check remote-tracking #3 ($PROTOCOL)" '
217         git -C workbench show-ref |
218                 grep -v -e refs/remotes -e refs/heads -e refs/tags >out &&
219         make_user_friendly_and_stable_output <out >actual &&
220         cat >expect <<-EOF &&
221         <COMMIT-A> refs/t/changes/23/123/1
222         <COMMIT-B> refs/t/changes/24/124/2
223         EOF
224         test_cmp expect actual &&
225         git -C workbench update-ref -d refs/t/changes/24/124/1 &&
226         git -C workbench update-ref -d refs/t/changes/25/125/2
227 '