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
36 test_expect_success 'setup repository' '
39 git checkout -b o/foo &&
42 git checkout -b o/bar b &&
44 git checkout -b baz a &&
46 git checkout master &&
50 test_expect_success 'config controls ref-in-want advertisement' '
51 test-tool serve-v2 --advertise-capabilities >out &&
52 ! grep -a ref-in-want out &&
54 git config uploadpack.allowRefInWant false &&
55 test-tool serve-v2 --advertise-capabilities >out &&
56 ! grep -a ref-in-want out &&
58 git config uploadpack.allowRefInWant true &&
59 test-tool serve-v2 --advertise-capabilities >out &&
60 grep -a ref-in-want out
63 test_expect_success 'invalid want-ref line' '
64 test-tool pkt-line pack >in <<-EOF &&
68 want-ref refs/heads/non-existent
73 test_must_fail test-tool serve-v2 --stateless-rpc 2>out <in &&
74 grep "unknown ref" out
77 test_expect_success 'basic want-ref' '
78 oid=$(git rev-parse f) &&
79 cat >expected_refs <<-EOF &&
80 $oid refs/heads/master
82 git rev-parse f >expected_commits &&
84 oid=$(git rev-parse a) &&
85 test-tool pkt-line pack >in <<-EOF &&
89 want-ref refs/heads/master
95 test-tool serve-v2 --stateless-rpc >out <in &&
99 test_expect_success 'multiple want-ref lines' '
100 oid_c=$(git rev-parse c) &&
101 oid_d=$(git rev-parse d) &&
102 cat >expected_refs <<-EOF &&
103 $oid_c refs/heads/o/foo
104 $oid_d refs/heads/o/bar
106 git rev-parse c d >expected_commits &&
108 oid=$(git rev-parse b) &&
109 test-tool pkt-line pack >in <<-EOF &&
113 want-ref refs/heads/o/foo
114 want-ref refs/heads/o/bar
120 test-tool serve-v2 --stateless-rpc >out <in &&
124 test_expect_success 'mix want and want-ref' '
125 oid=$(git rev-parse f) &&
126 cat >expected_refs <<-EOF &&
127 $oid refs/heads/master
129 git rev-parse e f >expected_commits &&
131 test-tool pkt-line pack >in <<-EOF &&
135 want-ref refs/heads/master
136 want $(git rev-parse e)
137 have $(git rev-parse a)
142 test-tool serve-v2 --stateless-rpc >out <in &&
146 test_expect_success 'want-ref with ref we already have commit for' '
147 oid=$(git rev-parse c) &&
148 cat >expected_refs <<-EOF &&
149 $oid refs/heads/o/foo
153 oid=$(git rev-parse c) &&
154 test-tool pkt-line pack >in <<-EOF &&
158 want-ref refs/heads/o/foo
164 test-tool serve-v2 --stateless-rpc >out <in &&
169 LOCAL_PRISTINE="$(pwd)/local_pristine"
186 test_expect_success 'setup repos for fetching with ref-in-want tests' '
192 # Local repo with many commits (so that negotiation will take
193 # more than 1 request/response pair)
194 rm -rf "$LOCAL_PRISTINE" &&
195 git clone "file://$REPO" "$LOCAL_PRISTINE" &&
196 cd "$LOCAL_PRISTINE" &&
197 git checkout -b side &&
198 test_commit_bulk --id=s 33 &&
200 # Add novel commits to upstream
201 git checkout master &&
203 git checkout -b o/foo &&
206 git checkout -b o/bar b &&
208 git checkout -b baz a &&
210 git checkout master &&
213 git -C "$REPO" config uploadpack.allowRefInWant true &&
214 git -C "$LOCAL_PRISTINE" config protocol.version 2
217 test_expect_success 'fetching with exact OID' '
218 test_when_finished "rm -f log" &&
221 cp -r "$LOCAL_PRISTINE" local &&
222 oid=$(git -C "$REPO" rev-parse d) &&
223 GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
224 "$oid":refs/heads/actual &&
226 git -C "$REPO" rev-parse "d" >expected &&
227 git -C local rev-parse refs/heads/actual >actual &&
228 test_cmp expected actual &&
232 test_expect_success 'fetching multiple refs' '
233 test_when_finished "rm -f log" &&
236 cp -r "$LOCAL_PRISTINE" local &&
237 GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin master baz &&
239 git -C "$REPO" rev-parse "master" "baz" >expected &&
240 git -C local rev-parse refs/remotes/origin/master refs/remotes/origin/baz >actual &&
241 test_cmp expected actual &&
242 grep "want-ref refs/heads/master" log &&
243 grep "want-ref refs/heads/baz" log
246 test_expect_success 'fetching ref and exact OID' '
247 test_when_finished "rm -f log" &&
250 cp -r "$LOCAL_PRISTINE" local &&
251 oid=$(git -C "$REPO" rev-parse b) &&
252 GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
253 master "$oid":refs/heads/actual &&
255 git -C "$REPO" rev-parse "master" "b" >expected &&
256 git -C local rev-parse refs/remotes/origin/master refs/heads/actual >actual &&
257 test_cmp expected actual &&
258 grep "want $oid" log &&
259 grep "want-ref refs/heads/master" log
262 test_expect_success 'fetching with wildcard that does not match any refs' '
263 test_when_finished "rm -f log" &&
266 cp -r "$LOCAL_PRISTINE" local &&
267 git -C local fetch origin refs/heads/none*:refs/heads/* >out &&
268 test_must_be_empty out
271 test_expect_success 'fetching with wildcard that matches multiple refs' '
272 test_when_finished "rm -f log" &&
275 cp -r "$LOCAL_PRISTINE" local &&
276 GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin refs/heads/o*:refs/heads/o* &&
278 git -C "$REPO" rev-parse "o/foo" "o/bar" >expected &&
279 git -C local rev-parse "o/foo" "o/bar" >actual &&
280 test_cmp expected actual &&
281 grep "want-ref refs/heads/o/foo" log &&
282 grep "want-ref refs/heads/o/bar" log
285 . "$TEST_DIRECTORY"/lib-httpd.sh
288 REPO="$HTTPD_DOCUMENT_ROOT_PATH/repo"
289 LOCAL_PRISTINE="$(pwd)/local_pristine"
291 test_expect_success 'setup repos for change-while-negotiating test' '
295 >.git/git-daemon-export-ok &&
299 # Local repo with many commits (so that negotiation will take
300 # more than 1 request/response pair)
301 rm -rf "$LOCAL_PRISTINE" &&
302 git clone "http://127.0.0.1:$LIB_HTTPD_PORT/smart/repo" "$LOCAL_PRISTINE" &&
303 cd "$LOCAL_PRISTINE" &&
304 git checkout -b side &&
305 test_commit_bulk --id=s 33 &&
307 # Add novel commits to upstream
308 git checkout master &&
314 git -C "$LOCAL_PRISTINE" remote set-url origin "http://127.0.0.1:$LIB_HTTPD_PORT/one_time_perl/repo" &&
315 git -C "$LOCAL_PRISTINE" config protocol.version 2
319 # Simulate that the server initially reports $2 as the ref
320 # corresponding to $1, and after that, $1 as the ref corresponding to
321 # $1. This corresponds to the real-life situation where the server's
322 # repository appears to change during negotiation, for example, when
323 # different servers in a load-balancing arrangement serve (stateless)
324 # RPCs during a single negotiation.
325 oid1=$(git -C "$REPO" rev-parse $1) &&
326 oid2=$(git -C "$REPO" rev-parse $2) &&
327 echo "s/$oid1/$oid2/" >"$HTTPD_ROOT_PATH/one-time-perl"
330 test_expect_success 'server is initially ahead - no ref in want' '
331 git -C "$REPO" config uploadpack.allowRefInWant false &&
333 cp -r "$LOCAL_PRISTINE" local &&
334 inconsistency master $(test_oid numeric) &&
335 test_must_fail git -C local fetch 2>err &&
336 test_i18ngrep "fatal: remote error: upload-pack: not our ref" err
339 test_expect_success 'server is initially ahead - ref in want' '
340 git -C "$REPO" config uploadpack.allowRefInWant true &&
342 cp -r "$LOCAL_PRISTINE" local &&
343 inconsistency master $(test_oid numeric) &&
344 git -C local fetch &&
346 git -C "$REPO" rev-parse --verify master >expected &&
347 git -C local rev-parse --verify refs/remotes/origin/master >actual &&
348 test_cmp expected actual
351 test_expect_success 'server is initially behind - no ref in want' '
352 git -C "$REPO" config uploadpack.allowRefInWant false &&
354 cp -r "$LOCAL_PRISTINE" local &&
355 inconsistency master "master^" &&
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 - ref in want' '
364 git -C "$REPO" config uploadpack.allowRefInWant true &&
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 loses a ref - ref in want' '
376 git -C "$REPO" config uploadpack.allowRefInWant true &&
378 cp -r "$LOCAL_PRISTINE" local &&
379 echo "s/master/raster/" >"$HTTPD_ROOT_PATH/one-time-perl" &&
380 test_must_fail git -C local fetch 2>err &&
382 test_i18ngrep "fatal: remote error: unknown ref refs/heads/raster" err
385 # DO NOT add non-httpd-specific tests here, because the last part of this
386 # test script is only executed when httpd is available and enabled.