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