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 ! grep -a ref-in-want out &&
63 git config uploadpack.allowRefInWant false &&
64 test-tool serve-v2 --advertise-capabilities >out &&
65 ! grep -a ref-in-want out &&
67 git config uploadpack.allowRefInWant true &&
68 test-tool serve-v2 --advertise-capabilities >out &&
69 grep -a ref-in-want out
72 test_expect_success 'invalid want-ref line' '
73 test-tool pkt-line pack >in <<-EOF &&
74 $(write_command fetch)
77 want-ref refs/heads/non-existent
82 test_must_fail test-tool serve-v2 --stateless-rpc 2>out <in &&
83 grep "unknown ref" out
86 test_expect_success 'basic want-ref' '
87 oid=$(git rev-parse f) &&
88 cat >expected_refs <<-EOF &&
89 $oid refs/heads/master
91 git rev-parse f >expected_commits &&
93 oid=$(git rev-parse a) &&
94 test-tool pkt-line pack >in <<-EOF &&
95 $(write_command fetch)
98 want-ref refs/heads/master
104 test-tool serve-v2 --stateless-rpc >out <in &&
108 test_expect_success 'multiple want-ref lines' '
109 oid_c=$(git rev-parse c) &&
110 oid_d=$(git rev-parse d) &&
111 cat >expected_refs <<-EOF &&
112 $oid_c refs/heads/o/foo
113 $oid_d refs/heads/o/bar
115 git rev-parse c d >expected_commits &&
117 oid=$(git rev-parse b) &&
118 test-tool pkt-line pack >in <<-EOF &&
119 $(write_command fetch)
122 want-ref refs/heads/o/foo
123 want-ref refs/heads/o/bar
129 test-tool serve-v2 --stateless-rpc >out <in &&
133 test_expect_success 'mix want and want-ref' '
134 oid=$(git rev-parse f) &&
135 cat >expected_refs <<-EOF &&
136 $oid refs/heads/master
138 git rev-parse e f >expected_commits &&
140 test-tool pkt-line pack >in <<-EOF &&
141 $(write_command fetch)
144 want-ref refs/heads/master
145 want $(git rev-parse e)
146 have $(git rev-parse a)
151 test-tool serve-v2 --stateless-rpc >out <in &&
155 test_expect_success 'want-ref with ref we already have commit for' '
156 oid=$(git rev-parse c) &&
157 cat >expected_refs <<-EOF &&
158 $oid refs/heads/o/foo
162 oid=$(git rev-parse c) &&
163 test-tool pkt-line pack >in <<-EOF &&
164 $(write_command fetch)
167 want-ref refs/heads/o/foo
173 test-tool serve-v2 --stateless-rpc >out <in &&
178 LOCAL_PRISTINE="$(pwd)/local_pristine"
195 test_expect_success 'setup repos for fetching with ref-in-want tests' '
201 # Local repo with many commits (so that negotiation will take
202 # more than 1 request/response pair)
203 rm -rf "$LOCAL_PRISTINE" &&
204 git clone "file://$REPO" "$LOCAL_PRISTINE" &&
205 cd "$LOCAL_PRISTINE" &&
206 git checkout -b side &&
207 test_commit_bulk --id=s 33 &&
209 # Add novel commits to upstream
210 git checkout master &&
212 git checkout -b o/foo &&
215 git checkout -b o/bar b &&
217 git checkout -b baz a &&
219 git checkout master &&
222 git -C "$REPO" config uploadpack.allowRefInWant true &&
223 git -C "$LOCAL_PRISTINE" config protocol.version 2
226 test_expect_success 'fetching with exact OID' '
227 test_when_finished "rm -f log" &&
230 cp -r "$LOCAL_PRISTINE" local &&
231 oid=$(git -C "$REPO" rev-parse d) &&
232 GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
233 "$oid":refs/heads/actual &&
235 git -C "$REPO" rev-parse "d" >expected &&
236 git -C local rev-parse refs/heads/actual >actual &&
237 test_cmp expected actual &&
241 test_expect_success 'fetching multiple refs' '
242 test_when_finished "rm -f log" &&
245 cp -r "$LOCAL_PRISTINE" local &&
246 GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin master baz &&
248 git -C "$REPO" rev-parse "master" "baz" >expected &&
249 git -C local rev-parse refs/remotes/origin/master refs/remotes/origin/baz >actual &&
250 test_cmp expected actual &&
251 grep "want-ref refs/heads/master" log &&
252 grep "want-ref refs/heads/baz" log
255 test_expect_success 'fetching ref and exact OID' '
256 test_when_finished "rm -f log" &&
259 cp -r "$LOCAL_PRISTINE" local &&
260 oid=$(git -C "$REPO" rev-parse b) &&
261 GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
262 master "$oid":refs/heads/actual &&
264 git -C "$REPO" rev-parse "master" "b" >expected &&
265 git -C local rev-parse refs/remotes/origin/master refs/heads/actual >actual &&
266 test_cmp expected actual &&
267 grep "want $oid" log &&
268 grep "want-ref refs/heads/master" log
271 test_expect_success 'fetching with wildcard that does not match any refs' '
272 test_when_finished "rm -f log" &&
275 cp -r "$LOCAL_PRISTINE" local &&
276 git -C local fetch origin refs/heads/none*:refs/heads/* >out &&
277 test_must_be_empty out
280 test_expect_success 'fetching with wildcard that matches multiple refs' '
281 test_when_finished "rm -f log" &&
284 cp -r "$LOCAL_PRISTINE" local &&
285 GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin refs/heads/o*:refs/heads/o* &&
287 git -C "$REPO" rev-parse "o/foo" "o/bar" >expected &&
288 git -C local rev-parse "o/foo" "o/bar" >actual &&
289 test_cmp expected actual &&
290 grep "want-ref refs/heads/o/foo" log &&
291 grep "want-ref refs/heads/o/bar" log
294 . "$TEST_DIRECTORY"/lib-httpd.sh
297 REPO="$HTTPD_DOCUMENT_ROOT_PATH/repo"
298 LOCAL_PRISTINE="$(pwd)/local_pristine"
300 test_expect_success 'setup repos for change-while-negotiating test' '
304 >.git/git-daemon-export-ok &&
308 # Local repo with many commits (so that negotiation will take
309 # more than 1 request/response pair)
310 rm -rf "$LOCAL_PRISTINE" &&
311 git clone "http://127.0.0.1:$LIB_HTTPD_PORT/smart/repo" "$LOCAL_PRISTINE" &&
312 cd "$LOCAL_PRISTINE" &&
313 git checkout -b side &&
314 test_commit_bulk --id=s 33 &&
316 # Add novel commits to upstream
317 git checkout master &&
323 git -C "$LOCAL_PRISTINE" remote set-url origin "http://127.0.0.1:$LIB_HTTPD_PORT/one_time_perl/repo" &&
324 git -C "$LOCAL_PRISTINE" config protocol.version 2
328 # Simulate that the server initially reports $2 as the ref
329 # corresponding to $1, and after that, $1 as the ref corresponding to
330 # $1. This corresponds to the real-life situation where the server's
331 # repository appears to change during negotiation, for example, when
332 # different servers in a load-balancing arrangement serve (stateless)
333 # RPCs during a single negotiation.
334 oid1=$(git -C "$REPO" rev-parse $1) &&
335 oid2=$(git -C "$REPO" rev-parse $2) &&
336 echo "s/$oid1/$oid2/" >"$HTTPD_ROOT_PATH/one-time-perl"
339 test_expect_success 'server is initially ahead - no ref in want' '
340 git -C "$REPO" config uploadpack.allowRefInWant false &&
342 cp -r "$LOCAL_PRISTINE" local &&
343 inconsistency master $(test_oid numeric) &&
344 test_must_fail git -C local fetch 2>err &&
345 test_i18ngrep "fatal: remote error: upload-pack: not our ref" err
348 test_expect_success 'server is initially ahead - ref in want' '
349 git -C "$REPO" config uploadpack.allowRefInWant true &&
351 cp -r "$LOCAL_PRISTINE" local &&
352 inconsistency master $(test_oid numeric) &&
353 git -C local fetch &&
355 git -C "$REPO" rev-parse --verify master >expected &&
356 git -C local rev-parse --verify refs/remotes/origin/master >actual &&
357 test_cmp expected actual
360 test_expect_success 'server is initially behind - no ref in want' '
361 git -C "$REPO" config uploadpack.allowRefInWant false &&
363 cp -r "$LOCAL_PRISTINE" local &&
364 inconsistency master "master^" &&
365 git -C local fetch &&
367 git -C "$REPO" rev-parse --verify "master^" >expected &&
368 git -C local rev-parse --verify refs/remotes/origin/master >actual &&
369 test_cmp expected actual
372 test_expect_success 'server is initially behind - ref in want' '
373 git -C "$REPO" config uploadpack.allowRefInWant true &&
375 cp -r "$LOCAL_PRISTINE" local &&
376 inconsistency master "master^" &&
377 git -C local fetch &&
379 git -C "$REPO" rev-parse --verify "master" >expected &&
380 git -C local rev-parse --verify refs/remotes/origin/master >actual &&
381 test_cmp expected actual
384 test_expect_success 'server loses a ref - ref in want' '
385 git -C "$REPO" config uploadpack.allowRefInWant true &&
387 cp -r "$LOCAL_PRISTINE" local &&
388 echo "s/master/raster/" >"$HTTPD_ROOT_PATH/one-time-perl" &&
389 test_must_fail git -C local fetch 2>err &&
391 test_i18ngrep "fatal: remote error: unknown ref refs/heads/raster" err
394 # DO NOT add non-httpd-specific tests here, because the last part of this
395 # test script is only executed when httpd is available and enabled.