1 test_expect_success "setup git config for remote-tracking of special refs" '
4 if ! git config --get-all remote.origin.fetch | grep refs/for/
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/master/topic" \
21 -r "option old-oid $A" \
22 -r "option new-oid $B" \
23 -r "ok refs/for/master/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/master/topic" \
28 -r "option refname refs/changes/25/125/1" \
29 -r "option old-oid $A" \
30 -r "option new-oid $B"
34 # Refs of upstream : master(A)
35 # Refs of workbench: master(A) tags/v123
36 # git push : refs/for/master/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/master/topic \
41 make_user_friendly_and_stable_output <out >actual &&
43 remote: # pre-receive hook
44 remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
45 remote: # proc-receive hook
46 remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
47 remote: proc-receive> ok refs/for/master/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/master/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/master/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/master/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/master/topic
64 * [new reference] HEAD -> refs/changes/24/124/1
65 <OID-A>..<OID-B> HEAD -> refs/changes/25/125/1
67 test_cmp expect actual &&
68 git -C "$upstream" show-ref >out &&
69 make_user_friendly_and_stable_output <out >actual &&
71 <COMMIT-A> refs/heads/master
73 test_cmp expect actual
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 &&
81 <COMMIT-A> refs/t/changes/24/124/1
82 <COMMIT-B> refs/t/changes/25/125/1
83 <COMMIT-B> refs/t/for/master/topic
85 test_cmp expect actual &&
86 git -C workbench update-ref -d refs/t/for/master/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
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/master/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/master/topic" \
100 -r "option old-oid $A" \
101 -r "option new-oid $B" \
102 -r "ok refs/for/master/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"
110 # Refs of upstream : master(A)
111 # Refs of workbench: master(A) tags/v123
112 # git push : refs/for/master/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/master/topic \
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/master/topic
121 remote: # proc-receive hook
122 remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
123 remote: proc-receive> ok refs/for/master/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/master/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/master/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/master/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/master/topic
142 + <OID-B>...<OID-A> HEAD -> refs/changes/25/125/1 (forced update)
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/master
150 test_cmp expect actual
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/master/topic
162 test_cmp expect actual &&
163 git -C workbench update-ref -d refs/t/for/master/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
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/master/topic" \
173 -r "option refname refs/changes/23/123/1" \
174 -r "ok refs/for/master/topic" \
175 -r "option refname refs/changes/24/124/2" \
176 -r "option old-oid $A" \
177 -r "option new-oid $B"
181 # Refs of upstream : master(A)
182 # Refs of workbench: master(A) tags/v123
183 # git push : refs/for/master/topic(A)
184 test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL)" '
185 git -C workbench push origin \
186 HEAD:refs/for/master/topic \
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/master/topic
192 remote: # proc-receive hook
193 remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
194 remote: proc-receive> ok refs/for/master/topic
195 remote: proc-receive> option refname refs/changes/23/123/1
196 remote: proc-receive> ok refs/for/master/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
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/master
213 test_cmp expect actual
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
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