3 test_description='partial clone'
8 rm $1/.git/objects/$(echo $2 | sed -e 's|^..|&/|')
11 pack_as_from_promisor () {
12 HASH=$(git -C repo pack-objects .git/objects/pack/pack) &&
13 >repo/.git/objects/pack/pack-$HASH.promisor &&
17 promise_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 &&
21 # tag -d prints a message to stdout, so redirect it
22 git -C repo tag -d my_annotated_tag >/dev/null &&
23 delete_object repo "$HASH"
26 test_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
33 test_expect_success 'missing reflog object, but promised by a commit, passes fsck' '
35 test_create_repo repo &&
36 test_commit -C repo my_commit &&
38 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
39 C=$(git -C repo commit-tree -m c -p $A HEAD^{tree}) &&
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" &&
46 # State that we got $C, which refers to $A, from promisor
47 printf "$C\n" | pack_as_from_promisor &&
50 test_must_fail git -C repo fsck &&
52 # But with the extension, it succeeds
53 git -C repo config core.repositoryformatversion 1 &&
54 git -C repo config extensions.partialclone "arbitrary string" &&
58 test_expect_success 'missing reflog object, but promised by a tag, passes fsck' '
60 test_create_repo repo &&
61 test_commit -C repo my_commit &&
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 &&
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" &&
73 # State that we got $T, which refers to $A, from promisor
74 printf "$T\n" | pack_as_from_promisor &&
76 git -C repo config core.repositoryformatversion 1 &&
77 git -C repo config extensions.partialclone "arbitrary string" &&
81 test_expect_success 'missing reflog object alone fails fsck, even with extension set' '
83 test_create_repo repo &&
84 test_commit -C repo my_commit &&
86 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
87 B=$(git -C repo commit-tree -m b HEAD^{tree}) &&
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" &&
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
99 test_expect_success 'missing ref object, but promised, passes fsck' '
101 test_create_repo repo &&
102 test_commit -C repo my_commit &&
104 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
106 # Reference $A only from ref
107 git -C repo branch my_branch "$A" &&
108 promise_and_delete "$A" &&
110 git -C repo config core.repositoryformatversion 1 &&
111 git -C repo config extensions.partialclone "arbitrary string" &&
115 test_expect_success 'missing object, but promised, passes fsck' '
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" &&
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) &&
128 promise_and_delete "$C" &&
129 promise_and_delete "$T" &&
130 promise_and_delete "$B" &&
131 promise_and_delete "$AT" &&
133 git -C repo config core.repositoryformatversion 1 &&
134 git -C repo config extensions.partialclone "arbitrary string" &&
138 test_expect_success 'missing CLI object, but promised, passes fsck' '
140 test_create_repo repo &&
141 test_commit -C repo my_commit &&
143 A=$(git -C repo commit-tree -m a HEAD^{tree}) &&
144 promise_and_delete "$A" &&
146 git -C repo config core.repositoryformatversion 1 &&
147 git -C repo config extensions.partialclone "arbitrary string" &&
148 git -C repo fsck "$A"
151 test_expect_success 'fetching of missing objects' '
153 test_create_repo server &&
154 test_commit -C server foo &&
155 git -C server repack -a -d --write-bitmap-index &&
157 git clone "file://$(pwd)/server" repo &&
158 HASH=$(git -C repo rev-parse foo) &&
159 rm -rf repo/.git/objects/* &&
161 git -C repo config core.repositoryformatversion 1 &&
162 git -C repo config extensions.partialclone "origin" &&
163 git -C repo cat-file -p "$HASH" &&
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"
173 test_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 &&
179 rm -rf repo/.git/objects/* &&
181 GIT_TRACE_PACKET="$(pwd)/trace" git -C repo cat-file -p "$HASH" &&
182 grep "git< fetch=.*ref-in-want" trace
185 test_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 &&
191 git clone "file://$(pwd)/server" repo &&
192 git hash-object repo/foo.t >blobhash &&
193 rm -rf repo/.git/objects/* &&
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" &&
200 git -C repo cat-file -p $(cat blobhash)
203 test_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 &&
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/* &&
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) &&
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
226 test_expect_success 'rev-list stops traversal at missing and promised commit' '
228 test_create_repo repo &&
229 test_commit -C repo foo &&
230 test_commit -C repo bar &&
232 FOO=$(git -C repo rev-parse foo) &&
233 promise_and_delete "$FOO" &&
235 git -C repo config core.repositoryformatversion 1 &&
236 git -C repo config extensions.partialclone "arbitrary string" &&
237 git -C repo rev-list --exclude-promisor-objects --objects bar >out &&
238 grep $(git -C repo rev-parse bar) out &&
242 test_expect_success 'rev-list stops traversal at missing and promised tree' '
244 test_create_repo repo &&
245 test_commit -C repo foo &&
247 echo something >repo/a_dir/something &&
248 git -C repo add a_dir/something &&
249 git -C repo commit -m bar &&
251 # foo^{tree} (tree referenced from commit)
252 TREE=$(git -C repo rev-parse foo^{tree}) &&
254 # a tree referenced by HEAD^{tree} (tree referenced from tree)
255 TREE2=$(git -C repo ls-tree HEAD^{tree} | grep " tree " | head -1 | cut -b13-52) &&
257 promise_and_delete "$TREE" &&
258 promise_and_delete "$TREE2" &&
260 git -C repo config core.repositoryformatversion 1 &&
261 git -C repo config extensions.partialclone "arbitrary string" &&
262 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
263 grep $(git -C repo rev-parse foo) out &&
265 grep $(git -C repo rev-parse HEAD) out &&
269 test_expect_success 'rev-list stops traversal at missing and promised blob' '
271 test_create_repo repo &&
272 echo something >repo/something &&
273 git -C repo add something &&
274 git -C repo commit -m foo &&
276 BLOB=$(git -C repo hash-object -w something) &&
277 promise_and_delete "$BLOB" &&
279 git -C repo config core.repositoryformatversion 1 &&
280 git -C repo config extensions.partialclone "arbitrary string" &&
281 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
282 grep $(git -C repo rev-parse HEAD) out &&
286 test_expect_success 'rev-list stops traversal at promisor commit, tree, and blob' '
288 test_create_repo repo &&
289 test_commit -C repo foo &&
290 test_commit -C repo bar &&
291 test_commit -C repo baz &&
293 COMMIT=$(git -C repo rev-parse foo) &&
294 TREE=$(git -C repo rev-parse bar^{tree}) &&
295 BLOB=$(git hash-object repo/baz.t) &&
296 printf "%s\n%s\n%s\n" $COMMIT $TREE $BLOB | pack_as_from_promisor &&
298 git -C repo config core.repositoryformatversion 1 &&
299 git -C repo config extensions.partialclone "arbitrary string" &&
300 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
301 ! grep $COMMIT out &&
304 grep $(git -C repo rev-parse bar) out # sanity check that some walking was done
307 test_expect_success 'rev-list accepts missing and promised objects on command line' '
309 test_create_repo repo &&
310 test_commit -C repo foo &&
311 test_commit -C repo bar &&
312 test_commit -C repo baz &&
314 COMMIT=$(git -C repo rev-parse foo) &&
315 TREE=$(git -C repo rev-parse bar^{tree}) &&
316 BLOB=$(git hash-object repo/baz.t) &&
318 promise_and_delete $COMMIT &&
319 promise_and_delete $TREE &&
320 promise_and_delete $BLOB &&
322 git -C repo config core.repositoryformatversion 1 &&
323 git -C repo config extensions.partialclone "arbitrary string" &&
324 git -C repo rev-list --exclude-promisor-objects --objects "$COMMIT" "$TREE" "$BLOB"
327 test_expect_success 'gc repacks promisor objects separately from non-promisor objects' '
329 test_create_repo repo &&
330 test_commit -C repo one &&
331 test_commit -C repo two &&
333 TREE_ONE=$(git -C repo rev-parse one^{tree}) &&
334 printf "$TREE_ONE\n" | pack_as_from_promisor &&
335 TREE_TWO=$(git -C repo rev-parse two^{tree}) &&
336 printf "$TREE_TWO\n" | pack_as_from_promisor &&
338 git -C repo config core.repositoryformatversion 1 &&
339 git -C repo config extensions.partialclone "arbitrary string" &&
342 # Ensure that exactly one promisor packfile exists, and that it
343 # contains the trees but not the commits
344 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
345 test_line_count = 1 promisorlist &&
346 PROMISOR_PACKFILE=$(sed "s/.promisor/.pack/" <promisorlist) &&
347 git verify-pack $PROMISOR_PACKFILE -v >out &&
348 grep "$TREE_ONE" out &&
349 grep "$TREE_TWO" out &&
350 ! grep "$(git -C repo rev-parse one)" out &&
351 ! grep "$(git -C repo rev-parse two)" out &&
353 # Remove the promisor packfile and associated files
354 rm $(sed "s/.promisor//" <promisorlist).* &&
356 # Ensure that the single other pack contains the commits, but not the
358 ls repo/.git/objects/pack/pack-*.pack >packlist &&
359 test_line_count = 1 packlist &&
360 git verify-pack repo/.git/objects/pack/pack-*.pack -v >out &&
361 grep "$(git -C repo rev-parse one)" out &&
362 grep "$(git -C repo rev-parse two)" out &&
363 ! grep "$TREE_ONE" out &&
364 ! grep "$TREE_TWO" out
367 test_expect_success 'gc does not repack promisor objects if there are none' '
369 test_create_repo repo &&
370 test_commit -C repo one &&
372 git -C repo config core.repositoryformatversion 1 &&
373 git -C repo config extensions.partialclone "arbitrary string" &&
376 # Ensure that only one pack exists
377 ls repo/.git/objects/pack/pack-*.pack >packlist &&
378 test_line_count = 1 packlist
381 repack_and_check () {
384 git -C repo2 repack $1 -d &&
387 git -C repo2 cat-file -e $2 &&
388 git -C repo2 cat-file -e $3
391 test_expect_success 'repack -d does not irreversibly delete promisor objects' '
393 test_create_repo repo &&
394 git -C repo config core.repositoryformatversion 1 &&
395 git -C repo config extensions.partialclone "arbitrary string" &&
397 git -C repo commit --allow-empty -m one &&
398 git -C repo commit --allow-empty -m two &&
399 git -C repo commit --allow-empty -m three &&
400 git -C repo commit --allow-empty -m four &&
401 ONE=$(git -C repo rev-parse HEAD^^^) &&
402 TWO=$(git -C repo rev-parse HEAD^^) &&
403 THREE=$(git -C repo rev-parse HEAD^) &&
405 printf "$TWO\n" | pack_as_from_promisor &&
406 printf "$THREE\n" | pack_as_from_promisor &&
407 delete_object repo "$ONE" &&
409 repack_and_check -a "$TWO" "$THREE" &&
410 repack_and_check -A "$TWO" "$THREE" &&
411 repack_and_check -l "$TWO" "$THREE"
414 test_expect_success 'gc stops traversal when a missing but promised object is reached' '
416 test_create_repo repo &&
417 test_commit -C repo my_commit &&
419 TREE_HASH=$(git -C repo rev-parse HEAD^{tree}) &&
420 HASH=$(promise_and_delete $TREE_HASH) &&
422 git -C repo config core.repositoryformatversion 1 &&
423 git -C repo config extensions.partialclone "arbitrary string" &&
426 # Ensure that the promisor packfile still exists, and remove it
427 test -e repo/.git/objects/pack/pack-$HASH.pack &&
428 rm repo/.git/objects/pack/pack-$HASH.* &&
430 # Ensure that the single other pack contains the commit, but not the tree
431 ls repo/.git/objects/pack/pack-*.pack >packlist &&
432 test_line_count = 1 packlist &&
433 git verify-pack repo/.git/objects/pack/pack-*.pack -v >out &&
434 grep "$(git -C repo rev-parse HEAD)" out &&
435 ! grep "$TREE_HASH" out
438 LIB_HTTPD_PORT=12345 # default port, 410, cannot be used as non-root
439 . "$TEST_DIRECTORY"/lib-httpd.sh
442 test_expect_success 'fetching of missing objects from an HTTP server' '
444 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
445 test_create_repo "$SERVER" &&
446 test_commit -C "$SERVER" foo &&
447 git -C "$SERVER" repack -a -d --write-bitmap-index &&
449 git clone $HTTPD_URL/smart/server repo &&
450 HASH=$(git -C repo rev-parse foo) &&
451 rm -rf repo/.git/objects/* &&
453 git -C repo config core.repositoryformatversion 1 &&
454 git -C repo config extensions.partialclone "origin" &&
455 git -C repo cat-file -p "$HASH" &&
457 # Ensure that the .promisor file is written, and check that its
458 # associated packfile contains the object
459 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
460 test_line_count = 1 promisorlist &&
461 IDX=$(cat promisorlist | sed "s/promisor$/idx/") &&
462 git verify-pack --verbose "$IDX" | grep "$HASH"