]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5616-partial-clone.sh
Merge branch 'ug/doc-lose-dircache' into maint
[thirdparty/git.git] / t / t5616-partial-clone.sh
CommitLineData
35a7ae95
JH
1#!/bin/sh
2
3test_description='git partial clone'
4
5. ./test-lib.sh
6
7# create a normal "src" repo where we can later create new commits.
8# expect_1.oids will contain a list of the OIDs of all blobs.
9test_expect_success 'setup normal src repo' '
10 echo "{print \$1}" >print_1.awk &&
11 echo "{print \$2}" >print_2.awk &&
12
13 git init src &&
14 for n in 1 2 3 4
15 do
16 echo "This is file: $n" > src/file.$n.txt
17 git -C src add file.$n.txt
18 git -C src commit -m "file $n"
19 git -C src ls-files -s file.$n.txt >>temp
20 done &&
21 awk -f print_2.awk <temp | sort >expect_1.oids &&
22 test_line_count = 4 expect_1.oids
23'
24
25# bare clone "src" giving "srv.bare" for use as our server.
26test_expect_success 'setup bare clone for server' '
27 git clone --bare "file://$(pwd)/src" srv.bare &&
28 git -C srv.bare config --local uploadpack.allowfilter 1 &&
29 git -C srv.bare config --local uploadpack.allowanysha1inwant 1
30'
31
32# do basic partial clone from "srv.bare"
33# confirm we are missing all of the known blobs.
34# confirm partial clone was registered in the local config.
35test_expect_success 'do partial clone 1' '
36 git clone --no-checkout --filter=blob:none "file://$(pwd)/srv.bare" pc1 &&
bdbc17e8 37
8d6ba495 38 git -C pc1 rev-list --quiet --objects --missing=print HEAD >revs &&
61de0ff6 39 awk -f print_1.awk revs |
bdbc17e8
MD
40 sed "s/?//" |
41 sort >observed.oids &&
42
35a7ae95
JH
43 test_cmp expect_1.oids observed.oids &&
44 test "$(git -C pc1 config --local core.repositoryformatversion)" = "1" &&
b14ed5ad 45 test "$(git -C pc1 config --local remote.origin.promisor)" = "true" &&
fa3d1b63 46 test "$(git -C pc1 config --local remote.origin.partialclonefilter)" = "blob:none"
35a7ae95
JH
47'
48
5374a290
JT
49test_expect_success 'verify that .promisor file contains refs fetched' '
50 ls pc1/.git/objects/pack/pack-*.promisor >promisorlist &&
51 test_line_count = 1 promisorlist &&
6c28bef2 52 git -C srv.bare rev-parse --verify HEAD >headhash &&
5374a290
JT
53 grep "$(cat headhash) HEAD" $(cat promisorlist) &&
54 grep "$(cat headhash) refs/heads/master" $(cat promisorlist)
55'
56
35a7ae95
JH
57# checkout master to force dynamic object fetch of blobs at HEAD.
58test_expect_success 'verify checkout with dynamic object fetch' '
8d6ba495 59 git -C pc1 rev-list --quiet --objects --missing=print HEAD >observed &&
35a7ae95
JH
60 test_line_count = 4 observed &&
61 git -C pc1 checkout master &&
8d6ba495 62 git -C pc1 rev-list --quiet --objects --missing=print HEAD >observed &&
35a7ae95
JH
63 test_line_count = 0 observed
64'
65
66# create new commits in "src" repo to establish a blame history on file.1.txt
67# and push to "srv.bare".
68test_expect_success 'push new commits to server' '
69 git -C src remote add srv "file://$(pwd)/srv.bare" &&
70 for x in a b c d e
71 do
aa57b871 72 echo "Mod file.1.txt $x" >>src/file.1.txt
35a7ae95
JH
73 git -C src add file.1.txt
74 git -C src commit -m "mod $x"
75 done &&
76 git -C src blame master -- file.1.txt >expect.blame &&
77 git -C src push -u srv master
78'
79
80# (partial) fetch in the partial clone repo from the promisor remote.
81# verify that fetch inherited the filter-spec from the config and DOES NOT
82# have the new blobs.
83test_expect_success 'partial fetch inherits filter settings' '
84 git -C pc1 fetch origin &&
8d6ba495
MD
85 git -C pc1 rev-list --quiet --objects --missing=print \
86 master..origin/master >observed &&
35a7ae95
JH
87 test_line_count = 5 observed
88'
89
90# force dynamic object fetch using diff.
91# we should only get 1 new blob (for the file in origin/master).
92test_expect_success 'verify diff causes dynamic object fetch' '
93 git -C pc1 diff master..origin/master -- file.1.txt &&
8d6ba495
MD
94 git -C pc1 rev-list --quiet --objects --missing=print \
95 master..origin/master >observed &&
35a7ae95
JH
96 test_line_count = 4 observed
97'
98
99# force full dynamic object fetch of the file's history using blame.
100# we should get the intermediate blobs for the file.
101test_expect_success 'verify blame causes dynamic object fetch' '
102 git -C pc1 blame origin/master -- file.1.txt >observed.blame &&
103 test_cmp expect.blame observed.blame &&
8d6ba495
MD
104 git -C pc1 rev-list --quiet --objects --missing=print \
105 master..origin/master >observed &&
35a7ae95
JH
106 test_line_count = 0 observed
107'
108
aa57b871
JH
109# create new commits in "src" repo to establish a history on file.2.txt
110# and push to "srv.bare".
111test_expect_success 'push new commits to server for file.2.txt' '
112 for x in a b c d e f
113 do
114 echo "Mod file.2.txt $x" >>src/file.2.txt
115 git -C src add file.2.txt
116 git -C src commit -m "mod $x"
117 done &&
118 git -C src push -u srv master
119'
120
3aa6694f 121# Do FULL fetch by disabling inherited filter-spec using --no-filter.
aa57b871
JH
122# Verify we have all the new blobs.
123test_expect_success 'override inherited filter-spec using --no-filter' '
124 git -C pc1 fetch --no-filter origin &&
8d6ba495
MD
125 git -C pc1 rev-list --quiet --objects --missing=print \
126 master..origin/master >observed &&
aa57b871
JH
127 test_line_count = 0 observed
128'
129
3aa6694f
JH
130# create new commits in "src" repo to establish a history on file.3.txt
131# and push to "srv.bare".
132test_expect_success 'push new commits to server for file.3.txt' '
133 for x in a b c d e f
134 do
135 echo "Mod file.3.txt $x" >>src/file.3.txt
136 git -C src add file.3.txt
137 git -C src commit -m "mod $x"
138 done &&
139 git -C src push -u srv master
140'
141
142# Do a partial fetch and then try to manually fetch the missing objects.
143# This can be used as the basis of a pre-command hook to bulk fetch objects
144# perhaps combined with a command in dry-run mode.
145test_expect_success 'manual prefetch of missing objects' '
146 git -C pc1 fetch --filter=blob:none origin &&
bdbc17e8 147
8d6ba495
MD
148 git -C pc1 rev-list --quiet --objects --missing=print \
149 master..origin/master >revs &&
61de0ff6 150 awk -f print_1.awk revs |
bdbc17e8
MD
151 sed "s/?//" |
152 sort >observed.oids &&
153
3aa6694f
JH
154 test_line_count = 6 observed.oids &&
155 git -C pc1 fetch-pack --stdin "file://$(pwd)/srv.bare" <observed.oids &&
bdbc17e8 156
8d6ba495
MD
157 git -C pc1 rev-list --quiet --objects --missing=print \
158 master..origin/master >revs &&
61de0ff6 159 awk -f print_1.awk revs |
bdbc17e8
MD
160 sed "s/?//" |
161 sort >observed.oids &&
162
3aa6694f
JH
163 test_line_count = 0 observed.oids
164'
165
1b03df5f
JT
166test_expect_success 'partial clone with transfer.fsckobjects=1 works with submodules' '
167 test_create_repo submodule &&
168 test_commit -C submodule mycommit &&
169
170 test_create_repo src_with_sub &&
171 test_config -C src_with_sub uploadpack.allowfilter 1 &&
172 test_config -C src_with_sub uploadpack.allowanysha1inwant 1 &&
173
174 git -C src_with_sub submodule add "file://$(pwd)/submodule" mysub &&
175 git -C src_with_sub commit -m "commit with submodule" &&
176
177 git -c transfer.fsckobjects=1 \
178 clone --filter="blob:none" "file://$(pwd)/src_with_sub" dst &&
179 test_when_finished rm -rf dst
180'
181
98a2ea46
JT
182test_expect_success 'partial clone with transfer.fsckobjects=1 uses index-pack --fsck-objects' '
183 git init src &&
184 test_commit -C src x &&
185 test_config -C src uploadpack.allowfilter 1 &&
186 test_config -C src uploadpack.allowanysha1inwant 1 &&
187
188 GIT_TRACE="$(pwd)/trace" git -c transfer.fsckobjects=1 \
189 clone --filter="blob:none" "file://$(pwd)/src" dst &&
190 grep "git index-pack.*--fsck-objects" trace
191'
192
bc5975d2
MD
193test_expect_success 'use fsck before and after manually fetching a missing subtree' '
194 # push new commit so server has a subtree
195 mkdir src/dir &&
196 echo "in dir" >src/dir/file.txt &&
197 git -C src add dir/file.txt &&
198 git -C src commit -m "file in dir" &&
199 git -C src push -u srv master &&
200 SUBTREE=$(git -C src rev-parse HEAD:dir) &&
201
202 rm -rf dst &&
203 git clone --no-checkout --filter=tree:0 "file://$(pwd)/srv.bare" dst &&
204 git -C dst fsck &&
205
206 # Make sure we only have commits, and all trees and blobs are missing.
207 git -C dst rev-list --missing=allow-any --objects master \
208 >fetched_objects &&
209 awk -f print_1.awk fetched_objects |
210 xargs -n1 git -C dst cat-file -t >fetched_types &&
211
212 sort -u fetched_types >unique_types.observed &&
213 echo commit >unique_types.expected &&
214 test_cmp unique_types.expected unique_types.observed &&
215
216 # Auto-fetch a tree with cat-file.
217 git -C dst cat-file -p $SUBTREE >tree_contents &&
218 grep file.txt tree_contents &&
219
220 # fsck still works after an auto-fetch of a tree.
221 git -C dst fsck &&
222
223 # Auto-fetch all remaining trees and blobs with --missing=error
224 git -C dst rev-list --missing=error --objects master >fetched_objects &&
225 test_line_count = 70 fetched_objects &&
226
227 awk -f print_1.awk fetched_objects |
228 xargs -n1 git -C dst cat-file -t >fetched_types &&
229
230 sort -u fetched_types >unique_types.observed &&
d9e6d094 231 test_write_lines blob commit tree >unique_types.expected &&
bc5975d2
MD
232 test_cmp unique_types.expected unique_types.observed
233'
234
489fc9ee
MD
235test_expect_success 'implicitly construct combine: filter with repeated flags' '
236 GIT_TRACE=$(pwd)/trace git clone --bare \
237 --filter=blob:none --filter=tree:1 \
238 "file://$(pwd)/srv.bare" pc2 &&
239 grep "trace:.* git pack-objects .*--filter=combine:blob:none+tree:1" \
240 trace &&
241 git -C pc2 rev-list --objects --missing=allow-any HEAD >objects &&
242
243 # We should have gotten some root trees.
244 grep " $" objects &&
245 # Should not have gotten any non-root trees or blobs.
246 ! grep " ." objects &&
247
248 xargs -n 1 git -C pc2 cat-file -t <objects >types &&
249 sort -u types >unique_types.actual &&
250 test_write_lines commit tree >unique_types.expected &&
251 test_cmp unique_types.expected unique_types.actual
252'
253
d43a21bd
JK
254test_expect_success 'upload-pack complains of bogus filter config' '
255 printf 0000 |
256 test_must_fail git \
257 -c uploadpackfilter.tree.maxdepth \
258 upload-pack . >/dev/null 2>err &&
259 test_i18ngrep "unable to parse.*tree.maxdepth" err
260'
261
6dd3456a
TB
262test_expect_success 'upload-pack fails banned object filters' '
263 test_config -C srv.bare uploadpackfilter.blob:none.allow false &&
264 test_must_fail ok=sigpipe git clone --no-checkout --filter=blob:none \
265 "file://$(pwd)/srv.bare" pc3 2>err &&
6cc275ea 266 test_i18ngrep "filter '\''blob:none'\'' not supported" err
6dd3456a
TB
267'
268
269test_expect_success 'upload-pack fails banned combine object filters' '
270 test_config -C srv.bare uploadpackfilter.allow false &&
271 test_config -C srv.bare uploadpackfilter.combine.allow true &&
272 test_config -C srv.bare uploadpackfilter.tree.allow true &&
273 test_config -C srv.bare uploadpackfilter.blob:none.allow false &&
274 test_must_fail ok=sigpipe git clone --no-checkout --filter=tree:1 \
275 --filter=blob:none "file://$(pwd)/srv.bare" pc3 2>err &&
6cc275ea 276 test_i18ngrep "filter '\''blob:none'\'' not supported" err
6dd3456a
TB
277'
278
279test_expect_success 'upload-pack fails banned object filters with fallback' '
280 test_config -C srv.bare uploadpackfilter.allow false &&
281 test_must_fail ok=sigpipe git clone --no-checkout --filter=blob:none \
282 "file://$(pwd)/srv.bare" pc3 2>err &&
6cc275ea 283 test_i18ngrep "filter '\''blob:none'\'' not supported" err
6dd3456a
TB
284'
285
5b01a4e8
TB
286test_expect_success 'upload-pack limits tree depth filters' '
287 test_config -C srv.bare uploadpackfilter.allow false &&
288 test_config -C srv.bare uploadpackfilter.tree.allow true &&
289 test_config -C srv.bare uploadpackfilter.tree.maxDepth 0 &&
290 test_must_fail ok=sigpipe git clone --no-checkout --filter=tree:1 \
291 "file://$(pwd)/srv.bare" pc3 2>err &&
8d133f50
TB
292 test_i18ngrep "tree filter allows max depth 0, but got 1" err &&
293
294 git clone --no-checkout --filter=tree:0 "file://$(pwd)/srv.bare" pc4 &&
295
296 test_config -C srv.bare uploadpackfilter.tree.maxDepth 5 &&
297 git clone --no-checkout --filter=tree:5 "file://$(pwd)/srv.bare" pc5 &&
298 test_must_fail ok=sigpipe git clone --no-checkout --filter=tree:6 \
299 "file://$(pwd)/srv.bare" pc6 2>err &&
300 test_i18ngrep "tree filter allows max depth 5, but got 6" err
5b01a4e8
TB
301'
302
a0c9016a
JT
303test_expect_success 'partial clone fetches blobs pointed to by refs even if normally filtered out' '
304 rm -rf src dst &&
305 git init src &&
306 test_commit -C src x &&
307 test_config -C src uploadpack.allowfilter 1 &&
308 test_config -C src uploadpack.allowanysha1inwant 1 &&
309
310 # Create a tag pointing to a blob.
311 BLOB=$(echo blob-contents | git -C src hash-object --stdin -w) &&
312 git -C src tag myblob "$BLOB" &&
313
314 git clone --filter="blob:none" "file://$(pwd)/src" dst 2>err &&
315 ! grep "does not point to a valid object" err &&
316 git -C dst fsck
317'
318
35f9e3e5
JT
319test_expect_success 'fetch what is specified on CLI even if already promised' '
320 rm -rf src dst.git &&
321 git init src &&
322 test_commit -C src foo &&
323 test_config -C src uploadpack.allowfilter 1 &&
324 test_config -C src uploadpack.allowanysha1inwant 1 &&
325
326 git hash-object --stdin <src/foo.t >blob &&
327
328 git clone --bare --filter=blob:none "file://$(pwd)/src" dst.git &&
329 git -C dst.git rev-list --objects --quiet --missing=print HEAD >missing_before &&
330 grep "?$(cat blob)" missing_before &&
331 git -C dst.git fetch origin $(cat blob) &&
332 git -C dst.git rev-list --objects --quiet --missing=print HEAD >missing_after &&
333 ! grep "?$(cat blob)" missing_after
334'
335
72de5895
JS
336test_expect_success 'setup src repo for sparse filter' '
337 git init sparse-src &&
338 git -C sparse-src config --local uploadpack.allowfilter 1 &&
339 git -C sparse-src config --local uploadpack.allowanysha1inwant 1 &&
340 test_commit -C sparse-src one &&
341 test_commit -C sparse-src two &&
342 echo /one.t >sparse-src/only-one &&
343 git -C sparse-src add . &&
344 git -C sparse-src commit -m "add sparse checkout files"
345'
346
4c96a775 347test_expect_success 'partial clone with sparse filter succeeds' '
72de5895
JS
348 rm -rf dst.git &&
349 git clone --no-local --bare \
350 --filter=sparse:oid=master:only-one \
351 sparse-src dst.git &&
352 (
353 cd dst.git &&
354 git rev-list --objects --missing=print HEAD >out &&
355 grep "^$(git rev-parse HEAD:one.t)" out &&
356 grep "^?$(git rev-parse HEAD:two.t)" out
357 )
358'
359
4c96a775 360test_expect_success 'partial clone with unresolvable sparse filter fails cleanly' '
72de5895
JS
361 rm -rf dst.git &&
362 test_must_fail git clone --no-local --bare \
363 --filter=sparse:oid=master:no-such-name \
364 sparse-src dst.git 2>err &&
365 test_i18ngrep "unable to access sparse blob in .master:no-such-name" err &&
366 test_must_fail git clone --no-local --bare \
367 --filter=sparse:oid=master \
368 sparse-src dst.git 2>err &&
cf34337f 369 test_i18ngrep "unable to parse sparse filter data in" err
72de5895
JS
370'
371
6462d5eb
JT
372setup_triangle () {
373 rm -rf big-blob.txt server client promisor-remote &&
374
375 printf "line %d\n" $(test_seq 1 100) >big-blob.txt &&
376
b54128bb 377 # Create a server with 2 commits: a commit with a big tree and a child
6462d5eb
JT
378 # commit with an incremental change. Also, create a partial clone
379 # client that only contains the first commit.
380 git init server &&
381 git -C server config --local uploadpack.allowfilter 1 &&
b54128bb
JT
382 for i in $(test_seq 1 100)
383 do
384 echo "make the tree big" >server/file$i &&
385 git -C server add file$i
386 done &&
6462d5eb
JT
387 git -C server commit -m "initial" &&
388 git clone --bare --filter=tree:0 "file://$(pwd)/server" client &&
b54128bb
JT
389 echo another line >>server/file1 &&
390 git -C server commit -am "incremental change" &&
6462d5eb 391
b54128bb
JT
392 # Create a promisor remote that only contains the tree and blob from
393 # the first commit.
6462d5eb 394 git init promisor-remote &&
b54128bb
JT
395 git -C server config --local uploadpack.allowanysha1inwant 1 &&
396 TREE_HASH=$(git -C server rev-parse HEAD~1^{tree}) &&
397 git -C promisor-remote fetch --keep "file://$(pwd)/server" "$TREE_HASH" &&
398 git -C promisor-remote count-objects -v >object-count &&
399 test_i18ngrep "count: 0" object-count &&
400 test_i18ngrep "in-pack: 2" object-count &&
401
402 # Set it as the promisor remote of client. Thus, whenever
403 # the client lazy fetches, the lazy fetch will succeed only if it is
404 # for this tree or blob.
6462d5eb
JT
405 test_commit -C promisor-remote one && # so that ref advertisement is not empty
406 git -C promisor-remote config --local uploadpack.allowanysha1inwant 1 &&
6462d5eb
JT
407 git -C client remote set-url origin "file://$(pwd)/promisor-remote"
408}
409
410# NEEDSWORK: The tests beginning with "fetch lazy-fetches" below only
411# test that "fetch" avoid fetching trees and blobs, but not commits or
412# tags. Revisit this if Git is ever taught to support partial clones
413# with commits and/or tags filtered out.
414
415test_expect_success 'fetch lazy-fetches only to resolve deltas' '
416 setup_triangle &&
417
418 # Exercise to make sure it works. Git will not fetch anything from the
b54128bb 419 # promisor remote other than for the big tree (because it needs to
6462d5eb
JT
420 # resolve the delta).
421 GIT_TRACE_PACKET="$(pwd)/trace" git -C client \
422 fetch "file://$(pwd)/server" master &&
423
424 # Verify the assumption that the client needed to fetch the delta base
425 # to resolve the delta.
b54128bb 426 git -C server rev-parse HEAD~1^{tree} >hash &&
6462d5eb
JT
427 grep "want $(cat hash)" trace
428'
429
430test_expect_success 'fetch lazy-fetches only to resolve deltas, protocol v2' '
431 setup_triangle &&
432
433 git -C server config --local protocol.version 2 &&
434 git -C client config --local protocol.version 2 &&
435 git -C promisor-remote config --local protocol.version 2 &&
436
437 # Exercise to make sure it works. Git will not fetch anything from the
438 # promisor remote other than for the big blob (because it needs to
439 # resolve the delta).
440 GIT_TRACE_PACKET="$(pwd)/trace" git -C client \
441 fetch "file://$(pwd)/server" master &&
442
443 # Verify that protocol version 2 was used.
444 grep "fetch< version 2" trace &&
445
446 # Verify the assumption that the client needed to fetch the delta base
447 # to resolve the delta.
b54128bb 448 git -C server rev-parse HEAD~1^{tree} >hash &&
6462d5eb
JT
449 grep "want $(cat hash)" trace
450'
451
5c3b801d
JT
452test_expect_success 'fetch does not lazy-fetch missing targets of its refs' '
453 rm -rf server client trace &&
454
455 test_create_repo server &&
456 test_config -C server uploadpack.allowfilter 1 &&
457 test_config -C server uploadpack.allowanysha1inwant 1 &&
458 test_commit -C server foo &&
459
460 git clone --filter=blob:none "file://$(pwd)/server" client &&
461 # Make all refs point to nothing by deleting all objects.
462 rm client/.git/objects/pack/* &&
463
464 test_commit -C server bar &&
465 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
466 --no-tags --recurse-submodules=no \
467 origin refs/tags/bar &&
468 FOO_HASH=$(git -C server rev-parse foo) &&
469 ! grep "want $FOO_HASH" trace
470'
471
08450ef7
CC
472# The following two tests must be in this order. It is important that
473# the srv.bare repository did not have tags during clone, but has tags
d0badf87
DS
474# in the fetch.
475
08450ef7 476test_expect_success 'verify fetch succeeds when asking for new tags' '
d0badf87
DS
477 git clone --filter=blob:none "file://$(pwd)/srv.bare" tag-test &&
478 for i in I J K
479 do
480 test_commit -C src $i &&
481 git -C src branch $i || return 1
482 done &&
483 git -C srv.bare fetch --tags origin +refs/heads/*:refs/heads/* &&
484 git -C tag-test -c protocol.version=2 fetch --tags origin
485'
486
3e96c668 487test_expect_success 'verify fetch downloads only one pack when updating refs' '
d0badf87
DS
488 git clone --filter=blob:none "file://$(pwd)/srv.bare" pack-test &&
489 ls pack-test/.git/objects/pack/*pack >pack-list &&
490 test_line_count = 2 pack-list &&
491 for i in A B C
492 do
493 test_commit -C src $i &&
494 git -C src branch $i || return 1
495 done &&
496 git -C srv.bare fetch origin +refs/heads/*:refs/heads/* &&
497 git -C pack-test fetch origin &&
498 ls pack-test/.git/objects/pack/*pack >pack-list &&
499 test_line_count = 3 pack-list
500'
501
167a575e
JK
502test_expect_success 'single-branch tag following respects partial clone' '
503 git clone --single-branch -b B --filter=blob:none \
504 "file://$(pwd)/srv.bare" single &&
505 git -C single rev-parse --verify refs/tags/B &&
506 git -C single rev-parse --verify refs/tags/A &&
507 test_must_fail git -C single rev-parse --verify refs/tags/C
508'
509
77aa0941
JT
510test_expect_success 'fetch from a partial clone, protocol v0' '
511 rm -rf server client trace &&
512
513 # Pretend that the server is a partial clone
514 git init server &&
515 git -C server remote add a_remote "file://$(pwd)/" &&
516 test_config -C server core.repositoryformatversion 1 &&
517 test_config -C server extensions.partialclone a_remote &&
518 test_config -C server protocol.version 0 &&
519 test_commit -C server foo &&
520
521 # Fetch from the server
522 git init client &&
523 test_config -C client protocol.version 0 &&
524 test_commit -C client bar &&
525 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "file://$(pwd)/server" &&
526 ! grep "version 2" trace
527'
528
529test_expect_success 'fetch from a partial clone, protocol v2' '
530 rm -rf server client trace &&
531
532 # Pretend that the server is a partial clone
533 git init server &&
534 git -C server remote add a_remote "file://$(pwd)/" &&
535 test_config -C server core.repositoryformatversion 1 &&
536 test_config -C server extensions.partialclone a_remote &&
537 test_config -C server protocol.version 2 &&
538 test_commit -C server foo &&
539
540 # Fetch from the server
541 git init client &&
542 test_config -C client protocol.version 2 &&
543 test_commit -C client bar &&
544 GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch "file://$(pwd)/server" &&
545 grep "version 2" trace
546'
547
a7e67c11
JT
548. "$TEST_DIRECTORY"/lib-httpd.sh
549start_httpd
550
385d1bfd
JT
551# Converts bytes into their hexadecimal representation. For example,
552# "printf 'ab\r\n' | hex_unpack" results in '61620d0a'.
553hex_unpack () {
554 perl -e '$/ = undef; $input = <>; print unpack("H2" x length($input), $input)'
555}
556
557# Inserts $1 at the start of the string and every 2 characters thereafter.
558intersperse () {
559 sed 's/\(..\)/'$1'\1/g'
560}
561
eafff6e4 562# Create a one-time-perl command to replace the existing packfile with $1.
385d1bfd
JT
563replace_packfile () {
564 # The protocol requires that the packfile be sent in sideband 1, hence
565 # the extra \x01 byte at the beginning.
eafff6e4
JS
566 cp $1 "$HTTPD_ROOT_PATH/one-time-pack" &&
567 echo 'if (/packfile/) {
568 print;
569 my $length = -s "one-time-pack";
570 printf "%04x\x01", $length + 5;
571 print `cat one-time-pack` . "0000";
572 last
573 }' >"$HTTPD_ROOT_PATH/one-time-perl"
a7e67c11
JT
574}
575
576test_expect_success 'upon cloning, check that all refs point to objects' '
577 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
578 rm -rf "$SERVER" repo &&
579 test_create_repo "$SERVER" &&
580 test_commit -C "$SERVER" foo &&
581 test_config -C "$SERVER" uploadpack.allowfilter 1 &&
582 test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 &&
583
584 # Create a tag pointing to a blob.
585 BLOB=$(echo blob-contents | git -C "$SERVER" hash-object --stdin -w) &&
586 git -C "$SERVER" tag myblob "$BLOB" &&
587
588 # Craft a packfile not including that blob.
589 git -C "$SERVER" rev-parse HEAD |
bdbc17e8 590 git -C "$SERVER" pack-objects --stdout >incomplete.pack &&
a7e67c11
JT
591
592 # Replace the existing packfile with the crafted one. The protocol
593 # requires that the packfile be sent in sideband 1, hence the extra
594 # \x01 byte at the beginning.
385d1bfd 595 replace_packfile incomplete.pack &&
a7e67c11 596
eafff6e4 597 # Use protocol v2 because the perl command looks for the "packfile"
a7e67c11
JT
598 # section header.
599 test_config -C "$SERVER" protocol.version 2 &&
600 test_must_fail git -c protocol.version=2 clone \
eafff6e4 601 --filter=blob:none $HTTPD_URL/one_time_perl/server repo 2>err &&
a7e67c11 602
3813a89f 603 test_i18ngrep "did not send all necessary objects" err &&
a7e67c11 604
eafff6e4
JS
605 # Ensure that the one-time-perl script was used.
606 ! test -e "$HTTPD_ROOT_PATH/one-time-perl"
a7e67c11
JT
607'
608
dc0a13f6
JT
609test_expect_success 'when partial cloning, tolerate server not sending target of tag' '
610 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
611 rm -rf "$SERVER" repo &&
612 test_create_repo "$SERVER" &&
613 test_commit -C "$SERVER" foo &&
614 test_config -C "$SERVER" uploadpack.allowfilter 1 &&
615 test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 &&
616
617 # Create an annotated tag pointing to a blob.
618 BLOB=$(echo blob-contents | git -C "$SERVER" hash-object --stdin -w) &&
619 git -C "$SERVER" tag -m message -a myblob "$BLOB" &&
620
621 # Craft a packfile including the tag, but not the blob it points to.
8c4cc326
JT
622 # Also, omit objects referenced from HEAD in order to force a second
623 # fetch (to fetch missing objects) upon the automatic checkout that
624 # happens after a clone.
625 printf "%s\n%s\n--not\n%s\n%s\n" \
dc0a13f6
JT
626 $(git -C "$SERVER" rev-parse HEAD) \
627 $(git -C "$SERVER" rev-parse myblob) \
8c4cc326 628 $(git -C "$SERVER" rev-parse HEAD^{tree}) \
dc0a13f6
JT
629 $(git -C "$SERVER" rev-parse myblob^{blob}) |
630 git -C "$SERVER" pack-objects --thin --stdout >incomplete.pack &&
631
632 # Replace the existing packfile with the crafted one. The protocol
633 # requires that the packfile be sent in sideband 1, hence the extra
634 # \x01 byte at the beginning.
385d1bfd 635 replace_packfile incomplete.pack &&
dc0a13f6 636
eafff6e4 637 # Use protocol v2 because the perl command looks for the "packfile"
dc0a13f6
JT
638 # section header.
639 test_config -C "$SERVER" protocol.version 2 &&
640
641 # Exercise to make sure it works.
642 git -c protocol.version=2 clone \
eafff6e4 643 --filter=blob:none $HTTPD_URL/one_time_perl/server repo 2> err &&
8c4cc326 644 ! grep "missing object referenced by" err &&
dc0a13f6 645
eafff6e4
JS
646 # Ensure that the one-time-perl script was used.
647 ! test -e "$HTTPD_ROOT_PATH/one-time-perl"
dc0a13f6
JT
648'
649
8a30a1ef
JT
650test_expect_success 'tolerate server sending REF_DELTA against missing promisor objects' '
651 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
652 rm -rf "$SERVER" repo &&
653 test_create_repo "$SERVER" &&
654 test_config -C "$SERVER" uploadpack.allowfilter 1 &&
655 test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 &&
656
810e1932 657 # Create a commit with 2 blobs to be used as delta bases.
8a30a1ef
JT
658 for i in $(test_seq 10)
659 do
810e1932
JT
660 echo "this is a line" >>"$SERVER/foo.txt" &&
661 echo "this is another line" >>"$SERVER/have.txt"
8a30a1ef 662 done &&
810e1932 663 git -C "$SERVER" add foo.txt have.txt &&
8a30a1ef 664 git -C "$SERVER" commit -m bar &&
810e1932
JT
665 git -C "$SERVER" rev-parse HEAD:foo.txt >deltabase_missing &&
666 git -C "$SERVER" rev-parse HEAD:have.txt >deltabase_have &&
8a30a1ef 667
810e1932 668 # Clone. The client has deltabase_have but not deltabase_missing.
8a30a1ef 669 git -c protocol.version=2 clone --no-checkout \
eafff6e4 670 --filter=blob:none $HTTPD_URL/one_time_perl/server repo &&
810e1932 671 git -C repo hash-object -w -- "$SERVER/have.txt" &&
8a30a1ef 672
810e1932
JT
673 # Sanity check to ensure that the client does not have
674 # deltabase_missing.
5718c53d 675 git -C repo rev-list --objects --ignore-missing \
810e1932 676 -- $(cat deltabase_missing) >objlist &&
8a30a1ef
JT
677 test_line_count = 0 objlist &&
678
679 # Another commit. This commit will be fetched by the client.
680 echo "abcdefghijklmnopqrstuvwxyz" >>"$SERVER/foo.txt" &&
810e1932
JT
681 echo "abcdefghijklmnopqrstuvwxyz" >>"$SERVER/have.txt" &&
682 git -C "$SERVER" add foo.txt have.txt &&
8a30a1ef
JT
683 git -C "$SERVER" commit -m baz &&
684
685 # Pack a thin pack containing, among other things, HEAD:foo.txt
810e1932
JT
686 # delta-ed against HEAD^:foo.txt and HEAD:have.txt delta-ed against
687 # HEAD^:have.txt.
8a30a1ef
JT
688 printf "%s\n--not\n%s\n" \
689 $(git -C "$SERVER" rev-parse HEAD) \
690 $(git -C "$SERVER" rev-parse HEAD^) |
691 git -C "$SERVER" pack-objects --thin --stdout >thin.pack &&
692
693 # Ensure that the pack contains one delta against HEAD^:foo.txt. Since
694 # the delta contains at least 26 novel characters, the size cannot be
695 # contained in 4 bits, so the object header will take up 2 bytes. The
696 # most significant nybble of the first byte is 0b1111 (0b1 to indicate
697 # that the header continues, and 0b111 to indicate REF_DELTA), followed
698 # by any 3 nybbles, then the OID of the delta base.
810e1932
JT
699 printf "f.,..%s" $(intersperse "," <deltabase_missing) >want &&
700 hex_unpack <thin.pack | intersperse "," >have &&
701 grep $(cat want) have &&
702
703 # Ensure that the pack contains one delta against HEAD^:have.txt,
704 # similar to the above.
705 printf "f.,..%s" $(intersperse "," <deltabase_have) >want &&
8a30a1ef
JT
706 hex_unpack <thin.pack | intersperse "," >have &&
707 grep $(cat want) have &&
708
709 replace_packfile thin.pack &&
710
eafff6e4 711 # Use protocol v2 because the perl command looks for the "packfile"
8a30a1ef
JT
712 # section header.
713 test_config -C "$SERVER" protocol.version 2 &&
714
715 # Fetch the thin pack and ensure that index-pack is able to handle the
716 # REF_DELTA object with a missing promisor delta base.
810e1932
JT
717 GIT_TRACE_PACKET="$(pwd)/trace" git -C repo -c protocol.version=2 fetch &&
718
719 # Ensure that the missing delta base was directly fetched, but not the
720 # one that the client has.
721 grep "want $(cat deltabase_missing)" trace &&
722 ! grep "want $(cat deltabase_have)" trace &&
8a30a1ef 723
eafff6e4
JS
724 # Ensure that the one-time-perl script was used.
725 ! test -e "$HTTPD_ROOT_PATH/one-time-perl"
8a30a1ef
JT
726'
727
decfe05b
SG
728# DO NOT add non-httpd-specific tests here, because the last part of this
729# test script is only executed when httpd is available and enabled.
730
35a7ae95 731test_done