unpack-trees: failure to set SKIP_WORKTREE bits always just a warning
[git/raj.git] / t / t5703-upload-pack-ref-in-want.sh
blob7fba3063bf9150687df4bcbd56cdfecf50c8e289
1 #!/bin/sh
3 test_description='upload-pack ref-in-want'
5 . ./test-lib.sh
7 get_actual_refs () {
8 sed -n -e '/wanted-refs/,/0001/{
9 /wanted-refs/d
10 /0001/d
12 }' <out | test-tool pkt-line unpack >actual_refs
15 get_actual_commits () {
16 sed -n -e '/packfile/,/0000/{
17 /packfile/d
19 }' <out | test-tool pkt-line unpack-sideband >o.pack &&
20 git index-pack o.pack &&
21 git verify-pack -v o.idx >objs &&
22 grep commit objs | cut -d" " -f1 | sort >actual_commits
25 check_output () {
26 get_actual_refs &&
27 test_cmp expected_refs actual_refs &&
28 get_actual_commits &&
29 sort expected_commits >sorted_commits &&
30 test_cmp sorted_commits actual_commits
33 # c(o/foo) d(o/bar)
34 # \ /
35 # b e(baz) f(master)
36 # \__ | __/
37 # \ | /
38 # a
39 test_expect_success 'setup repository' '
40 test_oid_init &&
41 test_commit a &&
42 git checkout -b o/foo &&
43 test_commit b &&
44 test_commit c &&
45 git checkout -b o/bar b &&
46 test_commit d &&
47 git checkout -b baz a &&
48 test_commit e &&
49 git checkout master &&
50 test_commit f
53 test_expect_success 'config controls ref-in-want advertisement' '
54 test-tool serve-v2 --advertise-capabilities >out &&
55 ! grep -a ref-in-want out &&
57 git config uploadpack.allowRefInWant false &&
58 test-tool serve-v2 --advertise-capabilities >out &&
59 ! grep -a ref-in-want out &&
61 git config uploadpack.allowRefInWant true &&
62 test-tool serve-v2 --advertise-capabilities >out &&
63 grep -a ref-in-want out
66 test_expect_success 'invalid want-ref line' '
67 test-tool pkt-line pack >in <<-EOF &&
68 command=fetch
69 0001
70 no-progress
71 want-ref refs/heads/non-existent
72 done
73 0000
74 EOF
76 test_must_fail test-tool serve-v2 --stateless-rpc 2>out <in &&
77 grep "unknown ref" out
80 test_expect_success 'basic want-ref' '
81 oid=$(git rev-parse f) &&
82 cat >expected_refs <<-EOF &&
83 $oid refs/heads/master
84 EOF
85 git rev-parse f >expected_commits &&
87 oid=$(git rev-parse a) &&
88 test-tool pkt-line pack >in <<-EOF &&
89 command=fetch
90 0001
91 no-progress
92 want-ref refs/heads/master
93 have $oid
94 done
95 0000
96 EOF
98 test-tool serve-v2 --stateless-rpc >out <in &&
99 check_output
102 test_expect_success 'multiple want-ref lines' '
103 oid_c=$(git rev-parse c) &&
104 oid_d=$(git rev-parse d) &&
105 cat >expected_refs <<-EOF &&
106 $oid_c refs/heads/o/foo
107 $oid_d refs/heads/o/bar
109 git rev-parse c d >expected_commits &&
111 oid=$(git rev-parse b) &&
112 test-tool pkt-line pack >in <<-EOF &&
113 command=fetch
114 0001
115 no-progress
116 want-ref refs/heads/o/foo
117 want-ref refs/heads/o/bar
118 have $oid
119 done
120 0000
123 test-tool serve-v2 --stateless-rpc >out <in &&
124 check_output
127 test_expect_success 'mix want and want-ref' '
128 oid=$(git rev-parse f) &&
129 cat >expected_refs <<-EOF &&
130 $oid refs/heads/master
132 git rev-parse e f >expected_commits &&
134 test-tool pkt-line pack >in <<-EOF &&
135 command=fetch
136 0001
137 no-progress
138 want-ref refs/heads/master
139 want $(git rev-parse e)
140 have $(git rev-parse a)
141 done
142 0000
145 test-tool serve-v2 --stateless-rpc >out <in &&
146 check_output
149 test_expect_success 'want-ref with ref we already have commit for' '
150 oid=$(git rev-parse c) &&
151 cat >expected_refs <<-EOF &&
152 $oid refs/heads/o/foo
154 >expected_commits &&
156 oid=$(git rev-parse c) &&
157 test-tool pkt-line pack >in <<-EOF &&
158 command=fetch
159 0001
160 no-progress
161 want-ref refs/heads/o/foo
162 have $oid
163 done
164 0000
167 test-tool serve-v2 --stateless-rpc >out <in &&
168 check_output
171 REPO="$(pwd)/repo"
172 LOCAL_PRISTINE="$(pwd)/local_pristine"
174 # $REPO
175 # c(o/foo) d(o/bar)
176 # \ /
177 # b e(baz) f(master)
178 # \__ | __/
179 # \ | /
182 # $LOCAL_PRISTINE
183 # s32(side)
188 # a(master)
189 test_expect_success 'setup repos for fetching with ref-in-want tests' '
191 git init "$REPO" &&
192 cd "$REPO" &&
193 test_commit a &&
195 # Local repo with many commits (so that negotiation will take
196 # more than 1 request/response pair)
197 rm -rf "$LOCAL_PRISTINE" &&
198 git clone "file://$REPO" "$LOCAL_PRISTINE" &&
199 cd "$LOCAL_PRISTINE" &&
200 git checkout -b side &&
201 test_commit_bulk --id=s 33 &&
203 # Add novel commits to upstream
204 git checkout master &&
205 cd "$REPO" &&
206 git checkout -b o/foo &&
207 test_commit b &&
208 test_commit c &&
209 git checkout -b o/bar b &&
210 test_commit d &&
211 git checkout -b baz a &&
212 test_commit e &&
213 git checkout master &&
214 test_commit f
215 ) &&
216 git -C "$REPO" config uploadpack.allowRefInWant true &&
217 git -C "$LOCAL_PRISTINE" config protocol.version 2
220 test_expect_success 'fetching with exact OID' '
221 test_when_finished "rm -f log" &&
223 rm -rf local &&
224 cp -r "$LOCAL_PRISTINE" local &&
225 oid=$(git -C "$REPO" rev-parse d) &&
226 GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
227 "$oid":refs/heads/actual &&
229 git -C "$REPO" rev-parse "d" >expected &&
230 git -C local rev-parse refs/heads/actual >actual &&
231 test_cmp expected actual &&
232 grep "want $oid" log
235 test_expect_success 'fetching multiple refs' '
236 test_when_finished "rm -f log" &&
238 rm -rf local &&
239 cp -r "$LOCAL_PRISTINE" local &&
240 GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin master baz &&
242 git -C "$REPO" rev-parse "master" "baz" >expected &&
243 git -C local rev-parse refs/remotes/origin/master refs/remotes/origin/baz >actual &&
244 test_cmp expected actual &&
245 grep "want-ref refs/heads/master" log &&
246 grep "want-ref refs/heads/baz" log
249 test_expect_success 'fetching ref and exact OID' '
250 test_when_finished "rm -f log" &&
252 rm -rf local &&
253 cp -r "$LOCAL_PRISTINE" local &&
254 oid=$(git -C "$REPO" rev-parse b) &&
255 GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
256 master "$oid":refs/heads/actual &&
258 git -C "$REPO" rev-parse "master" "b" >expected &&
259 git -C local rev-parse refs/remotes/origin/master refs/heads/actual >actual &&
260 test_cmp expected actual &&
261 grep "want $oid" log &&
262 grep "want-ref refs/heads/master" log
265 test_expect_success 'fetching with wildcard that does not match any refs' '
266 test_when_finished "rm -f log" &&
268 rm -rf local &&
269 cp -r "$LOCAL_PRISTINE" local &&
270 git -C local fetch origin refs/heads/none*:refs/heads/* >out &&
271 test_must_be_empty out
274 test_expect_success 'fetching with wildcard that matches multiple refs' '
275 test_when_finished "rm -f log" &&
277 rm -rf local &&
278 cp -r "$LOCAL_PRISTINE" local &&
279 GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin refs/heads/o*:refs/heads/o* &&
281 git -C "$REPO" rev-parse "o/foo" "o/bar" >expected &&
282 git -C local rev-parse "o/foo" "o/bar" >actual &&
283 test_cmp expected actual &&
284 grep "want-ref refs/heads/o/foo" log &&
285 grep "want-ref refs/heads/o/bar" log
288 . "$TEST_DIRECTORY"/lib-httpd.sh
289 start_httpd
291 REPO="$HTTPD_DOCUMENT_ROOT_PATH/repo"
292 LOCAL_PRISTINE="$(pwd)/local_pristine"
294 test_expect_success 'setup repos for change-while-negotiating test' '
296 git init "$REPO" &&
297 cd "$REPO" &&
298 >.git/git-daemon-export-ok &&
299 test_commit m1 &&
300 git tag -d m1 &&
302 # Local repo with many commits (so that negotiation will take
303 # more than 1 request/response pair)
304 rm -rf "$LOCAL_PRISTINE" &&
305 git clone "http://127.0.0.1:$LIB_HTTPD_PORT/smart/repo" "$LOCAL_PRISTINE" &&
306 cd "$LOCAL_PRISTINE" &&
307 git checkout -b side &&
308 test_commit_bulk --id=s 33 &&
310 # Add novel commits to upstream
311 git checkout master &&
312 cd "$REPO" &&
313 test_commit m2 &&
314 test_commit m3 &&
315 git tag -d m2 m3
316 ) &&
317 git -C "$LOCAL_PRISTINE" remote set-url origin "http://127.0.0.1:$LIB_HTTPD_PORT/one_time_perl/repo" &&
318 git -C "$LOCAL_PRISTINE" config protocol.version 2
321 inconsistency () {
322 # Simulate that the server initially reports $2 as the ref
323 # corresponding to $1, and after that, $1 as the ref corresponding to
324 # $1. This corresponds to the real-life situation where the server's
325 # repository appears to change during negotiation, for example, when
326 # different servers in a load-balancing arrangement serve (stateless)
327 # RPCs during a single negotiation.
328 oid1=$(git -C "$REPO" rev-parse $1) &&
329 oid2=$(git -C "$REPO" rev-parse $2) &&
330 echo "s/$oid1/$oid2/" >"$HTTPD_ROOT_PATH/one-time-perl"
333 test_expect_success 'server is initially ahead - no ref in want' '
334 git -C "$REPO" config uploadpack.allowRefInWant false &&
335 rm -rf local &&
336 cp -r "$LOCAL_PRISTINE" local &&
337 inconsistency master $(test_oid numeric) &&
338 test_must_fail git -C local fetch 2>err &&
339 test_i18ngrep "fatal: remote error: upload-pack: not our ref" err
342 test_expect_success 'server is initially ahead - ref in want' '
343 git -C "$REPO" config uploadpack.allowRefInWant true &&
344 rm -rf local &&
345 cp -r "$LOCAL_PRISTINE" local &&
346 inconsistency master $(test_oid numeric) &&
347 git -C local fetch &&
349 git -C "$REPO" rev-parse --verify master >expected &&
350 git -C local rev-parse --verify refs/remotes/origin/master >actual &&
351 test_cmp expected actual
354 test_expect_success 'server is initially behind - no ref in want' '
355 git -C "$REPO" config uploadpack.allowRefInWant false &&
356 rm -rf local &&
357 cp -r "$LOCAL_PRISTINE" local &&
358 inconsistency master "master^" &&
359 git -C local fetch &&
361 git -C "$REPO" rev-parse --verify "master^" >expected &&
362 git -C local rev-parse --verify refs/remotes/origin/master >actual &&
363 test_cmp expected actual
366 test_expect_success 'server is initially behind - ref in want' '
367 git -C "$REPO" config uploadpack.allowRefInWant true &&
368 rm -rf local &&
369 cp -r "$LOCAL_PRISTINE" local &&
370 inconsistency master "master^" &&
371 git -C local fetch &&
373 git -C "$REPO" rev-parse --verify "master" >expected &&
374 git -C local rev-parse --verify refs/remotes/origin/master >actual &&
375 test_cmp expected actual
378 test_expect_success 'server loses a ref - ref in want' '
379 git -C "$REPO" config uploadpack.allowRefInWant true &&
380 rm -rf local &&
381 cp -r "$LOCAL_PRISTINE" local &&
382 echo "s/master/raster/" >"$HTTPD_ROOT_PATH/one-time-perl" &&
383 test_must_fail git -C local fetch 2>err &&
385 test_i18ngrep "fatal: remote error: unknown ref refs/heads/raster" err
388 # DO NOT add non-httpd-specific tests here, because the last part of this
389 # test script is only executed when httpd is available and enabled.
391 test_done