]> git.ipfire.org Git - thirdparty/git.git/blame - t/t0410-partial-clone.sh
sha1-file: split OBJECT_INFO_FOR_PREFETCH
[thirdparty/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 &&
29 git -C client config --unset core.partialclonefilter &&
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 &&
169 IDX=$(cat promisorlist | sed "s/promisor$/idx/") &&
170 git verify-pack --verbose "$IDX" | grep "$HASH"
171'
172
e6830201
JT
173test_expect_success 'fetching of missing objects works with ref-in-want enabled' '
174 # ref-in-want requires protocol version 2
175 git -C server config protocol.version 2 &&
176 git -C server config uploadpack.allowrefinwant 1 &&
177 git -C repo config protocol.version 2 &&
178
179 rm -rf repo/.git/objects/* &&
180 rm -f trace &&
181 GIT_TRACE_PACKET="$(pwd)/trace" git -C repo cat-file -p "$HASH" &&
182 grep "git< fetch=.*ref-in-want" trace
183'
184
4c7f9567
JT
185test_expect_success 'fetching of missing blobs works' '
186 rm -rf server repo &&
187 test_create_repo server &&
188 test_commit -C server foo &&
189 git -C server repack -a -d --write-bitmap-index &&
190
191 git clone "file://$(pwd)/server" repo &&
192 git hash-object repo/foo.t >blobhash &&
193 rm -rf repo/.git/objects/* &&
194
195 git -C server config uploadpack.allowanysha1inwant 1 &&
196 git -C server config uploadpack.allowfilter 1 &&
197 git -C repo config core.repositoryformatversion 1 &&
198 git -C repo config extensions.partialclone "origin" &&
199
200 git -C repo cat-file -p $(cat blobhash)
201'
202
203test_expect_success 'fetching of missing trees does not fetch blobs' '
204 rm -rf server repo &&
205 test_create_repo server &&
206 test_commit -C server foo &&
207 git -C server repack -a -d --write-bitmap-index &&
208
209 git clone "file://$(pwd)/server" repo &&
210 git -C repo rev-parse foo^{tree} >treehash &&
211 git hash-object repo/foo.t >blobhash &&
212 rm -rf repo/.git/objects/* &&
213
214 git -C server config uploadpack.allowanysha1inwant 1 &&
215 git -C server config uploadpack.allowfilter 1 &&
216 git -C repo config core.repositoryformatversion 1 &&
217 git -C repo config extensions.partialclone "origin" &&
218 git -C repo cat-file -p $(cat treehash) &&
219
220 # Ensure that the tree, but not the blob, is fetched
221 git -C repo rev-list --objects --missing=print $(cat treehash) >objects &&
222 grep "^$(cat treehash)" objects &&
223 grep "^[?]$(cat blobhash)" objects
224'
225
df11e196
JT
226test_expect_success 'rev-list stops traversal at missing and promised commit' '
227 rm -rf repo &&
228 test_create_repo repo &&
229 test_commit -C repo foo &&
230 test_commit -C repo bar &&
231
232 FOO=$(git -C repo rev-parse foo) &&
233 promise_and_delete "$FOO" &&
234
235 git -C repo config core.repositoryformatversion 1 &&
236 git -C repo config extensions.partialclone "arbitrary string" &&
859fdc0c 237 GIT_TEST_COMMIT_GRAPH=0 git -C repo rev-list --exclude-promisor-objects --objects bar >out &&
df11e196
JT
238 grep $(git -C repo rev-parse bar) out &&
239 ! grep $FOO out
240'
241
7c0fe330
MD
242test_expect_success 'missing tree objects with --missing=allow-promisor and --exclude-promisor-objects' '
243 rm -rf repo &&
244 test_create_repo repo &&
245 test_commit -C repo foo &&
246 test_commit -C repo bar &&
247 test_commit -C repo baz &&
248
249 promise_and_delete $(git -C repo rev-parse bar^{tree}) &&
250 promise_and_delete $(git -C repo rev-parse foo^{tree}) &&
251
252 git -C repo config core.repositoryformatversion 1 &&
253 git -C repo config extensions.partialclone "arbitrary string" &&
254
255 git -C repo rev-list --missing=allow-promisor --objects HEAD >objs 2>rev_list_err &&
256 test_must_be_empty rev_list_err &&
257 # 3 commits, 3 blobs, and 1 tree
258 test_line_count = 7 objs &&
259
260 # Do the same for --exclude-promisor-objects, but with all trees gone.
261 promise_and_delete $(git -C repo rev-parse baz^{tree}) &&
262 git -C repo rev-list --exclude-promisor-objects --objects HEAD >objs 2>rev_list_err &&
263 test_must_be_empty rev_list_err &&
264 # 3 commits, no blobs or trees
265 test_line_count = 3 objs
266'
267
268test_expect_success 'missing non-root tree object and rev-list' '
269 rm -rf repo &&
270 test_create_repo repo &&
271 mkdir repo/dir &&
272 echo foo >repo/dir/foo &&
273 git -C repo add dir/foo &&
274 git -C repo commit -m "commit dir/foo" &&
275
276 promise_and_delete $(git -C repo rev-parse HEAD:dir) &&
277
278 git -C repo config core.repositoryformatversion 1 &&
279 git -C repo config extensions.partialclone "arbitrary string" &&
280
281 git -C repo rev-list --missing=allow-any --objects HEAD >objs 2>rev_list_err &&
282 test_must_be_empty rev_list_err &&
283 # 1 commit and 1 tree
284 test_line_count = 2 objs
285'
286
df11e196
JT
287test_expect_success 'rev-list stops traversal at missing and promised tree' '
288 rm -rf repo &&
289 test_create_repo repo &&
290 test_commit -C repo foo &&
291 mkdir repo/a_dir &&
292 echo something >repo/a_dir/something &&
293 git -C repo add a_dir/something &&
294 git -C repo commit -m bar &&
295
296 # foo^{tree} (tree referenced from commit)
297 TREE=$(git -C repo rev-parse foo^{tree}) &&
298
299 # a tree referenced by HEAD^{tree} (tree referenced from tree)
300 TREE2=$(git -C repo ls-tree HEAD^{tree} | grep " tree " | head -1 | cut -b13-52) &&
301
302 promise_and_delete "$TREE" &&
303 promise_and_delete "$TREE2" &&
304
305 git -C repo config core.repositoryformatversion 1 &&
306 git -C repo config extensions.partialclone "arbitrary string" &&
307 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
308 grep $(git -C repo rev-parse foo) out &&
309 ! grep $TREE out &&
310 grep $(git -C repo rev-parse HEAD) out &&
311 ! grep $TREE2 out
312'
313
314test_expect_success 'rev-list stops traversal at missing and promised blob' '
315 rm -rf repo &&
316 test_create_repo repo &&
317 echo something >repo/something &&
318 git -C repo add something &&
319 git -C repo commit -m foo &&
320
321 BLOB=$(git -C repo hash-object -w something) &&
322 promise_and_delete "$BLOB" &&
323
324 git -C repo config core.repositoryformatversion 1 &&
325 git -C repo config extensions.partialclone "arbitrary string" &&
326 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
327 grep $(git -C repo rev-parse HEAD) out &&
328 ! grep $BLOB out
329'
330
331test_expect_success 'rev-list stops traversal at promisor commit, tree, and blob' '
332 rm -rf repo &&
333 test_create_repo repo &&
334 test_commit -C repo foo &&
335 test_commit -C repo bar &&
336 test_commit -C repo baz &&
337
338 COMMIT=$(git -C repo rev-parse foo) &&
339 TREE=$(git -C repo rev-parse bar^{tree}) &&
340 BLOB=$(git hash-object repo/baz.t) &&
341 printf "%s\n%s\n%s\n" $COMMIT $TREE $BLOB | pack_as_from_promisor &&
342
343 git -C repo config core.repositoryformatversion 1 &&
344 git -C repo config extensions.partialclone "arbitrary string" &&
345 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
346 ! grep $COMMIT out &&
347 ! grep $TREE out &&
348 ! grep $BLOB out &&
349 grep $(git -C repo rev-parse bar) out # sanity check that some walking was done
350'
351
4cf67869 352test_expect_success 'rev-list dies for missing objects on cmd line' '
df11e196
JT
353 rm -rf repo &&
354 test_create_repo repo &&
355 test_commit -C repo foo &&
356 test_commit -C repo bar &&
357 test_commit -C repo baz &&
358
359 COMMIT=$(git -C repo rev-parse foo) &&
360 TREE=$(git -C repo rev-parse bar^{tree}) &&
361 BLOB=$(git hash-object repo/baz.t) &&
362
363 promise_and_delete $COMMIT &&
364 promise_and_delete $TREE &&
365 promise_and_delete $BLOB &&
366
367 git -C repo config core.repositoryformatversion 1 &&
368 git -C repo config extensions.partialclone "arbitrary string" &&
4cf67869
MD
369
370 for OBJ in "$COMMIT" "$TREE" "$BLOB"; do
371 test_must_fail git -C repo rev-list --objects \
372 --exclude-promisor-objects "$OBJ" &&
373 test_must_fail git -C repo rev-list --objects-edge-aggressive \
374 --exclude-promisor-objects "$OBJ" &&
375
376 # Do not die or crash when --ignore-missing is passed.
377 git -C repo rev-list --ignore-missing --objects \
378 --exclude-promisor-objects "$OBJ" &&
379 git -C repo rev-list --ignore-missing --objects-edge-aggressive \
380 --exclude-promisor-objects "$OBJ"
381 done
df11e196
JT
382'
383
5d19e813 384test_expect_success 'gc repacks promisor objects separately from non-promisor objects' '
0c16cd49
JT
385 rm -rf repo &&
386 test_create_repo repo &&
5d19e813
JT
387 test_commit -C repo one &&
388 test_commit -C repo two &&
0c16cd49 389
5d19e813
JT
390 TREE_ONE=$(git -C repo rev-parse one^{tree}) &&
391 printf "$TREE_ONE\n" | pack_as_from_promisor &&
392 TREE_TWO=$(git -C repo rev-parse two^{tree}) &&
393 printf "$TREE_TWO\n" | pack_as_from_promisor &&
0c16cd49
JT
394
395 git -C repo config core.repositoryformatversion 1 &&
396 git -C repo config extensions.partialclone "arbitrary string" &&
397 git -C repo gc &&
398
5d19e813
JT
399 # Ensure that exactly one promisor packfile exists, and that it
400 # contains the trees but not the commits
401 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
402 test_line_count = 1 promisorlist &&
403 PROMISOR_PACKFILE=$(sed "s/.promisor/.pack/" <promisorlist) &&
404 git verify-pack $PROMISOR_PACKFILE -v >out &&
405 grep "$TREE_ONE" out &&
406 grep "$TREE_TWO" out &&
407 ! grep "$(git -C repo rev-parse one)" out &&
408 ! grep "$(git -C repo rev-parse two)" out &&
409
410 # Remove the promisor packfile and associated files
411 rm $(sed "s/.promisor//" <promisorlist).* &&
412
413 # Ensure that the single other pack contains the commits, but not the
414 # trees
0c16cd49
JT
415 ls repo/.git/objects/pack/pack-*.pack >packlist &&
416 test_line_count = 1 packlist &&
417 git verify-pack repo/.git/objects/pack/pack-*.pack -v >out &&
5d19e813
JT
418 grep "$(git -C repo rev-parse one)" out &&
419 grep "$(git -C repo rev-parse two)" out &&
420 ! grep "$TREE_ONE" out &&
421 ! grep "$TREE_TWO" out
422'
423
424test_expect_success 'gc does not repack promisor objects if there are none' '
425 rm -rf repo &&
426 test_create_repo repo &&
427 test_commit -C repo one &&
428
429 git -C repo config core.repositoryformatversion 1 &&
430 git -C repo config extensions.partialclone "arbitrary string" &&
431 git -C repo gc &&
432
433 # Ensure that only one pack exists
434 ls repo/.git/objects/pack/pack-*.pack >packlist &&
435 test_line_count = 1 packlist
436'
437
438repack_and_check () {
439 rm -rf repo2 &&
440 cp -r repo repo2 &&
441 git -C repo2 repack $1 -d &&
442 git -C repo2 fsck &&
443
444 git -C repo2 cat-file -e $2 &&
445 git -C repo2 cat-file -e $3
446}
447
448test_expect_success 'repack -d does not irreversibly delete promisor objects' '
449 rm -rf repo &&
450 test_create_repo repo &&
451 git -C repo config core.repositoryformatversion 1 &&
452 git -C repo config extensions.partialclone "arbitrary string" &&
453
454 git -C repo commit --allow-empty -m one &&
455 git -C repo commit --allow-empty -m two &&
456 git -C repo commit --allow-empty -m three &&
457 git -C repo commit --allow-empty -m four &&
458 ONE=$(git -C repo rev-parse HEAD^^^) &&
459 TWO=$(git -C repo rev-parse HEAD^^) &&
460 THREE=$(git -C repo rev-parse HEAD^) &&
461
462 printf "$TWO\n" | pack_as_from_promisor &&
463 printf "$THREE\n" | pack_as_from_promisor &&
464 delete_object repo "$ONE" &&
465
466 repack_and_check -a "$TWO" "$THREE" &&
467 repack_and_check -A "$TWO" "$THREE" &&
468 repack_and_check -l "$TWO" "$THREE"
0c16cd49
JT
469'
470
471test_expect_success 'gc stops traversal when a missing but promised object is reached' '
472 rm -rf repo &&
473 test_create_repo repo &&
474 test_commit -C repo my_commit &&
475
476 TREE_HASH=$(git -C repo rev-parse HEAD^{tree}) &&
477 HASH=$(promise_and_delete $TREE_HASH) &&
478
479 git -C repo config core.repositoryformatversion 1 &&
480 git -C repo config extensions.partialclone "arbitrary string" &&
481 git -C repo gc &&
482
483 # Ensure that the promisor packfile still exists, and remove it
484 test -e repo/.git/objects/pack/pack-$HASH.pack &&
485 rm repo/.git/objects/pack/pack-$HASH.* &&
486
487 # Ensure that the single other pack contains the commit, but not the tree
488 ls repo/.git/objects/pack/pack-*.pack >packlist &&
489 test_line_count = 1 packlist &&
490 git verify-pack repo/.git/objects/pack/pack-*.pack -v >out &&
491 grep "$(git -C repo rev-parse HEAD)" out &&
492 ! grep "$TREE_HASH" out
493'
494
8b4c0103
JT
495. "$TEST_DIRECTORY"/lib-httpd.sh
496start_httpd
497
498test_expect_success 'fetching of missing objects from an HTTP server' '
499 rm -rf repo &&
500 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
501 test_create_repo "$SERVER" &&
502 test_commit -C "$SERVER" foo &&
503 git -C "$SERVER" repack -a -d --write-bitmap-index &&
504
505 git clone $HTTPD_URL/smart/server repo &&
506 HASH=$(git -C repo rev-parse foo) &&
507 rm -rf repo/.git/objects/* &&
508
509 git -C repo config core.repositoryformatversion 1 &&
510 git -C repo config extensions.partialclone "origin" &&
511 git -C repo cat-file -p "$HASH" &&
512
513 # Ensure that the .promisor file is written, and check that its
514 # associated packfile contains the object
515 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
516 test_line_count = 1 promisorlist &&
517 IDX=$(cat promisorlist | sed "s/promisor$/idx/") &&
518 git verify-pack --verbose "$IDX" | grep "$HASH"
519'
520
521stop_httpd
522
498f1f61 523test_done