]> git.ipfire.org Git - thirdparty/git.git/blob - t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh
Merge branch 'ew/midx-doc-update'
[thirdparty/git.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 format_and_save_expect <<-EOF &&
43 > remote: # pre-receive hook Z
44 > remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic Z
45 > remote: # proc-receive hook Z
46 > remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic Z
47 > remote: proc-receive> ok refs/for/main/topic Z
48 > remote: proc-receive> option old-oid <COMMIT-A> Z
49 > remote: proc-receive> option new-oid <COMMIT-B> Z
50 > remote: proc-receive> ok refs/for/main/topic Z
51 > remote: proc-receive> option refname refs/changes/24/124/1 Z
52 > remote: proc-receive> option old-oid <ZERO-OID> Z
53 > remote: proc-receive> option new-oid <COMMIT-A> Z
54 > remote: proc-receive> ok refs/for/main/topic Z
55 > remote: proc-receive> option refname refs/changes/25/125/1 Z
56 > remote: proc-receive> option old-oid <COMMIT-A> Z
57 > remote: proc-receive> option new-oid <COMMIT-B> Z
58 > remote: # post-receive hook Z
59 > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/main/topic Z
60 > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1 Z
61 > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/25/125/1 Z
62 > To <URL/of/upstream.git>
63 > <COMMIT-A>..<COMMIT-B> HEAD -> refs/for/main/topic
64 > * [new reference] HEAD -> refs/changes/24/124/1
65 > <COMMIT-A>..<COMMIT-B> HEAD -> refs/changes/25/125/1
66 EOF
67 test_cmp expect actual &&
68
69 test_cmp_refs -C "$upstream" <<-EOF
70 <COMMIT-A> refs/heads/main
71 EOF
72 '
73
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
87 '
88
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"
105 EOF
106 '
107
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 format_and_save_expect <<-EOF &&
117 > remote: # pre-receive hook Z
118 > remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic Z
119 > remote: # proc-receive hook Z
120 > remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic Z
121 > remote: proc-receive> ok refs/for/main/topic Z
122 > remote: proc-receive> option refname refs/changes/24/124/1 Z
123 > remote: proc-receive> option old-oid <ZERO-OID> Z
124 > remote: proc-receive> option new-oid <COMMIT-A> Z
125 > remote: proc-receive> ok refs/for/main/topic Z
126 > remote: proc-receive> option old-oid <COMMIT-A> Z
127 > remote: proc-receive> option new-oid <COMMIT-B> Z
128 > remote: proc-receive> ok refs/for/main/topic Z
129 > remote: proc-receive> option refname refs/changes/25/125/1 Z
130 > remote: proc-receive> option old-oid <COMMIT-B> Z
131 > remote: proc-receive> option new-oid <COMMIT-A> Z
132 > remote: proc-receive> option forced-update Z
133 > remote: # post-receive hook Z
134 > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1 Z
135 > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/main/topic Z
136 > remote: post-receive< <COMMIT-B> <COMMIT-A> refs/changes/25/125/1 Z
137 > To <URL/of/upstream.git>
138 > * [new reference] HEAD -> refs/changes/24/124/1
139 > <COMMIT-A>..<COMMIT-B> HEAD -> refs/for/main/topic
140 > + <COMMIT-B>...<COMMIT-A> HEAD -> refs/changes/25/125/1 (forced update)
141 EOF
142 test_cmp expect actual &&
143
144 test_cmp_refs -C "$upstream" <<-EOF
145 <COMMIT-A> refs/heads/main
146 EOF
147 '
148
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
157 EOF
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
162 '
163
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"
174 EOF
175 '
176
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 format_and_save_expect <<-EOF &&
186 > remote: # pre-receive hook Z
187 > remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic Z
188 > remote: # proc-receive hook Z
189 > remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic Z
190 > remote: proc-receive> ok refs/for/main/topic Z
191 > remote: proc-receive> option refname refs/changes/23/123/1 Z
192 > remote: proc-receive> ok refs/for/main/topic Z
193 > remote: proc-receive> option refname refs/changes/24/124/2 Z
194 > remote: proc-receive> option old-oid <COMMIT-A> Z
195 > remote: proc-receive> option new-oid <COMMIT-B> Z
196 > remote: # post-receive hook Z
197 > remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/23/123/1 Z
198 > remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/24/124/2 Z
199 > To <URL/of/upstream.git>
200 > * [new reference] HEAD -> refs/changes/23/123/1
201 > <COMMIT-A>..<COMMIT-B> HEAD -> refs/changes/24/124/2
202 EOF
203 test_cmp expect actual &&
204
205 test_cmp_refs -C "$upstream" <<-EOF
206 <COMMIT-A> refs/heads/main
207 EOF
208 '
209
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
217 EOF
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
221 '