t5411: refactor check of refs using test_cmp_refs
[git.git] / t / t5411 / test-0036-report-multi-rewrite-for-one-ref.sh
blobbe9b18b2b69e22ff6dc490a847b0b25c25d099a5
1 test_expect_success "setup git config for remote-tracking of special refs" '
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/*"
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
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 &&
69 test_cmp_refs -C "$upstream" <<-EOF
70 <COMMIT-A> refs/heads/main
71 EOF
74 test_expect_success "proc-receive: check remote-tracking #1 ($PROTOCOL)" '
75 git -C workbench show-ref |
76 grep -v -e refs/remotes -e refs/heads -e refs/tags >out &&
77 make_user_friendly_and_stable_output <out >actual &&
78 cat >expect <<-EOF &&
79 <COMMIT-A> refs/t/changes/24/124/1
80 <COMMIT-B> refs/t/changes/25/125/1
81 <COMMIT-B> refs/t/for/main/topic
82 EOF
83 test_cmp expect actual &&
84 git -C workbench update-ref -d refs/t/for/main/topic &&
85 git -C workbench update-ref -d refs/t/changes/24/124/1 &&
86 git -C workbench update-ref -d refs/t/changes/25/125/1
89 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 2nd rewrite, $PROTOCOL)" '
90 write_script "$upstream/hooks/proc-receive" <<-EOF
91 printf >&2 "# proc-receive hook\n"
92 test-tool proc-receive -v \
93 -r "ok refs/for/main/topic" \
94 -r "option refname refs/changes/24/124/1" \
95 -r "option old-oid $ZERO_OID" \
96 -r "option new-oid $A" \
97 -r "ok refs/for/main/topic" \
98 -r "option old-oid $A" \
99 -r "option new-oid $B" \
100 -r "ok refs/for/main/topic" \
101 -r "option refname refs/changes/25/125/1" \
102 -r "option old-oid $B" \
103 -r "option new-oid $A" \
104 -r "option forced-update"
108 # Refs of upstream : main(A)
109 # Refs of workbench: main(A) tags/v123
110 # git push : refs/for/main/topic(A)
111 test_expect_success "proc-receive: multiple rewrites for one ref, no refname for the 2nd rewrite ($PROTOCOL)" '
112 git -C workbench push origin \
113 HEAD:refs/for/main/topic \
114 >out 2>&1 &&
115 make_user_friendly_and_stable_output <out >actual &&
116 cat >expect <<-EOF &&
117 remote: # pre-receive hook
118 remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
119 remote: # proc-receive hook
120 remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
121 remote: proc-receive> ok refs/for/main/topic
122 remote: proc-receive> option refname refs/changes/24/124/1
123 remote: proc-receive> option old-oid <ZERO-OID>
124 remote: proc-receive> option new-oid <COMMIT-A>
125 remote: proc-receive> ok refs/for/main/topic
126 remote: proc-receive> option old-oid <COMMIT-A>
127 remote: proc-receive> option new-oid <COMMIT-B>
128 remote: proc-receive> ok refs/for/main/topic
129 remote: proc-receive> option refname refs/changes/25/125/1
130 remote: proc-receive> option old-oid <COMMIT-B>
131 remote: proc-receive> option new-oid <COMMIT-A>
132 remote: proc-receive> option forced-update
133 remote: # post-receive hook
134 remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1
135 remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/main/topic
136 remote: post-receive< <COMMIT-B> <COMMIT-A> refs/changes/25/125/1
137 To <URL/of/upstream.git>
138 * [new reference] HEAD -> refs/changes/24/124/1
139 <OID-A>..<OID-B> HEAD -> refs/for/main/topic
140 + <OID-B>...<OID-A> HEAD -> refs/changes/25/125/1 (forced update)
142 test_cmp expect actual &&
144 test_cmp_refs -C "$upstream" <<-EOF
145 <COMMIT-A> refs/heads/main
149 test_expect_success "proc-receive: check remote-tracking #2 ($PROTOCOL)" '
150 git -C workbench show-ref |
151 grep -v -e refs/remotes -e refs/heads -e refs/tags >out &&
152 make_user_friendly_and_stable_output <out >actual &&
153 cat >expect <<-EOF &&
154 <COMMIT-A> refs/t/changes/24/124/1
155 <COMMIT-A> refs/t/changes/25/125/1
156 <COMMIT-B> refs/t/for/main/topic
158 test_cmp expect actual &&
159 git -C workbench update-ref -d refs/t/for/main/topic &&
160 git -C workbench update-ref -d refs/t/changes/24/124/1 &&
161 git -C workbench update-ref -d refs/t/changes/25/125/1
164 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, $PROTOCOL)" '
165 write_script "$upstream/hooks/proc-receive" <<-EOF
166 printf >&2 "# proc-receive hook\n"
167 test-tool proc-receive -v \
168 -r "ok refs/for/main/topic" \
169 -r "option refname refs/changes/23/123/1" \
170 -r "ok refs/for/main/topic" \
171 -r "option refname refs/changes/24/124/2" \
172 -r "option old-oid $A" \
173 -r "option new-oid $B"
177 # Refs of upstream : main(A)
178 # Refs of workbench: main(A) tags/v123
179 # git push : refs/for/main/topic(A)
180 test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL)" '
181 git -C workbench push origin \
182 HEAD:refs/for/main/topic \
183 >out 2>&1 &&
184 make_user_friendly_and_stable_output <out >actual &&
185 cat >expect <<-EOF &&
186 remote: # pre-receive hook
187 remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
188 remote: # proc-receive hook
189 remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
190 remote: proc-receive> ok refs/for/main/topic
191 remote: proc-receive> option refname refs/changes/23/123/1
192 remote: proc-receive> ok refs/for/main/topic
193 remote: proc-receive> option refname refs/changes/24/124/2
194 remote: proc-receive> option old-oid <COMMIT-A>
195 remote: proc-receive> option new-oid <COMMIT-B>
196 remote: # post-receive hook
197 remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/23/123/1
198 remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/24/124/2
199 To <URL/of/upstream.git>
200 * [new reference] HEAD -> refs/changes/23/123/1
201 <OID-A>..<OID-B> HEAD -> refs/changes/24/124/2
203 test_cmp expect actual &&
205 test_cmp_refs -C "$upstream" <<-EOF
206 <COMMIT-A> refs/heads/main
210 test_expect_success "proc-receive: check remote-tracking #3 ($PROTOCOL)" '
211 git -C workbench show-ref |
212 grep -v -e refs/remotes -e refs/heads -e refs/tags >out &&
213 make_user_friendly_and_stable_output <out >actual &&
214 cat >expect <<-EOF &&
215 <COMMIT-A> refs/t/changes/23/123/1
216 <COMMIT-B> refs/t/changes/24/124/2
218 test_cmp expect actual &&
219 git -C workbench update-ref -d refs/t/changes/24/124/1 &&
220 git -C workbench update-ref -d refs/t/changes/25/125/2