list-objects: support for skipping tree traversal
[git.git] / t / t0410-partial-clone.sh
blob2f4ea487a4304d0282f655aca6f1013d075489ad
1 #!/bin/sh
3 test_description='partial clone'
5 . ./test-lib.sh
7 delete_object () {
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 &&
14 echo $HASH
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' '
34 rm -rf repo &&
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 &&
49 # Normally, it fails
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" &&
55 git -C repo fsck
58 test_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 &&
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" &&
78 git -C repo fsck
81 test_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 &&
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' '
100 rm -rf repo &&
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" &&
112 git -C repo fsck
115 test_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" &&
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" &&
135 git -C repo fsck
138 test_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 &&
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' '
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 &&
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' '
174 rm -rf repo &&
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 &&
186 ! grep $FOO out
189 test_expect_success 'missing tree objects with --missing=allow-promisor and --exclude-promisor-objects' '
190 rm -rf repo &&
191 test_create_repo repo &&
192 test_commit -C repo foo &&
193 test_commit -C repo bar &&
194 test_commit -C repo baz &&
196 promise_and_delete $(git -C repo rev-parse bar^{tree}) &&
197 promise_and_delete $(git -C repo rev-parse foo^{tree}) &&
199 git -C repo config core.repositoryformatversion 1 &&
200 git -C repo config extensions.partialclone "arbitrary string" &&
202 git -C repo rev-list --missing=allow-promisor --objects HEAD >objs 2>rev_list_err &&
203 test_must_be_empty rev_list_err &&
204 # 3 commits, 3 blobs, and 1 tree
205 test_line_count = 7 objs &&
207 # Do the same for --exclude-promisor-objects, but with all trees gone.
208 promise_and_delete $(git -C repo rev-parse baz^{tree}) &&
209 git -C repo rev-list --exclude-promisor-objects --objects HEAD >objs 2>rev_list_err &&
210 test_must_be_empty rev_list_err &&
211 # 3 commits, no blobs or trees
212 test_line_count = 3 objs
215 test_expect_success 'missing non-root tree object and rev-list' '
216 rm -rf repo &&
217 test_create_repo repo &&
218 mkdir repo/dir &&
219 echo foo >repo/dir/foo &&
220 git -C repo add dir/foo &&
221 git -C repo commit -m "commit dir/foo" &&
223 promise_and_delete $(git -C repo rev-parse HEAD:dir) &&
225 git -C repo config core.repositoryformatversion 1 &&
226 git -C repo config extensions.partialclone "arbitrary string" &&
228 git -C repo rev-list --missing=allow-any --objects HEAD >objs 2>rev_list_err &&
229 test_must_be_empty rev_list_err &&
230 # 1 commit and 1 tree
231 test_line_count = 2 objs
234 test_expect_success 'rev-list stops traversal at missing and promised tree' '
235 rm -rf repo &&
236 test_create_repo repo &&
237 test_commit -C repo foo &&
238 mkdir repo/a_dir &&
239 echo something >repo/a_dir/something &&
240 git -C repo add a_dir/something &&
241 git -C repo commit -m bar &&
243 # foo^{tree} (tree referenced from commit)
244 TREE=$(git -C repo rev-parse foo^{tree}) &&
246 # a tree referenced by HEAD^{tree} (tree referenced from tree)
247 TREE2=$(git -C repo ls-tree HEAD^{tree} | grep " tree " | head -1 | cut -b13-52) &&
249 promise_and_delete "$TREE" &&
250 promise_and_delete "$TREE2" &&
252 git -C repo config core.repositoryformatversion 1 &&
253 git -C repo config extensions.partialclone "arbitrary string" &&
254 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
255 grep $(git -C repo rev-parse foo) out &&
256 ! grep $TREE out &&
257 grep $(git -C repo rev-parse HEAD) out &&
258 ! grep $TREE2 out
261 test_expect_success 'rev-list stops traversal at missing and promised blob' '
262 rm -rf repo &&
263 test_create_repo repo &&
264 echo something >repo/something &&
265 git -C repo add something &&
266 git -C repo commit -m foo &&
268 BLOB=$(git -C repo hash-object -w something) &&
269 promise_and_delete "$BLOB" &&
271 git -C repo config core.repositoryformatversion 1 &&
272 git -C repo config extensions.partialclone "arbitrary string" &&
273 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
274 grep $(git -C repo rev-parse HEAD) out &&
275 ! grep $BLOB out
278 test_expect_success 'rev-list stops traversal at promisor commit, tree, and blob' '
279 rm -rf repo &&
280 test_create_repo repo &&
281 test_commit -C repo foo &&
282 test_commit -C repo bar &&
283 test_commit -C repo baz &&
285 COMMIT=$(git -C repo rev-parse foo) &&
286 TREE=$(git -C repo rev-parse bar^{tree}) &&
287 BLOB=$(git hash-object repo/baz.t) &&
288 printf "%s\n%s\n%s\n" $COMMIT $TREE $BLOB | pack_as_from_promisor &&
290 git -C repo config core.repositoryformatversion 1 &&
291 git -C repo config extensions.partialclone "arbitrary string" &&
292 git -C repo rev-list --exclude-promisor-objects --objects HEAD >out &&
293 ! grep $COMMIT out &&
294 ! grep $TREE out &&
295 ! grep $BLOB out &&
296 grep $(git -C repo rev-parse bar) out # sanity check that some walking was done
299 test_expect_success 'rev-list accepts missing and promised objects on command line' '
300 rm -rf repo &&
301 test_create_repo repo &&
302 test_commit -C repo foo &&
303 test_commit -C repo bar &&
304 test_commit -C repo baz &&
306 COMMIT=$(git -C repo rev-parse foo) &&
307 TREE=$(git -C repo rev-parse bar^{tree}) &&
308 BLOB=$(git hash-object repo/baz.t) &&
310 promise_and_delete $COMMIT &&
311 promise_and_delete $TREE &&
312 promise_and_delete $BLOB &&
314 git -C repo config core.repositoryformatversion 1 &&
315 git -C repo config extensions.partialclone "arbitrary string" &&
316 git -C repo rev-list --exclude-promisor-objects --objects "$COMMIT" "$TREE" "$BLOB"
319 test_expect_success 'gc does not repack promisor objects' '
320 rm -rf repo &&
321 test_create_repo repo &&
322 test_commit -C repo my_commit &&
324 TREE_HASH=$(git -C repo rev-parse HEAD^{tree}) &&
325 HASH=$(printf "$TREE_HASH\n" | pack_as_from_promisor) &&
327 git -C repo config core.repositoryformatversion 1 &&
328 git -C repo config extensions.partialclone "arbitrary string" &&
329 git -C repo gc &&
331 # Ensure that the promisor packfile still exists, and remove it
332 test -e repo/.git/objects/pack/pack-$HASH.pack &&
333 rm repo/.git/objects/pack/pack-$HASH.* &&
335 # Ensure that the single other pack contains the commit, but not the tree
336 ls repo/.git/objects/pack/pack-*.pack >packlist &&
337 test_line_count = 1 packlist &&
338 git verify-pack repo/.git/objects/pack/pack-*.pack -v >out &&
339 grep "$(git -C repo rev-parse HEAD)" out &&
340 ! grep "$TREE_HASH" out
343 test_expect_success 'gc stops traversal when a missing but promised object is reached' '
344 rm -rf repo &&
345 test_create_repo repo &&
346 test_commit -C repo my_commit &&
348 TREE_HASH=$(git -C repo rev-parse HEAD^{tree}) &&
349 HASH=$(promise_and_delete $TREE_HASH) &&
351 git -C repo config core.repositoryformatversion 1 &&
352 git -C repo config extensions.partialclone "arbitrary string" &&
353 git -C repo gc &&
355 # Ensure that the promisor packfile still exists, and remove it
356 test -e repo/.git/objects/pack/pack-$HASH.pack &&
357 rm repo/.git/objects/pack/pack-$HASH.* &&
359 # Ensure that the single other pack contains the commit, but not the tree
360 ls repo/.git/objects/pack/pack-*.pack >packlist &&
361 test_line_count = 1 packlist &&
362 git verify-pack repo/.git/objects/pack/pack-*.pack -v >out &&
363 grep "$(git -C repo rev-parse HEAD)" out &&
364 ! grep "$TREE_HASH" out
367 LIB_HTTPD_PORT=12345 # default port, 410, cannot be used as non-root
368 . "$TEST_DIRECTORY"/lib-httpd.sh
369 start_httpd
371 test_expect_success 'fetching of missing objects from an HTTP server' '
372 rm -rf repo &&
373 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
374 test_create_repo "$SERVER" &&
375 test_commit -C "$SERVER" foo &&
376 git -C "$SERVER" repack -a -d --write-bitmap-index &&
378 git clone $HTTPD_URL/smart/server repo &&
379 HASH=$(git -C repo rev-parse foo) &&
380 rm -rf repo/.git/objects/* &&
382 git -C repo config core.repositoryformatversion 1 &&
383 git -C repo config extensions.partialclone "origin" &&
384 git -C repo cat-file -p "$HASH" &&
386 # Ensure that the .promisor file is written, and check that its
387 # associated packfile contains the object
388 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
389 test_line_count = 1 promisorlist &&
390 IDX=$(cat promisorlist | sed "s/promisor$/idx/") &&
391 git verify-pack --verbose "$IDX" | grep "$HASH"
394 stop_httpd
396 test_done