3 test_description
='upload-pack ref-in-want'
8 sed -n -e '/wanted-refs/,/0001/{
12 }' <out | test-tool pkt-line unpack
>actual_refs
15 get_actual_commits
() {
16 sed -n -e '/packfile/,/0000/{
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
27 test_cmp expected_refs actual_refs
&&
29 sort expected_commits
>sorted_commits
&&
30 test_cmp sorted_commits actual_commits
39 test_expect_success
'setup repository' '
42 git checkout -b o/foo &&
45 git checkout -b o/bar b &&
47 git checkout -b baz a &&
49 git checkout master &&
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 &&
71 want-ref refs/heads/non-existent
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
85 git rev-parse f >expected_commits &&
87 oid=$(git rev-parse a) &&
88 test-tool pkt-line pack >in <<-EOF &&
92 want-ref refs/heads/master
98 test-tool serve-v2 --stateless-rpc >out <in &&
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 &&
116 want-ref refs/heads/o/foo
117 want-ref refs/heads/o/bar
123 test-tool serve-v2 --stateless-rpc >out <in &&
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 &&
138 want-ref refs/heads/master
139 want $(git rev-parse e)
140 have $(git rev-parse a)
145 test-tool serve-v2 --stateless-rpc >out <in &&
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
156 oid=$(git rev-parse c) &&
157 test-tool pkt-line pack >in <<-EOF &&
161 want-ref refs/heads/o/foo
167 test-tool serve-v2 --stateless-rpc >out <in &&
172 LOCAL_PRISTINE
="$(pwd)/local_pristine"
189 test_expect_success
'setup repos for fetching with ref-in-want tests' '
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 &&
206 git checkout -b o/foo &&
209 git checkout -b o/bar b &&
211 git checkout -b baz a &&
213 git checkout master &&
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" &&
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 &&
235 test_expect_success
'fetching multiple refs' '
236 test_when_finished "rm -f log" &&
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" &&
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" &&
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" &&
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
291 REPO
="$HTTPD_DOCUMENT_ROOT_PATH/repo"
292 LOCAL_PRISTINE
="$(pwd)/local_pristine"
294 test_expect_success
'setup repos for change-while-negotiating test' '
298 >.git/git-daemon-export-ok &&
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 &&
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
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 &&
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 &&
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 &&
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 &&
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 &&
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.