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 does not repack promisor objects' '
276 test_create_repo repo &&
277 test_commit -C repo my_commit &&
279 TREE_HASH=$(git -C repo rev-parse HEAD^{tree}) &&
280 HASH=$(printf "$TREE_HASH\n" | pack_as_from_promisor) &&
282 git -C repo config core.repositoryformatversion 1 &&
283 git -C repo config extensions.partialclone "arbitrary string" &&
286 # Ensure that the promisor packfile still exists, and remove it
287 test -e repo/.git/objects/pack/pack-$HASH.pack &&
288 rm repo/.git/objects/pack/pack-$HASH.* &&
290 # Ensure that the single other pack contains the commit, but not the tree
291 ls repo/.git/objects/pack/pack-*.pack >packlist &&
292 test_line_count = 1 packlist &&
293 git verify-pack repo/.git/objects/pack/pack-*.pack -v >out &&
294 grep "$(git -C repo rev-parse HEAD)" out &&
295 ! grep "$TREE_HASH" out
298 test_expect_success 'gc stops traversal when a missing but promised object is reached' '
300 test_create_repo repo &&
301 test_commit -C repo my_commit &&
303 TREE_HASH=$(git -C repo rev-parse HEAD^{tree}) &&
304 HASH=$(promise_and_delete $TREE_HASH) &&
306 git -C repo config core.repositoryformatversion 1 &&
307 git -C repo config extensions.partialclone "arbitrary string" &&
310 # Ensure that the promisor packfile still exists, and remove it
311 test -e repo/.git/objects/pack/pack-$HASH.pack &&
312 rm repo/.git/objects/pack/pack-$HASH.* &&
314 # Ensure that the single other pack contains the commit, but not the tree
315 ls repo/.git/objects/pack/pack-*.pack >packlist &&
316 test_line_count = 1 packlist &&
317 git verify-pack repo/.git/objects/pack/pack-*.pack -v >out &&
318 grep "$(git -C repo rev-parse HEAD)" out &&
319 ! grep "$TREE_HASH" out
322 LIB_HTTPD_PORT=12345 # default port, 410, cannot be used as non-root
323 . "$TEST_DIRECTORY"/lib-httpd.sh
326 test_expect_success 'fetching of missing objects from an HTTP server' '
328 SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
329 test_create_repo "$SERVER" &&
330 test_commit -C "$SERVER" foo &&
331 git -C "$SERVER" repack -a -d --write-bitmap-index &&
333 git clone $HTTPD_URL/smart/server repo &&
334 HASH=$(git -C repo rev-parse foo) &&
335 rm -rf repo/.git/objects/* &&
337 git -C repo config core.repositoryformatversion 1 &&
338 git -C repo config extensions.partialclone "origin" &&
339 git -C repo cat-file -p "$HASH" &&
341 # Ensure that the .promisor file is written, and check that its
342 # associated packfile contains the object
343 ls repo/.git/objects/pack/pack-*.promisor >promisorlist &&
344 test_line_count = 1 promisorlist &&
345 IDX=$(cat promisorlist | sed "s/promisor$/idx/") &&
346 git verify-pack --verbose "$IDX" | grep "$HASH"