promisor-remote: parse remote.*.partialclonefilter
[git/git.git] / t / t0410-partial-clone.sh
CommitLineData
498f1f61
JT
1#!/bin/sh
2
3test_description='partial clone'
4
5. ./test-lib.sh
6
7delete_object () {
8 rm $1/.git/objects/$(echo $2 | sed -e 's|^..|&/|')
9}
10
11pack_as_from_promisor () {
12 HASH=$(git -C repo pack-objects .git/objects/pack/pack) &&
0c16cd49
JT
13 >repo/.git/objects/pack/pack-$HASH.promisor &&
14 echo $HASH
498f1f61
JT
15}
16
43f25158
JT
17promise_and_delete () {
18 HASH=$(git -C repo rev-parse "$1") &&
19 git -C repo tag -a -m message my_annotated_tag "$HASH" &&
20 git -C repo rev-parse my_annotated_tag | pack_as_from_promisor &&
0c16cd49
JT
21 # tag -d prints a message to stdout, so redirect it
22 git -C repo tag -d my_annotated_tag >/dev/null &&
43f25158
JT
23 delete_object repo "$HASH"
24}
25
cac1137d
JT
26test_expect_success 'extensions.partialclone without filter' '
27 test_create_repo server &&
28 git clone --filter="blob:none" "file://$(pwd)/server" client &&
fa3d1b63 29 git -C client config --unset remote.origin.partialclonefilter &&
cac1137d
JT
30 git -C client fetch origin
31'
32
498f1f61 33test_expect_success 'missing reflog object, but promised by a commit, passes fsck' '
cac1137d 34 rm -rf repo &&
498f1f61
JT
35 test_create_repo repo &&
36 test_commit -C repo my_commit &&
37
38 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
39 C=$(git -C repo commit-tree -m c -p $A HEAD^{tree}) &&
40
41 # Reference $A only from reflog, and delete it
42 git -C repo branch my_branch "$A" &&
43 git -C repo branch -f my_branch my_commit &&
44 delete_object repo "$A" &&
45
46 # State that we got $C, which refers to $A, from promisor
47 printf "$C\n" | pack_as_from_promisor &&
48
49 # Normally, it fails
50 test_must_fail git -C repo fsck &&
51
52 # But with the extension, it succeeds
53 git -C repo config core.repositoryformatversion 1 &&
54 git -C repo config extensions.partialclone "arbitrary string" &&
55 git -C repo fsck
56'
57
58test_expect_success 'missing reflog object, but promised by a tag, passes fsck' '
59 rm -rf repo &&
60 test_create_repo repo &&
61 test_commit -C repo my_commit &&
62
63 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
64 git -C repo tag -a -m d my_tag_name $A &&
65 T=$(git -C repo rev-parse my_tag_name) &&
66 git -C repo tag -d my_tag_name &&
67
68 # Reference $A only from reflog, and delete it
69 git -C repo branch my_branch "$A" &&
70 git -C repo branch -f my_branch my_commit &&
71 delete_object repo "$A" &&
72
73 # State that we got $T, which refers to $A, from promisor
74 printf "$T\n" | pack_as_from_promisor &&
75
76 git -C repo config core.repositoryformatversion 1 &&
77 git -C repo config extensions.partialclone "arbitrary string" &&
78 git -C repo fsck
79'
80
81test_expect_success 'missing reflog object alone fails fsck, even with extension set' '
82 rm -rf repo &&
83 test_create_repo repo &&
84 test_commit -C repo my_commit &&
85
86 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
87 B=$(git -C repo commit-tree -m b HEAD^{tree}) &&
88
89 # Reference $A only from reflog, and delete it
90 git -C repo branch my_branch "$A" &&
91 git -C repo branch -f my_branch my_commit &&
92 delete_object repo "$A" &&
93
94 git -C repo config core.repositoryformatversion 1 &&
95 git -C repo config extensions.partialclone "arbitrary string" &&
96 test_must_fail git -C repo fsck
97'
98
43f25158
JT
99test_expect_success 'missing ref object, but promised, passes fsck' '
100 rm -rf repo &&
101 test_create_repo repo &&
102 test_commit -C repo my_commit &&
103
104 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
105
106 # Reference $A only from ref
107 git -C repo branch my_branch "$A" &&
108 promise_and_delete "$A" &&
109
110 git -C repo config core.repositoryformatversion 1 &&
111 git -C repo config extensions.partialclone "arbitrary string" &&
112 git -C repo fsck
113'
114
caba7fc3
JT
115test_expect_success 'missing object, but promised, passes fsck' '
116 rm -rf repo &&
117 test_create_repo repo &&
118 test_commit -C repo 1 &&
119 test_commit -C repo 2 &&
120 test_commit -C repo 3 &&
121 git -C repo tag -a annotated_tag -m "annotated tag" &&
122
123 C=$(git -C repo rev-parse 1) &&
124 T=$(git -C repo rev-parse 2^{tree}) &&
125 B=$(git hash-object repo/3.t) &&
126 AT=$(git -C repo rev-parse annotated_tag) &&
127
128 promise_and_delete "$C" &&
129 promise_and_delete "$T" &&
130 promise_and_delete "$B" &&
131 promise_and_delete "$AT" &&
132
133 git -C repo config core.repositoryformatversion 1 &&
134 git -C repo config extensions.partialclone "arbitrary string" &&
135 git -C repo fsck
136'
137
096c9b8b
JT
138test_expect_success 'missing CLI object, but promised, passes fsck' '
139 rm -rf repo &&
140 test_create_repo repo &&
141 test_commit -C repo my_commit &&
142
143 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
144 promise_and_delete "$A" &&
145
146 git -C repo config core.repositoryformatversion 1 &&
147 git -C repo config extensions.partialclone "arbitrary string" &&
148 git -C repo fsck "$A"
149'
150
8b4c0103
JT
151test_expect_success 'fetching of missing objects' '
152 rm -rf repo &&
153 test_create_repo server &&
154 test_commit -C server foo &&
155 git -C server repack -a -d --write-bitmap-index &&
156
157 git clone "file://$(pwd)/server" repo &&
158 HASH=$(git -C repo rev-parse foo) &&
159 rm -rf repo/.git/objects/* &&
160
161 git -C repo config core.repositoryformatversion 1 &&
162 git -C repo config extensions.partialclone "origin" &&
163 git -C repo cat-file -p "$HASH" &&
164
165 # Ensure that the .promisor file is written, and check that its
166 # associated packfile contains the object
167 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
168 test_line_count = 1 promisorlist &&
c59c7c87
CC
169 IDX=$(sed "s/promisor$/idx/" promisorlist) &&
170 git verify-pack --verbose "$IDX" >out &&
171 grep "$HASH" out
8b4c0103
JT
172'
173
e6830201
JT
174test_expect_success 'fetching of missing objects works with ref-in-want enabled' '
175 # ref-in-want requires protocol version 2
176 git -C server config protocol.version 2 &&
177 git -C server config uploadpack.allowrefinwant 1 &&
178 git -C repo config protocol.version 2 &&
179
180 rm -rf repo/.git/objects/* &&
181 rm -f trace &&
182 GIT_TRACE_PACKET="$(pwd)/trace" git -C repo cat-file -p "$HASH" &&
183 grep "git< fetch=.*ref-in-want" trace
184'
185
4c7f9567
JT
186test_expect_success 'fetching of missing blobs works' '
187 rm -rf server repo &&
188 test_create_repo server &&
189 test_commit -C server foo &&
190 git -C server repack -a -d --write-bitmap-index &&
191
192 git clone "file://$(pwd)/server" repo &&
193 git hash-object repo/foo.t >blobhash &&
194 rm -rf repo/.git/objects/* &&
195
196 git -C server config uploadpack.allowanysha1inwant 1 &&
197 git -C server config uploadpack.allowfilter 1 &&
198 git -C repo config core.repositoryformatversion 1 &&
199 git -C repo config extensions.partialclone "origin" &&
200
201 git -C repo cat-file -p $(cat blobhash)
202'
203
204test_expect_success 'fetching of missing trees does not fetch blobs' '
205 rm -rf server repo &&
206 test_create_repo server &&
207 test_commit -C server foo &&
208 git -C server repack -a -d --write-bitmap-index &&
209
210 git clone "file://$(pwd)/server" repo &&
211 git -C repo rev-parse foo^{tree} >treehash &&
212 git hash-object repo/foo.t >blobhash &&
213 rm -rf repo/.git/objects/* &&
214
215 git -C server config uploadpack.allowanysha1inwant 1 &&
216 git -C server config uploadpack.allowfilter 1 &&
217 git -C repo config core.repositoryformatversion 1 &&
218 git -C repo config extensions.partialclone "origin" &&
219 git -C repo cat-file -p $(cat treehash) &&
220
221 # Ensure that the tree, but not the blob, is fetched
222 git -C repo rev-list --objects --missing=print $(cat treehash) >objects &&
223 grep "^$(cat treehash)" objects &&
224 grep "^[?]$(cat blobhash)" objects
225'
226
df11e196
JT
227test_expect_success 'rev-list stops traversal at missing and promised commit' '
228 rm -rf repo &&
229 test_create_repo repo &&
230 test_commit -C repo foo &&
231 test_commit -C repo bar &&
232
233 FOO=$(git -C repo rev-parse foo) &&
234 promise_and_delete "$FOO" &&
235
236 git -C repo config core.repositoryformatversion 1 &&
237 git -C repo config extensions.partialclone "arbitrary string" &&
859fdc0c 238 GIT_TEST_COMMIT_GRAPH=0 git -C repo rev-list --exclude-promisor-objects --objects bar >out &&
df11e196
JT
239 grep $(git -C repo rev-parse bar) out &&
240 ! grep $FOO out
241'
242
7c0fe330
MD
243test_expect_success 'missing tree objects with --missing=allow-promisor and --exclude-promisor-objects' '
244 rm -rf repo &&
245 test_create_repo repo &&
246 test_commit -C repo foo &&
247 test_commit -C repo bar &&
248 test_commit -C repo baz &&
249
250 promise_and_delete $(git -C repo rev-parse bar^{tree}) &&
251 promise_and_delete $(git -C repo rev-parse foo^{tree}) &&
252
253 git -C repo config core.repositoryformatversion 1 &&
254 git -C repo config extensions.partialclone "arbitrary string" &&
255
256 git -C repo rev-list --missing=allow-promisor --objects HEAD >objs 2>rev_list_err &&
257 test_must_be_empty rev_list_err &&
258 # 3 commits, 3 blobs, and 1 tree
259 test_line_count = 7 objs &&
260
261 # Do the same for --exclude-promisor-objects, but with all trees gone.
262 promise_and_delete $(git -C repo rev-parse baz^{tree}) &&
263 git -C repo rev-list --exclude-promisor-objects --objects HEAD >objs 2>rev_list_err &&
264 test_must_be_empty rev_list_err &&
265 # 3 commits, no blobs or trees
266 test_line_count = 3 objs
267'
268
269test_expect_success 'missing non-root tree object and rev-list' '
270 rm -rf repo &&
271 test_create_repo repo &&
272 mkdir repo/dir &&
273 echo foo >repo/dir/foo &&
274 git -C repo add dir/foo &&
275 git -C repo commit -m "commit dir/foo" &&
276
277 promise_and_delete $(git -C repo rev-parse HEAD:dir) &&
278
279 git -C repo config core.repositoryformatversion 1 &&
280 git -C repo config extensions.partialclone "arbitrary string" &&
281
282 git -C repo rev-list --missing=allow-any --objects HEAD >objs 2>rev_list_err &&
283 test_must_be_empty rev_list_err &&
284 # 1 commit and 1 tree
285 test_line_count = 2 objs
286'
287
df11e196
JT
288test_expect_success 'rev-list stops traversal at missing and promised tree' '
289 rm -rf repo &&
290 test_create_repo repo &&
291 test_commit -C repo foo &&
292 mkdir repo/a_dir &&
293 echo something >repo/a_dir/something &&
294 git -C repo add a_dir/something &&
295 git -C repo commit -m bar &&
296
297 # foo^{tree} (tree referenced from commit)
298 TREE=$(git -C repo rev-parse foo^{tree}) &&
299
300 # a tree referenced by HEAD^{tree} (tree referenced from tree)
301 TREE2=$(git -C repo ls-tree HEAD^{tree} | grep " tree " | head -1 | cut -b13-52) &&
302
303 promise_and_delete "$TREE" &&
304 promise_and_delete "$TREE2" &&
305
306 git -C repo config core.repositoryformatversion 1 &&
307 git -C repo config extensions.partialclone "arbitrary string" &&
308 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
309 grep $(git -C repo rev-parse foo) out &&
310 ! grep $TREE out &&
311 grep $(git -C repo rev-parse HEAD) out &&
312 ! grep $TREE2 out
313'
314
315test_expect_success 'rev-list stops traversal at missing and promised blob' '
316 rm -rf repo &&
317 test_create_repo repo &&
318 echo something >repo/something &&
319 git -C repo add something &&
320 git -C repo commit -m foo &&
321
322 BLOB=$(git -C repo hash-object -w something) &&
323 promise_and_delete "$BLOB" &&
324
325 git -C repo config core.repositoryformatversion 1 &&
326 git -C repo config extensions.partialclone "arbitrary string" &&
327 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
328 grep $(git -C repo rev-parse HEAD) out &&
329 ! grep $BLOB out
330'
331
332test_expect_success 'rev-list stops traversal at promisor commit, tree, and blob' '
333 rm -rf repo &&
334 test_create_repo repo &&
335 test_commit -C repo foo &&
336 test_commit -C repo bar &&
337 test_commit -C repo baz &&
338
339 COMMIT=$(git -C repo rev-parse foo) &&
340 TREE=$(git -C repo rev-parse bar^{tree}) &&
341 BLOB=$(git hash-object repo/baz.t) &&
342 printf "%s\n%s\n%s\n" $COMMIT $TREE $BLOB | pack_as_from_promisor &&
343
344 git -C repo config core.repositoryformatversion 1 &&
345 git -C repo config extensions.partialclone "arbitrary string" &&
346 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
347 ! grep $COMMIT out &&
348 ! grep $TREE out &&
349 ! grep $BLOB out &&
350 grep $(git -C repo rev-parse bar) out # sanity check that some walking was done
351'
352
4cf67869 353test_expect_success 'rev-list dies for missing objects on cmd line' '
df11e196
JT
354 rm -rf repo &&
355 test_create_repo repo &&
356 test_commit -C repo foo &&
357 test_commit -C repo bar &&
358 test_commit -C repo baz &&
359
360 COMMIT=$(git -C repo rev-parse foo) &&
361 TREE=$(git -C repo rev-parse bar^{tree}) &&
362 BLOB=$(git hash-object repo/baz.t) &&
363
364 promise_and_delete $COMMIT &&
365 promise_and_delete $TREE &&
366 promise_and_delete $BLOB &&
367
368 git -C repo config core.repositoryformatversion 1 &&
369 git -C repo config extensions.partialclone "arbitrary string" &&
4cf67869
MD
370
371 for OBJ in "$COMMIT" "$TREE" "$BLOB"; do
372 test_must_fail git -C repo rev-list --objects \
373 --exclude-promisor-objects "$OBJ" &&
374 test_must_fail git -C repo rev-list --objects-edge-aggressive \
375 --exclude-promisor-objects "$OBJ" &&
376
377 # Do not die or crash when --ignore-missing is passed.
378 git -C repo rev-list --ignore-missing --objects \
379 --exclude-promisor-objects "$OBJ" &&
380 git -C repo rev-list --ignore-missing --objects-edge-aggressive \
381 --exclude-promisor-objects "$OBJ"
382 done
df11e196
JT
383'
384
5d19e813 385test_expect_success 'gc repacks promisor objects separately from non-promisor objects' '
0c16cd49
JT
386 rm -rf repo &&
387 test_create_repo repo &&
5d19e813
JT
388 test_commit -C repo one &&
389 test_commit -C repo two &&
0c16cd49 390
5d19e813
JT
391 TREE_ONE=$(git -C repo rev-parse one^{tree}) &&
392 printf "$TREE_ONE\n" | pack_as_from_promisor &&
393 TREE_TWO=$(git -C repo rev-parse two^{tree}) &&
394 printf "$TREE_TWO\n" | pack_as_from_promisor &&
0c16cd49
JT
395
396 git -C repo config core.repositoryformatversion 1 &&
397 git -C repo config extensions.partialclone "arbitrary string" &&
398 git -C repo gc &&
399
5d19e813
JT
400 # Ensure that exactly one promisor packfile exists, and that it
401 # contains the trees but not the commits
402 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
403 test_line_count = 1 promisorlist &&
404 PROMISOR_PACKFILE=$(sed "s/.promisor/.pack/" <promisorlist) &&
405 git verify-pack $PROMISOR_PACKFILE -v >out &&
406 grep "$TREE_ONE" out &&
407 grep "$TREE_TWO" out &&
408 ! grep "$(git -C repo rev-parse one)" out &&
409 ! grep "$(git -C repo rev-parse two)" out &&
410
411 # Remove the promisor packfile and associated files
412 rm $(sed "s/.promisor//" <promisorlist).* &&
413
414 # Ensure that the single other pack contains the commits, but not the
415 # trees
0c16cd49
JT
416 ls repo/.git/objects/pack/pack-*.pack >packlist &&
417 test_line_count = 1 packlist &&
418 git verify-pack repo/.git/objects/pack/pack-*.pack -v >out &&
5d19e813
JT
419 grep "$(git -C repo rev-parse one)" out &&
420 grep "$(git -C repo rev-parse two)" out &&
421 ! grep "$TREE_ONE" out &&
422 ! grep "$TREE_TWO" out
423'
424
425test_expect_success 'gc does not repack promisor objects if there are none' '
426 rm -rf repo &&
427 test_create_repo repo &&
428 test_commit -C repo one &&
429
430 git -C repo config core.repositoryformatversion 1 &&
431 git -C repo config extensions.partialclone "arbitrary string" &&
432 git -C repo gc &&
433
434 # Ensure that only one pack exists
435 ls repo/.git/objects/pack/pack-*.pack >packlist &&
436 test_line_count = 1 packlist
437'
438
439repack_and_check () {
440 rm -rf repo2 &&
441 cp -r repo repo2 &&
442 git -C repo2 repack $1 -d &&
443 git -C repo2 fsck &&
444
445 git -C repo2 cat-file -e $2 &&
446 git -C repo2 cat-file -e $3
447}
448
449test_expect_success 'repack -d does not irreversibly delete promisor objects' '
450 rm -rf repo &&
451 test_create_repo repo &&
452 git -C repo config core.repositoryformatversion 1 &&
453 git -C repo config extensions.partialclone "arbitrary string" &&
454
455 git -C repo commit --allow-empty -m one &&
456 git -C repo commit --allow-empty -m two &&
457 git -C repo commit --allow-empty -m three &&
458 git -C repo commit --allow-empty -m four &&
459 ONE=$(git -C repo rev-parse HEAD^^^) &&
460 TWO=$(git -C repo rev-parse HEAD^^) &&
461 THREE=$(git -C repo rev-parse HEAD^) &&
462
463 printf "$TWO\n" | pack_as_from_promisor &&
464 printf "$THREE\n" | pack_as_from_promisor &&
465 delete_object repo "$ONE" &&
466
467 repack_and_check -a "$TWO" "$THREE" &&
468 repack_and_check -A "$TWO" "$THREE" &&
469 repack_and_check -l "$TWO" "$THREE"
0c16cd49
JT
470'
471
472test_expect_success 'gc stops traversal when a missing but promised object is reached' '
473 rm -rf repo &&
474 test_create_repo repo &&
475 test_commit -C repo my_commit &&
476
477 TREE_HASH=$(git -C repo rev-parse HEAD^{tree}) &&
478 HASH=$(promise_and_delete $TREE_HASH) &&
479
480 git -C repo config core.repositoryformatversion 1 &&
481 git -C repo config extensions.partialclone "arbitrary string" &&
482 git -C repo gc &&
483
484 # Ensure that the promisor packfile still exists, and remove it
485 test -e repo/.git/objects/pack/pack-$HASH.pack &&
486 rm repo/.git/objects/pack/pack-$HASH.* &&
487
488 # Ensure that the single other pack contains the commit, but not the tree
489 ls repo/.git/objects/pack/pack-*.pack >packlist &&
490 test_line_count = 1 packlist &&
491 git verify-pack repo/.git/objects/pack/pack-*.pack -v >out &&
492 grep "$(git -C repo rev-parse HEAD)" out &&
493 ! grep "$TREE_HASH" out
494'
495
8b4c0103
JT
496. "$TEST_DIRECTORY"/lib-httpd.sh
497start_httpd
498
499test_expect_success 'fetching of missing objects from an HTTP server' '
500 rm -rf repo &&
501 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
502 test_create_repo "$SERVER" &&
503 test_commit -C "$SERVER" foo &&
504 git -C "$SERVER" repack -a -d --write-bitmap-index &&
505
506 git clone $HTTPD_URL/smart/server repo &&
507 HASH=$(git -C repo rev-parse foo) &&
508 rm -rf repo/.git/objects/* &&
509
510 git -C repo config core.repositoryformatversion 1 &&
511 git -C repo config extensions.partialclone "origin" &&
512 git -C repo cat-file -p "$HASH" &&
513
514 # Ensure that the .promisor file is written, and check that its
515 # associated packfile contains the object
516 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
517 test_line_count = 1 promisorlist &&
c59c7c87
CC
518 IDX=$(sed "s/promisor$/idx/" promisorlist) &&
519 git verify-pack --verbose "$IDX" >out &&
520 grep "$HASH" out
8b4c0103
JT
521'
522
498f1f61 523test_done