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 'rev-list stops traversal at missing and promised commit' '
175 test_create_repo repo &&
176 test_commit -C repo foo &&
177 test_commit -C repo bar &&
179 FOO=$(git -C repo rev-parse foo) &&
180 promise_and_delete "$FOO" &&
182 git -C repo config core.repositoryformatversion 1 &&
183 git -C repo config extensions.partialclone "arbitrary string" &&
184 git -C repo rev-list --exclude-promisor-objects --objects bar >out &&
185 grep $(git -C repo rev-parse bar) out &&
189 test_expect_success 'rev-list stops traversal at missing and promised tree' '
191 test_create_repo repo &&
192 test_commit -C repo foo &&
194 echo something >repo/a_dir/something &&
195 git -C repo add a_dir/something &&
196 git -C repo commit -m bar &&
198 # foo^{tree} (tree referenced from commit)
199 TREE=$(git -C repo rev-parse foo^{tree}) &&
201 # a tree referenced by HEAD^{tree} (tree referenced from tree)
202 TREE2=$(git -C repo ls-tree HEAD^{tree} | grep " tree " | head -1 | cut -b13-52) &&
204 promise_and_delete "$TREE" &&
205 promise_and_delete "$TREE2" &&
207 git -C repo config core.repositoryformatversion 1 &&
208 git -C repo config extensions.partialclone "arbitrary string" &&
209 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
210 grep $(git -C repo rev-parse foo) out &&
212 grep $(git -C repo rev-parse HEAD) out &&
216 test_expect_success 'rev-list stops traversal at missing and promised blob' '
218 test_create_repo repo &&
219 echo something >repo/something &&
220 git -C repo add something &&
221 git -C repo commit -m foo &&
223 BLOB=$(git -C repo hash-object -w something) &&
224 promise_and_delete "$BLOB" &&
226 git -C repo config core.repositoryformatversion 1 &&
227 git -C repo config extensions.partialclone "arbitrary string" &&
228 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
229 grep $(git -C repo rev-parse HEAD) out &&
233 test_expect_success 'rev-list stops traversal at promisor commit, tree, and blob' '
235 test_create_repo repo &&
236 test_commit -C repo foo &&
237 test_commit -C repo bar &&
238 test_commit -C repo baz &&
240 COMMIT=$(git -C repo rev-parse foo) &&
241 TREE=$(git -C repo rev-parse bar^{tree}) &&
242 BLOB=$(git hash-object repo/baz.t) &&
243 printf "%s\n%s\n%s\n" $COMMIT $TREE $BLOB | pack_as_from_promisor &&
245 git -C repo config core.repositoryformatversion 1 &&
246 git -C repo config extensions.partialclone "arbitrary string" &&
247 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
248 ! grep $COMMIT out &&
251 grep $(git -C repo rev-parse bar) out # sanity check that some walking was done
254 test_expect_success 'rev-list accepts missing and promised objects on command line' '
256 test_create_repo repo &&
257 test_commit -C repo foo &&
258 test_commit -C repo bar &&
259 test_commit -C repo baz &&
261 COMMIT=$(git -C repo rev-parse foo) &&
262 TREE=$(git -C repo rev-parse bar^{tree}) &&
263 BLOB=$(git hash-object repo/baz.t) &&
265 promise_and_delete $COMMIT &&
266 promise_and_delete $TREE &&
267 promise_and_delete $BLOB &&
269 git -C repo config core.repositoryformatversion 1 &&
270 git -C repo config extensions.partialclone "arbitrary string" &&
271 git -C repo rev-list --exclude-promisor-objects --objects "$COMMIT" "$TREE" "$BLOB"
274 test_expect_success 'gc repacks promisor objects separately from non-promisor objects' '
276 test_create_repo repo &&
277 test_commit -C repo one &&
278 test_commit -C repo two &&
280 TREE_ONE=$(git -C repo rev-parse one^{tree}) &&
281 printf "$TREE_ONE\n" | pack_as_from_promisor &&
282 TREE_TWO=$(git -C repo rev-parse two^{tree}) &&
283 printf "$TREE_TWO\n" | pack_as_from_promisor &&
285 git -C repo config core.repositoryformatversion 1 &&
286 git -C repo config extensions.partialclone "arbitrary string" &&
289 # Ensure that exactly one promisor packfile exists, and that it
290 # contains the trees but not the commits
291 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
292 test_line_count = 1 promisorlist &&
293 PROMISOR_PACKFILE=$(sed "s/.promisor/.pack/" <promisorlist) &&
294 git verify-pack $PROMISOR_PACKFILE -v >out &&
295 grep "$TREE_ONE" out &&
296 grep "$TREE_TWO" out &&
297 ! grep "$(git -C repo rev-parse one)" out &&
298 ! grep "$(git -C repo rev-parse two)" out &&
300 # Remove the promisor packfile and associated files
301 rm $(sed "s/.promisor//" <promisorlist).* &&
303 # Ensure that the single other pack contains the commits, but not the
305 ls repo/.git/objects/pack/pack-*.pack >packlist &&
306 test_line_count = 1 packlist &&
307 git verify-pack repo/.git/objects/pack/pack-*.pack -v >out &&
308 grep "$(git -C repo rev-parse one)" out &&
309 grep "$(git -C repo rev-parse two)" out &&
310 ! grep "$TREE_ONE" out &&
311 ! grep "$TREE_TWO" out
314 test_expect_success 'gc does not repack promisor objects if there are none' '
316 test_create_repo repo &&
317 test_commit -C repo one &&
319 git -C repo config core.repositoryformatversion 1 &&
320 git -C repo config extensions.partialclone "arbitrary string" &&
323 # Ensure that only one pack exists
324 ls repo/.git/objects/pack/pack-*.pack >packlist &&
325 test_line_count = 1 packlist
328 repack_and_check () {
331 git -C repo2 repack $1 -d &&
334 git -C repo2 cat-file -e $2 &&
335 git -C repo2 cat-file -e $3
338 test_expect_success 'repack -d does not irreversibly delete promisor objects' '
340 test_create_repo repo &&
341 git -C repo config core.repositoryformatversion 1 &&
342 git -C repo config extensions.partialclone "arbitrary string" &&
344 git -C repo commit --allow-empty -m one &&
345 git -C repo commit --allow-empty -m two &&
346 git -C repo commit --allow-empty -m three &&
347 git -C repo commit --allow-empty -m four &&
348 ONE=$(git -C repo rev-parse HEAD^^^) &&
349 TWO=$(git -C repo rev-parse HEAD^^) &&
350 THREE=$(git -C repo rev-parse HEAD^) &&
352 printf "$TWO\n" | pack_as_from_promisor &&
353 printf "$THREE\n" | pack_as_from_promisor &&
354 delete_object repo "$ONE" &&
356 repack_and_check -a "$TWO" "$THREE" &&
357 repack_and_check -A "$TWO" "$THREE" &&
358 repack_and_check -l "$TWO" "$THREE"
361 test_expect_success 'gc stops traversal when a missing but promised object is reached' '
363 test_create_repo repo &&
364 test_commit -C repo my_commit &&
366 TREE_HASH=$(git -C repo rev-parse HEAD^{tree}) &&
367 HASH=$(promise_and_delete $TREE_HASH) &&
369 git -C repo config core.repositoryformatversion 1 &&
370 git -C repo config extensions.partialclone "arbitrary string" &&
373 # Ensure that the promisor packfile still exists, and remove it
374 test -e repo/.git/objects/pack/pack-$HASH.pack &&
375 rm repo/.git/objects/pack/pack-$HASH.* &&
377 # Ensure that the single other pack contains the commit, but not the tree
378 ls repo/.git/objects/pack/pack-*.pack >packlist &&
379 test_line_count = 1 packlist &&
380 git verify-pack repo/.git/objects/pack/pack-*.pack -v >out &&
381 grep "$(git -C repo rev-parse HEAD)" out &&
382 ! grep "$TREE_HASH" out
385 LIB_HTTPD_PORT=12345 # default port, 410, cannot be used as non-root
386 . "$TEST_DIRECTORY"/lib-httpd.sh
389 test_expect_success 'fetching of missing objects from an HTTP server' '
391 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
392 test_create_repo "$SERVER" &&
393 test_commit -C "$SERVER" foo &&
394 git -C "$SERVER" repack -a -d --write-bitmap-index &&
396 git clone $HTTPD_URL/smart/server repo &&
397 HASH=$(git -C repo rev-parse foo) &&
398 rm -rf repo/.git/objects/* &&
400 git -C repo config core.repositoryformatversion 1 &&
401 git -C repo config extensions.partialclone "origin" &&
402 git -C repo cat-file -p "$HASH" &&
404 # Ensure that the .promisor file is written, and check that its
405 # associated packfile contains the object
406 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
407 test_line_count = 1 promisorlist &&
408 IDX=$(cat promisorlist | sed "s/promisor$/idx/") &&
409 git verify-pack --verbose "$IDX" | grep "$HASH"