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 test-tool pkt-line unpack-sideband
<out
>o.pack
&&
17 git index-pack o.pack
&&
18 git verify-pack
-v o.idx
>objs
&&
19 grep commit objs | cut
-d" " -f1 |
sort >actual_commits
24 test_cmp expected_refs actual_refs
&&
26 sort expected_commits
>sorted_commits
&&
27 test_cmp sorted_commits actual_commits
33 if test "$(test_oid algo)" != sha1
35 echo "object-format=$(test_oid algo)"
45 test_expect_success
'setup repository' '
48 git checkout -b o/foo &&
51 git checkout -b o/bar b &&
53 git checkout -b baz a &&
55 git checkout master &&
59 test_expect_success
'config controls ref-in-want advertisement' '
60 test-tool serve-v2 --advertise-capabilities >out &&
61 perl -ne "/ref-in-want/ and print" out >out.filter &&
62 test_must_be_empty out.filter &&
64 git config uploadpack.allowRefInWant false &&
65 test-tool serve-v2 --advertise-capabilities >out &&
66 perl -ne "/ref-in-want/ and print" out >out.filter &&
67 test_must_be_empty out.filter &&
69 git config uploadpack.allowRefInWant true &&
70 test-tool serve-v2 --advertise-capabilities >out &&
71 perl -ne "/ref-in-want/ and print" out >out.filter &&
72 test_file_not_empty out.filter
75 test_expect_success
'invalid want-ref line' '
76 test-tool pkt-line pack >in <<-EOF &&
77 $(write_command fetch)
80 want-ref refs/heads/non-existent
85 test_must_fail test-tool serve-v2 --stateless-rpc 2>out <in &&
86 grep "unknown ref" out
89 test_expect_success
'basic want-ref' '
90 oid=$(git rev-parse f) &&
91 cat >expected_refs <<-EOF &&
92 $oid refs/heads/master
94 git rev-parse f >expected_commits &&
96 oid=$(git rev-parse a) &&
97 test-tool pkt-line pack >in <<-EOF &&
98 $(write_command fetch)
101 want-ref refs/heads/master
107 test-tool serve-v2 --stateless-rpc >out <in &&
111 test_expect_success
'multiple want-ref lines' '
112 oid_c=$(git rev-parse c) &&
113 oid_d=$(git rev-parse d) &&
114 cat >expected_refs <<-EOF &&
115 $oid_c refs/heads/o/foo
116 $oid_d refs/heads/o/bar
118 git rev-parse c d >expected_commits &&
120 oid=$(git rev-parse b) &&
121 test-tool pkt-line pack >in <<-EOF &&
122 $(write_command fetch)
125 want-ref refs/heads/o/foo
126 want-ref refs/heads/o/bar
132 test-tool serve-v2 --stateless-rpc >out <in &&
136 test_expect_success
'mix want and want-ref' '
137 oid=$(git rev-parse f) &&
138 cat >expected_refs <<-EOF &&
139 $oid refs/heads/master
141 git rev-parse e f >expected_commits &&
143 test-tool pkt-line pack >in <<-EOF &&
144 $(write_command fetch)
147 want-ref refs/heads/master
148 want $(git rev-parse e)
149 have $(git rev-parse a)
154 test-tool serve-v2 --stateless-rpc >out <in &&
158 test_expect_success
'want-ref with ref we already have commit for' '
159 oid=$(git rev-parse c) &&
160 cat >expected_refs <<-EOF &&
161 $oid refs/heads/o/foo
165 oid=$(git rev-parse c) &&
166 test-tool pkt-line pack >in <<-EOF &&
167 $(write_command fetch)
170 want-ref refs/heads/o/foo
176 test-tool serve-v2 --stateless-rpc >out <in &&
181 LOCAL_PRISTINE
="$(pwd)/local_pristine"
198 test_expect_success
'setup repos for fetching with ref-in-want tests' '
204 # Local repo with many commits (so that negotiation will take
205 # more than 1 request/response pair)
206 rm -rf "$LOCAL_PRISTINE" &&
207 git clone "file://$REPO" "$LOCAL_PRISTINE" &&
208 cd "$LOCAL_PRISTINE" &&
209 git checkout -b side &&
210 test_commit_bulk --id=s 33 &&
212 # Add novel commits to upstream
213 git checkout master &&
215 git checkout -b o/foo &&
218 git checkout -b o/bar b &&
220 git checkout -b baz a &&
222 git checkout master &&
225 git -C "$REPO" config uploadpack.allowRefInWant true &&
226 git -C "$LOCAL_PRISTINE" config protocol.version 2
229 test_expect_success
'fetching with exact OID' '
230 test_when_finished "rm -f log" &&
233 cp -r "$LOCAL_PRISTINE" local &&
234 oid=$(git -C "$REPO" rev-parse d) &&
235 GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
236 "$oid":refs/heads/actual &&
238 git -C "$REPO" rev-parse "d" >expected &&
239 git -C local rev-parse refs/heads/actual >actual &&
240 test_cmp expected actual &&
244 test_expect_success
'fetching multiple refs' '
245 test_when_finished "rm -f log" &&
248 cp -r "$LOCAL_PRISTINE" local &&
249 GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin master baz &&
251 git -C "$REPO" rev-parse "master" "baz" >expected &&
252 git -C local rev-parse refs/remotes/origin/master refs/remotes/origin/baz >actual &&
253 test_cmp expected actual &&
254 grep "want-ref refs/heads/master" log &&
255 grep "want-ref refs/heads/baz" log
258 test_expect_success
'fetching ref and exact OID' '
259 test_when_finished "rm -f log" &&
262 cp -r "$LOCAL_PRISTINE" local &&
263 oid=$(git -C "$REPO" rev-parse b) &&
264 GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
265 master "$oid":refs/heads/actual &&
267 git -C "$REPO" rev-parse "master" "b" >expected &&
268 git -C local rev-parse refs/remotes/origin/master refs/heads/actual >actual &&
269 test_cmp expected actual &&
270 grep "want $oid" log &&
271 grep "want-ref refs/heads/master" log
274 test_expect_success
'fetching with wildcard that does not match any refs' '
275 test_when_finished "rm -f log" &&
278 cp -r "$LOCAL_PRISTINE" local &&
279 git -C local fetch origin refs/heads/none*:refs/heads/* >out &&
280 test_must_be_empty out
283 test_expect_success
'fetching with wildcard that matches multiple refs' '
284 test_when_finished "rm -f log" &&
287 cp -r "$LOCAL_PRISTINE" local &&
288 GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin refs/heads/o*:refs/heads/o* &&
290 git -C "$REPO" rev-parse "o/foo" "o/bar" >expected &&
291 git -C local rev-parse "o/foo" "o/bar" >actual &&
292 test_cmp expected actual &&
293 grep "want-ref refs/heads/o/foo" log &&
294 grep "want-ref refs/heads/o/bar" log
297 .
"$TEST_DIRECTORY"/lib-httpd.sh
300 REPO
="$HTTPD_DOCUMENT_ROOT_PATH/repo"
301 LOCAL_PRISTINE
="$(pwd)/local_pristine"
303 test_expect_success
'setup repos for change-while-negotiating test' '
307 >.git/git-daemon-export-ok &&
311 # Local repo with many commits (so that negotiation will take
312 # more than 1 request/response pair)
313 rm -rf "$LOCAL_PRISTINE" &&
314 git clone "http://127.0.0.1:$LIB_HTTPD_PORT/smart/repo" "$LOCAL_PRISTINE" &&
315 cd "$LOCAL_PRISTINE" &&
316 git checkout -b side &&
317 test_commit_bulk --id=s 33 &&
319 # Add novel commits to upstream
320 git checkout master &&
326 git -C "$LOCAL_PRISTINE" remote set-url origin "http://127.0.0.1:$LIB_HTTPD_PORT/one_time_perl/repo" &&
327 git -C "$LOCAL_PRISTINE" config protocol.version 2
331 # Simulate that the server initially reports $2 as the ref
332 # corresponding to $1, and after that, $1 as the ref corresponding to
333 # $1. This corresponds to the real-life situation where the server's
334 # repository appears to change during negotiation, for example, when
335 # different servers in a load-balancing arrangement serve (stateless)
336 # RPCs during a single negotiation.
337 oid1
=$
(git
-C "$REPO" rev-parse
$1) &&
338 oid2
=$
(git
-C "$REPO" rev-parse
$2) &&
339 echo "s/$oid1/$oid2/" >"$HTTPD_ROOT_PATH/one-time-perl"
342 test_expect_success
'server is initially ahead - no ref in want' '
343 git -C "$REPO" config uploadpack.allowRefInWant false &&
345 cp -r "$LOCAL_PRISTINE" local &&
346 inconsistency master $(test_oid numeric) &&
347 test_must_fail git -C local fetch 2>err &&
348 test_i18ngrep "fatal: remote error: upload-pack: not our ref" err
351 test_expect_success
'server is initially ahead - ref in want' '
352 git -C "$REPO" config uploadpack.allowRefInWant true &&
354 cp -r "$LOCAL_PRISTINE" local &&
355 inconsistency master $(test_oid numeric) &&
356 git -C local fetch &&
358 git -C "$REPO" rev-parse --verify master >expected &&
359 git -C local rev-parse --verify refs/remotes/origin/master >actual &&
360 test_cmp expected actual
363 test_expect_success
'server is initially behind - no ref in want' '
364 git -C "$REPO" config uploadpack.allowRefInWant false &&
366 cp -r "$LOCAL_PRISTINE" local &&
367 inconsistency master "master^" &&
368 git -C local fetch &&
370 git -C "$REPO" rev-parse --verify "master^" >expected &&
371 git -C local rev-parse --verify refs/remotes/origin/master >actual &&
372 test_cmp expected actual
375 test_expect_success
'server is initially behind - ref in want' '
376 git -C "$REPO" config uploadpack.allowRefInWant true &&
378 cp -r "$LOCAL_PRISTINE" local &&
379 inconsistency master "master^" &&
380 git -C local fetch &&
382 git -C "$REPO" rev-parse --verify "master" >expected &&
383 git -C local rev-parse --verify refs/remotes/origin/master >actual &&
384 test_cmp expected actual
387 test_expect_success
'server loses a ref - ref in want' '
388 git -C "$REPO" config uploadpack.allowRefInWant true &&
390 cp -r "$LOCAL_PRISTINE" local &&
391 echo "s/master/raster/" >"$HTTPD_ROOT_PATH/one-time-perl" &&
392 test_must_fail git -C local fetch 2>err &&
394 test_i18ngrep "fatal: remote error: unknown ref refs/heads/raster" err
397 # DO NOT add non-httpd-specific tests here, because the last part of this
398 # test script is only executed when httpd is available and enabled.