]>
Commit | Line | Data |
---|---|---|
498f1f61 JT |
1 | #!/bin/sh |
2 | ||
3 | test_description='partial clone' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
d3f17e17 JK |
7 | # missing promisor objects cause repacks which write bitmaps to fail |
8 | GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 | |
f30e4d85 GC |
9 | # When enabled, some commands will write commit-graphs. This causes fsck |
10 | # to fail when delete_object() is called because fsck will attempt to | |
11 | # verify the out-of-sync commit graph. | |
12 | GIT_TEST_COMMIT_GRAPH=0 | |
d3f17e17 | 13 | |
498f1f61 JT |
14 | delete_object () { |
15 | rm $1/.git/objects/$(echo $2 | sed -e 's|^..|&/|') | |
16 | } | |
17 | ||
18 | pack_as_from_promisor () { | |
19 | HASH=$(git -C repo pack-objects .git/objects/pack/pack) && | |
0c16cd49 JT |
20 | >repo/.git/objects/pack/pack-$HASH.promisor && |
21 | echo $HASH | |
498f1f61 JT |
22 | } |
23 | ||
43f25158 JT |
24 | promise_and_delete () { |
25 | HASH=$(git -C repo rev-parse "$1") && | |
26 | git -C repo tag -a -m message my_annotated_tag "$HASH" && | |
27 | git -C repo rev-parse my_annotated_tag | pack_as_from_promisor && | |
0c16cd49 JT |
28 | # tag -d prints a message to stdout, so redirect it |
29 | git -C repo tag -d my_annotated_tag >/dev/null && | |
43f25158 JT |
30 | delete_object repo "$HASH" |
31 | } | |
32 | ||
cac1137d JT |
33 | test_expect_success 'extensions.partialclone without filter' ' |
34 | test_create_repo server && | |
35 | git clone --filter="blob:none" "file://$(pwd)/server" client && | |
fa3d1b63 | 36 | git -C client config --unset remote.origin.partialclonefilter && |
cac1137d JT |
37 | git -C client fetch origin |
38 | ' | |
39 | ||
01bbbbd9 XL |
40 | test_expect_success 'convert shallow clone to partial clone' ' |
41 | rm -fr server client && | |
42 | test_create_repo server && | |
43 | test_commit -C server my_commit 1 && | |
44 | test_commit -C server my_commit2 1 && | |
45 | git clone --depth=1 "file://$(pwd)/server" client && | |
46 | git -C client fetch --unshallow --filter="blob:none" && | |
47 | test_cmp_config -C client true remote.origin.promisor && | |
48 | test_cmp_config -C client blob:none remote.origin.partialclonefilter && | |
49 | test_cmp_config -C client 1 core.repositoryformatversion | |
50 | ' | |
51 | ||
6c2adf80 | 52 | test_expect_success SHA1 'convert to partial clone with noop extension' ' |
14c7fa26 XL |
53 | rm -fr server client && |
54 | test_create_repo server && | |
55 | test_commit -C server my_commit 1 && | |
56 | test_commit -C server my_commit2 1 && | |
57 | git clone --depth=1 "file://$(pwd)/server" client && | |
58 | test_cmp_config -C client 0 core.repositoryformatversion && | |
11664196 | 59 | git -C client config extensions.noop true && |
62f2eca6 | 60 | git -C client fetch --unshallow --filter="blob:none" |
11664196 JN |
61 | ' |
62 | ||
6c2adf80 | 63 | test_expect_success SHA1 'converting to partial clone fails with unrecognized extension' ' |
11664196 JN |
64 | rm -fr server client && |
65 | test_create_repo server && | |
66 | test_commit -C server my_commit 1 && | |
67 | test_commit -C server my_commit2 1 && | |
68 | git clone --depth=1 "file://$(pwd)/server" client && | |
69 | test_cmp_config -C client 0 core.repositoryformatversion && | |
70 | git -C client config extensions.nonsense true && | |
14c7fa26 XL |
71 | test_must_fail git -C client fetch --unshallow --filter="blob:none" |
72 | ' | |
73 | ||
498f1f61 | 74 | test_expect_success 'missing reflog object, but promised by a commit, passes fsck' ' |
cac1137d | 75 | rm -rf repo && |
498f1f61 JT |
76 | test_create_repo repo && |
77 | test_commit -C repo my_commit && | |
78 | ||
79 | A=$(git -C repo commit-tree -m a HEAD^{tree}) && | |
80 | C=$(git -C repo commit-tree -m c -p $A HEAD^{tree}) && | |
81 | ||
82 | # Reference $A only from reflog, and delete it | |
83 | git -C repo branch my_branch "$A" && | |
84 | git -C repo branch -f my_branch my_commit && | |
85 | delete_object repo "$A" && | |
86 | ||
87 | # State that we got $C, which refers to $A, from promisor | |
88 | printf "$C\n" | pack_as_from_promisor && | |
89 | ||
90 | # Normally, it fails | |
91 | test_must_fail git -C repo fsck && | |
92 | ||
93 | # But with the extension, it succeeds | |
94 | git -C repo config core.repositoryformatversion 1 && | |
95 | git -C repo config extensions.partialclone "arbitrary string" && | |
96 | git -C repo fsck | |
97 | ' | |
98 | ||
99 | test_expect_success 'missing reflog object, but promised by a tag, 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 | git -C repo tag -a -m d my_tag_name $A && | |
106 | T=$(git -C repo rev-parse my_tag_name) && | |
107 | git -C repo tag -d my_tag_name && | |
108 | ||
109 | # Reference $A only from reflog, and delete it | |
110 | git -C repo branch my_branch "$A" && | |
111 | git -C repo branch -f my_branch my_commit && | |
112 | delete_object repo "$A" && | |
113 | ||
114 | # State that we got $T, which refers to $A, from promisor | |
115 | printf "$T\n" | pack_as_from_promisor && | |
116 | ||
117 | git -C repo config core.repositoryformatversion 1 && | |
118 | git -C repo config extensions.partialclone "arbitrary string" && | |
119 | git -C repo fsck | |
120 | ' | |
121 | ||
122 | test_expect_success 'missing reflog object alone fails fsck, even with extension set' ' | |
123 | rm -rf repo && | |
124 | test_create_repo repo && | |
125 | test_commit -C repo my_commit && | |
126 | ||
127 | A=$(git -C repo commit-tree -m a HEAD^{tree}) && | |
128 | B=$(git -C repo commit-tree -m b HEAD^{tree}) && | |
129 | ||
130 | # Reference $A only from reflog, and delete it | |
131 | git -C repo branch my_branch "$A" && | |
132 | git -C repo branch -f my_branch my_commit && | |
133 | delete_object repo "$A" && | |
134 | ||
135 | git -C repo config core.repositoryformatversion 1 && | |
136 | git -C repo config extensions.partialclone "arbitrary string" && | |
137 | test_must_fail git -C repo fsck | |
138 | ' | |
139 | ||
43f25158 JT |
140 | test_expect_success 'missing ref object, but promised, passes fsck' ' |
141 | rm -rf repo && | |
142 | test_create_repo repo && | |
143 | test_commit -C repo my_commit && | |
144 | ||
145 | A=$(git -C repo commit-tree -m a HEAD^{tree}) && | |
146 | ||
147 | # Reference $A only from ref | |
148 | git -C repo branch my_branch "$A" && | |
149 | promise_and_delete "$A" && | |
150 | ||
151 | git -C repo config core.repositoryformatversion 1 && | |
152 | git -C repo config extensions.partialclone "arbitrary string" && | |
153 | git -C repo fsck | |
154 | ' | |
155 | ||
caba7fc3 JT |
156 | test_expect_success 'missing object, but promised, passes fsck' ' |
157 | rm -rf repo && | |
158 | test_create_repo repo && | |
159 | test_commit -C repo 1 && | |
160 | test_commit -C repo 2 && | |
161 | test_commit -C repo 3 && | |
162 | git -C repo tag -a annotated_tag -m "annotated tag" && | |
163 | ||
164 | C=$(git -C repo rev-parse 1) && | |
165 | T=$(git -C repo rev-parse 2^{tree}) && | |
166 | B=$(git hash-object repo/3.t) && | |
167 | AT=$(git -C repo rev-parse annotated_tag) && | |
168 | ||
169 | promise_and_delete "$C" && | |
170 | promise_and_delete "$T" && | |
171 | promise_and_delete "$B" && | |
172 | promise_and_delete "$AT" && | |
173 | ||
174 | git -C repo config core.repositoryformatversion 1 && | |
175 | git -C repo config extensions.partialclone "arbitrary string" && | |
176 | git -C repo fsck | |
177 | ' | |
178 | ||
096c9b8b JT |
179 | test_expect_success 'missing CLI object, but promised, passes fsck' ' |
180 | rm -rf repo && | |
181 | test_create_repo repo && | |
182 | test_commit -C repo my_commit && | |
183 | ||
184 | A=$(git -C repo commit-tree -m a HEAD^{tree}) && | |
185 | promise_and_delete "$A" && | |
186 | ||
187 | git -C repo config core.repositoryformatversion 1 && | |
188 | git -C repo config extensions.partialclone "arbitrary string" && | |
189 | git -C repo fsck "$A" | |
190 | ' | |
191 | ||
8b4c0103 | 192 | test_expect_success 'fetching of missing objects' ' |
db3c293e | 193 | rm -rf repo err && |
8b4c0103 JT |
194 | test_create_repo server && |
195 | test_commit -C server foo && | |
196 | git -C server repack -a -d --write-bitmap-index && | |
197 | ||
198 | git clone "file://$(pwd)/server" repo && | |
199 | HASH=$(git -C repo rev-parse foo) && | |
200 | rm -rf repo/.git/objects/* && | |
201 | ||
202 | git -C repo config core.repositoryformatversion 1 && | |
203 | git -C repo config extensions.partialclone "origin" && | |
db3c293e JT |
204 | git -C repo cat-file -p "$HASH" 2>err && |
205 | ||
206 | # Ensure that no spurious FETCH_HEAD messages are written | |
207 | ! grep FETCH_HEAD err && | |
8b4c0103 JT |
208 | |
209 | # Ensure that the .promisor file is written, and check that its | |
210 | # associated packfile contains the object | |
211 | ls repo/.git/objects/pack/pack-*.promisor >promisorlist && | |
212 | test_line_count = 1 promisorlist && | |
c59c7c87 CC |
213 | IDX=$(sed "s/promisor$/idx/" promisorlist) && |
214 | git verify-pack --verbose "$IDX" >out && | |
215 | grep "$HASH" out | |
8b4c0103 JT |
216 | ' |
217 | ||
301f1e3a JT |
218 | test_expect_success 'fetching of a promised object that promisor remote no longer has' ' |
219 | rm -f err && | |
220 | test_create_repo unreliable-server && | |
221 | git -C unreliable-server config uploadpack.allowanysha1inwant 1 && | |
222 | git -C unreliable-server config uploadpack.allowfilter 1 && | |
223 | test_commit -C unreliable-server foo && | |
224 | ||
225 | git clone --filter=blob:none --no-checkout "file://$(pwd)/unreliable-server" unreliable-client && | |
226 | ||
227 | rm -rf unreliable-server/.git/objects/* && | |
228 | test_must_fail git -C unreliable-client checkout HEAD 2>err && | |
229 | grep "could not fetch.*from promisor remote" err | |
230 | ' | |
231 | ||
e6830201 JT |
232 | test_expect_success 'fetching of missing objects works with ref-in-want enabled' ' |
233 | # ref-in-want requires protocol version 2 | |
234 | git -C server config protocol.version 2 && | |
235 | git -C server config uploadpack.allowrefinwant 1 && | |
236 | git -C repo config protocol.version 2 && | |
237 | ||
238 | rm -rf repo/.git/objects/* && | |
239 | rm -f trace && | |
240 | GIT_TRACE_PACKET="$(pwd)/trace" git -C repo cat-file -p "$HASH" && | |
7ca3c0ac | 241 | grep "fetch< fetch=.*ref-in-want" trace |
e6830201 JT |
242 | ' |
243 | ||
9a4c5078 CC |
244 | test_expect_success 'fetching of missing objects from another promisor remote' ' |
245 | git clone "file://$(pwd)/server" server2 && | |
246 | test_commit -C server2 bar && | |
247 | git -C server2 repack -a -d --write-bitmap-index && | |
248 | HASH2=$(git -C server2 rev-parse bar) && | |
249 | ||
250 | git -C repo remote add server2 "file://$(pwd)/server2" && | |
251 | git -C repo config remote.server2.promisor true && | |
252 | git -C repo cat-file -p "$HASH2" && | |
253 | ||
254 | git -C repo fetch server2 && | |
255 | rm -rf repo/.git/objects/* && | |
256 | git -C repo cat-file -p "$HASH2" && | |
257 | ||
258 | # Ensure that the .promisor file is written, and check that its | |
259 | # associated packfile contains the object | |
260 | ls repo/.git/objects/pack/pack-*.promisor >promisorlist && | |
261 | test_line_count = 1 promisorlist && | |
262 | IDX=$(sed "s/promisor$/idx/" promisorlist) && | |
263 | git verify-pack --verbose "$IDX" >out && | |
264 | grep "$HASH2" out | |
265 | ' | |
266 | ||
267 | test_expect_success 'fetching of missing objects configures a promisor remote' ' | |
268 | git clone "file://$(pwd)/server" server3 && | |
269 | test_commit -C server3 baz && | |
270 | git -C server3 repack -a -d --write-bitmap-index && | |
271 | HASH3=$(git -C server3 rev-parse baz) && | |
272 | git -C server3 config uploadpack.allowfilter 1 && | |
273 | ||
274 | rm repo/.git/objects/pack/pack-*.promisor && | |
275 | ||
276 | git -C repo remote add server3 "file://$(pwd)/server3" && | |
277 | git -C repo fetch --filter="blob:none" server3 $HASH3 && | |
278 | ||
279 | test_cmp_config -C repo true remote.server3.promisor && | |
280 | ||
281 | # Ensure that the .promisor file is written, and check that its | |
282 | # associated packfile contains the object | |
283 | ls repo/.git/objects/pack/pack-*.promisor >promisorlist && | |
284 | test_line_count = 1 promisorlist && | |
285 | IDX=$(sed "s/promisor$/idx/" promisorlist) && | |
286 | git verify-pack --verbose "$IDX" >out && | |
287 | grep "$HASH3" out | |
288 | ' | |
289 | ||
4c7f9567 | 290 | test_expect_success 'fetching of missing blobs works' ' |
9a4c5078 CC |
291 | rm -rf server server2 repo && |
292 | rm -rf server server3 repo && | |
4c7f9567 JT |
293 | test_create_repo server && |
294 | test_commit -C server foo && | |
295 | git -C server repack -a -d --write-bitmap-index && | |
296 | ||
297 | git clone "file://$(pwd)/server" repo && | |
298 | git hash-object repo/foo.t >blobhash && | |
299 | rm -rf repo/.git/objects/* && | |
300 | ||
301 | git -C server config uploadpack.allowanysha1inwant 1 && | |
302 | git -C server config uploadpack.allowfilter 1 && | |
303 | git -C repo config core.repositoryformatversion 1 && | |
304 | git -C repo config extensions.partialclone "origin" && | |
305 | ||
306 | git -C repo cat-file -p $(cat blobhash) | |
307 | ' | |
308 | ||
309 | test_expect_success 'fetching of missing trees does not fetch blobs' ' | |
310 | rm -rf server repo && | |
311 | test_create_repo server && | |
312 | test_commit -C server foo && | |
313 | git -C server repack -a -d --write-bitmap-index && | |
314 | ||
315 | git clone "file://$(pwd)/server" repo && | |
316 | git -C repo rev-parse foo^{tree} >treehash && | |
317 | git hash-object repo/foo.t >blobhash && | |
318 | rm -rf repo/.git/objects/* && | |
319 | ||
320 | git -C server config uploadpack.allowanysha1inwant 1 && | |
321 | git -C server config uploadpack.allowfilter 1 && | |
322 | git -C repo config core.repositoryformatversion 1 && | |
323 | git -C repo config extensions.partialclone "origin" && | |
324 | git -C repo cat-file -p $(cat treehash) && | |
325 | ||
326 | # Ensure that the tree, but not the blob, is fetched | |
327 | git -C repo rev-list --objects --missing=print $(cat treehash) >objects && | |
328 | grep "^$(cat treehash)" objects && | |
329 | grep "^[?]$(cat blobhash)" objects | |
330 | ' | |
331 | ||
df11e196 JT |
332 | test_expect_success 'rev-list stops traversal at missing and promised commit' ' |
333 | rm -rf repo && | |
334 | test_create_repo repo && | |
335 | test_commit -C repo foo && | |
336 | test_commit -C repo bar && | |
337 | ||
338 | FOO=$(git -C repo rev-parse foo) && | |
339 | promise_and_delete "$FOO" && | |
340 | ||
341 | git -C repo config core.repositoryformatversion 1 && | |
342 | git -C repo config extensions.partialclone "arbitrary string" && | |
f30e4d85 | 343 | git -C repo rev-list --exclude-promisor-objects --objects bar >out && |
df11e196 JT |
344 | grep $(git -C repo rev-parse bar) out && |
345 | ! grep $FOO out | |
346 | ' | |
347 | ||
7c0fe330 MD |
348 | test_expect_success 'missing tree objects with --missing=allow-promisor and --exclude-promisor-objects' ' |
349 | rm -rf repo && | |
350 | test_create_repo repo && | |
351 | test_commit -C repo foo && | |
352 | test_commit -C repo bar && | |
353 | test_commit -C repo baz && | |
354 | ||
355 | promise_and_delete $(git -C repo rev-parse bar^{tree}) && | |
356 | promise_and_delete $(git -C repo rev-parse foo^{tree}) && | |
357 | ||
358 | git -C repo config core.repositoryformatversion 1 && | |
359 | git -C repo config extensions.partialclone "arbitrary string" && | |
360 | ||
361 | git -C repo rev-list --missing=allow-promisor --objects HEAD >objs 2>rev_list_err && | |
362 | test_must_be_empty rev_list_err && | |
363 | # 3 commits, 3 blobs, and 1 tree | |
364 | test_line_count = 7 objs && | |
365 | ||
366 | # Do the same for --exclude-promisor-objects, but with all trees gone. | |
367 | promise_and_delete $(git -C repo rev-parse baz^{tree}) && | |
368 | git -C repo rev-list --exclude-promisor-objects --objects HEAD >objs 2>rev_list_err && | |
369 | test_must_be_empty rev_list_err && | |
370 | # 3 commits, no blobs or trees | |
371 | test_line_count = 3 objs | |
372 | ' | |
373 | ||
374 | test_expect_success 'missing non-root tree object and rev-list' ' | |
375 | rm -rf repo && | |
376 | test_create_repo repo && | |
377 | mkdir repo/dir && | |
378 | echo foo >repo/dir/foo && | |
379 | git -C repo add dir/foo && | |
380 | git -C repo commit -m "commit dir/foo" && | |
381 | ||
382 | promise_and_delete $(git -C repo rev-parse HEAD:dir) && | |
383 | ||
384 | git -C repo config core.repositoryformatversion 1 && | |
385 | git -C repo config extensions.partialclone "arbitrary string" && | |
386 | ||
387 | git -C repo rev-list --missing=allow-any --objects HEAD >objs 2>rev_list_err && | |
388 | test_must_be_empty rev_list_err && | |
389 | # 1 commit and 1 tree | |
390 | test_line_count = 2 objs | |
391 | ' | |
392 | ||
df11e196 JT |
393 | test_expect_success 'rev-list stops traversal at missing and promised tree' ' |
394 | rm -rf repo && | |
395 | test_create_repo repo && | |
396 | test_commit -C repo foo && | |
397 | mkdir repo/a_dir && | |
398 | echo something >repo/a_dir/something && | |
399 | git -C repo add a_dir/something && | |
400 | git -C repo commit -m bar && | |
401 | ||
402 | # foo^{tree} (tree referenced from commit) | |
403 | TREE=$(git -C repo rev-parse foo^{tree}) && | |
404 | ||
405 | # a tree referenced by HEAD^{tree} (tree referenced from tree) | |
406 | TREE2=$(git -C repo ls-tree HEAD^{tree} | grep " tree " | head -1 | cut -b13-52) && | |
407 | ||
408 | promise_and_delete "$TREE" && | |
409 | promise_and_delete "$TREE2" && | |
410 | ||
411 | git -C repo config core.repositoryformatversion 1 && | |
412 | git -C repo config extensions.partialclone "arbitrary string" && | |
413 | git -C repo rev-list --exclude-promisor-objects --objects HEAD >out && | |
414 | grep $(git -C repo rev-parse foo) out && | |
415 | ! grep $TREE out && | |
416 | grep $(git -C repo rev-parse HEAD) out && | |
417 | ! grep $TREE2 out | |
418 | ' | |
419 | ||
420 | test_expect_success 'rev-list stops traversal at missing and promised blob' ' | |
421 | rm -rf repo && | |
422 | test_create_repo repo && | |
423 | echo something >repo/something && | |
424 | git -C repo add something && | |
425 | git -C repo commit -m foo && | |
426 | ||
427 | BLOB=$(git -C repo hash-object -w something) && | |
428 | promise_and_delete "$BLOB" && | |
429 | ||
430 | git -C repo config core.repositoryformatversion 1 && | |
431 | git -C repo config extensions.partialclone "arbitrary string" && | |
432 | git -C repo rev-list --exclude-promisor-objects --objects HEAD >out && | |
433 | grep $(git -C repo rev-parse HEAD) out && | |
434 | ! grep $BLOB out | |
435 | ' | |
436 | ||
437 | test_expect_success 'rev-list stops traversal at promisor commit, tree, and blob' ' | |
438 | rm -rf repo && | |
439 | test_create_repo repo && | |
440 | test_commit -C repo foo && | |
441 | test_commit -C repo bar && | |
442 | test_commit -C repo baz && | |
443 | ||
444 | COMMIT=$(git -C repo rev-parse foo) && | |
445 | TREE=$(git -C repo rev-parse bar^{tree}) && | |
446 | BLOB=$(git hash-object repo/baz.t) && | |
447 | printf "%s\n%s\n%s\n" $COMMIT $TREE $BLOB | pack_as_from_promisor && | |
448 | ||
449 | git -C repo config core.repositoryformatversion 1 && | |
450 | git -C repo config extensions.partialclone "arbitrary string" && | |
451 | git -C repo rev-list --exclude-promisor-objects --objects HEAD >out && | |
452 | ! grep $COMMIT out && | |
453 | ! grep $TREE out && | |
454 | ! grep $BLOB out && | |
455 | grep $(git -C repo rev-parse bar) out # sanity check that some walking was done | |
456 | ' | |
457 | ||
4cf67869 | 458 | test_expect_success 'rev-list dies for missing objects on cmd line' ' |
df11e196 JT |
459 | rm -rf repo && |
460 | test_create_repo repo && | |
461 | test_commit -C repo foo && | |
462 | test_commit -C repo bar && | |
463 | test_commit -C repo baz && | |
464 | ||
465 | COMMIT=$(git -C repo rev-parse foo) && | |
466 | TREE=$(git -C repo rev-parse bar^{tree}) && | |
467 | BLOB=$(git hash-object repo/baz.t) && | |
468 | ||
469 | promise_and_delete $COMMIT && | |
470 | promise_and_delete $TREE && | |
471 | promise_and_delete $BLOB && | |
472 | ||
473 | git -C repo config core.repositoryformatversion 1 && | |
474 | git -C repo config extensions.partialclone "arbitrary string" && | |
4cf67869 MD |
475 | |
476 | for OBJ in "$COMMIT" "$TREE" "$BLOB"; do | |
477 | test_must_fail git -C repo rev-list --objects \ | |
478 | --exclude-promisor-objects "$OBJ" && | |
479 | test_must_fail git -C repo rev-list --objects-edge-aggressive \ | |
480 | --exclude-promisor-objects "$OBJ" && | |
481 | ||
482 | # Do not die or crash when --ignore-missing is passed. | |
483 | git -C repo rev-list --ignore-missing --objects \ | |
484 | --exclude-promisor-objects "$OBJ" && | |
485 | git -C repo rev-list --ignore-missing --objects-edge-aggressive \ | |
db5875aa | 486 | --exclude-promisor-objects "$OBJ" || return 1 |
4cf67869 | 487 | done |
df11e196 JT |
488 | ' |
489 | ||
65904b8b ES |
490 | test_expect_success 'single promisor remote can be re-initialized gracefully' ' |
491 | # ensure one promisor is in the promisors list | |
492 | rm -rf repo && | |
493 | test_create_repo repo && | |
494 | test_create_repo other && | |
495 | git -C repo remote add foo "file://$(pwd)/other" && | |
496 | git -C repo config remote.foo.promisor true && | |
497 | git -C repo config extensions.partialclone foo && | |
498 | ||
499 | # reinitialize the promisors list | |
500 | git -C repo fetch --filter=blob:none foo | |
501 | ' | |
502 | ||
5d19e813 | 503 | test_expect_success 'gc repacks promisor objects separately from non-promisor objects' ' |
0c16cd49 JT |
504 | rm -rf repo && |
505 | test_create_repo repo && | |
5d19e813 JT |
506 | test_commit -C repo one && |
507 | test_commit -C repo two && | |
0c16cd49 | 508 | |
5d19e813 JT |
509 | TREE_ONE=$(git -C repo rev-parse one^{tree}) && |
510 | printf "$TREE_ONE\n" | pack_as_from_promisor && | |
511 | TREE_TWO=$(git -C repo rev-parse two^{tree}) && | |
512 | printf "$TREE_TWO\n" | pack_as_from_promisor && | |
0c16cd49 JT |
513 | |
514 | git -C repo config core.repositoryformatversion 1 && | |
515 | git -C repo config extensions.partialclone "arbitrary string" && | |
516 | git -C repo gc && | |
517 | ||
5d19e813 JT |
518 | # Ensure that exactly one promisor packfile exists, and that it |
519 | # contains the trees but not the commits | |
520 | ls repo/.git/objects/pack/pack-*.promisor >promisorlist && | |
521 | test_line_count = 1 promisorlist && | |
522 | PROMISOR_PACKFILE=$(sed "s/.promisor/.pack/" <promisorlist) && | |
523 | git verify-pack $PROMISOR_PACKFILE -v >out && | |
524 | grep "$TREE_ONE" out && | |
525 | grep "$TREE_TWO" out && | |
526 | ! grep "$(git -C repo rev-parse one)" out && | |
527 | ! grep "$(git -C repo rev-parse two)" out && | |
528 | ||
529 | # Remove the promisor packfile and associated files | |
530 | rm $(sed "s/.promisor//" <promisorlist).* && | |
531 | ||
532 | # Ensure that the single other pack contains the commits, but not the | |
533 | # trees | |
0c16cd49 JT |
534 | ls repo/.git/objects/pack/pack-*.pack >packlist && |
535 | test_line_count = 1 packlist && | |
536 | git verify-pack repo/.git/objects/pack/pack-*.pack -v >out && | |
5d19e813 JT |
537 | grep "$(git -C repo rev-parse one)" out && |
538 | grep "$(git -C repo rev-parse two)" out && | |
539 | ! grep "$TREE_ONE" out && | |
540 | ! grep "$TREE_TWO" out | |
541 | ' | |
542 | ||
543 | test_expect_success 'gc does not repack promisor objects if there are none' ' | |
544 | rm -rf repo && | |
545 | test_create_repo repo && | |
546 | test_commit -C repo one && | |
547 | ||
548 | git -C repo config core.repositoryformatversion 1 && | |
549 | git -C repo config extensions.partialclone "arbitrary string" && | |
550 | git -C repo gc && | |
551 | ||
552 | # Ensure that only one pack exists | |
553 | ls repo/.git/objects/pack/pack-*.pack >packlist && | |
554 | test_line_count = 1 packlist | |
555 | ' | |
556 | ||
557 | repack_and_check () { | |
558 | rm -rf repo2 && | |
559 | cp -r repo repo2 && | |
3ba3d062 TB |
560 | if test x"$1" = "x--must-fail" |
561 | then | |
562 | shift | |
563 | test_must_fail git -C repo2 repack $1 -d | |
564 | else | |
565 | git -C repo2 repack $1 -d | |
566 | fi && | |
5d19e813 JT |
567 | git -C repo2 fsck && |
568 | ||
569 | git -C repo2 cat-file -e $2 && | |
570 | git -C repo2 cat-file -e $3 | |
571 | } | |
572 | ||
573 | test_expect_success 'repack -d does not irreversibly delete promisor objects' ' | |
574 | rm -rf repo && | |
575 | test_create_repo repo && | |
576 | git -C repo config core.repositoryformatversion 1 && | |
577 | git -C repo config extensions.partialclone "arbitrary string" && | |
578 | ||
579 | git -C repo commit --allow-empty -m one && | |
580 | git -C repo commit --allow-empty -m two && | |
581 | git -C repo commit --allow-empty -m three && | |
582 | git -C repo commit --allow-empty -m four && | |
583 | ONE=$(git -C repo rev-parse HEAD^^^) && | |
584 | TWO=$(git -C repo rev-parse HEAD^^) && | |
585 | THREE=$(git -C repo rev-parse HEAD^) && | |
586 | ||
587 | printf "$TWO\n" | pack_as_from_promisor && | |
588 | printf "$THREE\n" | pack_as_from_promisor && | |
589 | delete_object repo "$ONE" && | |
590 | ||
3ba3d062 | 591 | repack_and_check --must-fail -ab "$TWO" "$THREE" && |
5d19e813 JT |
592 | repack_and_check -a "$TWO" "$THREE" && |
593 | repack_and_check -A "$TWO" "$THREE" && | |
594 | repack_and_check -l "$TWO" "$THREE" | |
0c16cd49 JT |
595 | ' |
596 | ||
597 | test_expect_success 'gc stops traversal when a missing but promised object is reached' ' | |
598 | rm -rf repo && | |
599 | test_create_repo repo && | |
600 | test_commit -C repo my_commit && | |
601 | ||
602 | TREE_HASH=$(git -C repo rev-parse HEAD^{tree}) && | |
603 | HASH=$(promise_and_delete $TREE_HASH) && | |
604 | ||
605 | git -C repo config core.repositoryformatversion 1 && | |
606 | git -C repo config extensions.partialclone "arbitrary string" && | |
607 | git -C repo gc && | |
608 | ||
609 | # Ensure that the promisor packfile still exists, and remove it | |
610 | test -e repo/.git/objects/pack/pack-$HASH.pack && | |
611 | rm repo/.git/objects/pack/pack-$HASH.* && | |
612 | ||
613 | # Ensure that the single other pack contains the commit, but not the tree | |
614 | ls repo/.git/objects/pack/pack-*.pack >packlist && | |
615 | test_line_count = 1 packlist && | |
616 | git verify-pack repo/.git/objects/pack/pack-*.pack -v >out && | |
617 | grep "$(git -C repo rev-parse HEAD)" out && | |
618 | ! grep "$TREE_HASH" out | |
619 | ' | |
620 | ||
f981ec18 JT |
621 | test_expect_success 'do not fetch when checking existence of tree we construct ourselves' ' |
622 | rm -rf repo && | |
623 | test_create_repo repo && | |
624 | test_commit -C repo base && | |
625 | test_commit -C repo side1 && | |
626 | git -C repo checkout base && | |
627 | test_commit -C repo side2 && | |
628 | ||
629 | git -C repo config core.repositoryformatversion 1 && | |
630 | git -C repo config extensions.partialclone "arbitrary string" && | |
631 | ||
632 | git -C repo cherry-pick side1 | |
633 | ' | |
634 | ||
ab3892e4 AC |
635 | test_expect_success 'exact rename does not need to fetch the blob lazily' ' |
636 | rm -rf repo partial.git && | |
637 | test_create_repo repo && | |
638 | content="some dummy content" && | |
639 | test_commit -C repo create-a-file file.txt "$content" && | |
640 | git -C repo mv file.txt new-file.txt && | |
641 | git -C repo commit -m rename-the-file && | |
642 | FILE_HASH=$(git -C repo rev-parse HEAD:new-file.txt) && | |
643 | test_config -C repo uploadpack.allowfilter 1 && | |
644 | test_config -C repo uploadpack.allowanysha1inwant 1 && | |
645 | ||
646 | git clone --filter=blob:none --bare "file://$(pwd)/repo" partial.git && | |
647 | git -C partial.git rev-list --objects --missing=print HEAD >out && | |
648 | grep "[?]$FILE_HASH" out && | |
649 | git -C partial.git log --follow -- new-file.txt && | |
650 | git -C partial.git rev-list --objects --missing=print HEAD >out && | |
651 | grep "[?]$FILE_HASH" out | |
652 | ' | |
653 | ||
ef830cc4 JT |
654 | test_expect_success 'lazy-fetch when accessing object not in the_repository' ' |
655 | rm -rf full partial.git && | |
656 | test_create_repo full && | |
657 | test_commit -C full create-a-file file.txt && | |
658 | ||
659 | test_config -C full uploadpack.allowfilter 1 && | |
660 | test_config -C full uploadpack.allowanysha1inwant 1 && | |
661 | git clone --filter=blob:none --bare "file://$(pwd)/full" partial.git && | |
662 | FILE_HASH=$(git -C full rev-parse HEAD:file.txt) && | |
663 | ||
664 | # Sanity check that the file is missing | |
665 | git -C partial.git rev-list --objects --missing=print HEAD >out && | |
666 | grep "[?]$FILE_HASH" out && | |
667 | ||
668 | git -C full cat-file -s "$FILE_HASH" >expect && | |
669 | test-tool partial-clone object-info partial.git "$FILE_HASH" >actual && | |
670 | test_cmp expect actual && | |
671 | ||
672 | # Sanity check that the file is now present | |
673 | git -C partial.git rev-list --objects --missing=print HEAD >out && | |
674 | ! grep "[?]$FILE_HASH" out | |
675 | ' | |
676 | ||
8b4c0103 JT |
677 | . "$TEST_DIRECTORY"/lib-httpd.sh |
678 | start_httpd | |
679 | ||
680 | test_expect_success 'fetching of missing objects from an HTTP server' ' | |
681 | rm -rf repo && | |
682 | SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" && | |
683 | test_create_repo "$SERVER" && | |
684 | test_commit -C "$SERVER" foo && | |
685 | git -C "$SERVER" repack -a -d --write-bitmap-index && | |
686 | ||
687 | git clone $HTTPD_URL/smart/server repo && | |
688 | HASH=$(git -C repo rev-parse foo) && | |
689 | rm -rf repo/.git/objects/* && | |
690 | ||
691 | git -C repo config core.repositoryformatversion 1 && | |
692 | git -C repo config extensions.partialclone "origin" && | |
693 | git -C repo cat-file -p "$HASH" && | |
694 | ||
695 | # Ensure that the .promisor file is written, and check that its | |
696 | # associated packfile contains the object | |
697 | ls repo/.git/objects/pack/pack-*.promisor >promisorlist && | |
698 | test_line_count = 1 promisorlist && | |
c59c7c87 CC |
699 | IDX=$(sed "s/promisor$/idx/" promisorlist) && |
700 | git verify-pack --verbose "$IDX" >out && | |
701 | grep "$HASH" out | |
8b4c0103 JT |
702 | ' |
703 | ||
decfe05b SG |
704 | # DO NOT add non-httpd-specific tests here, because the last part of this |
705 | # test script is only executed when httpd is available and enabled. | |
706 | ||
498f1f61 | 707 | test_done |