Git fork
1#!/bin/sh
2
3test_description='git repack works correctly'
4
5. ./test-lib.sh
6. "${TEST_DIRECTORY}/lib-bitmap.sh"
7. "${TEST_DIRECTORY}/lib-midx.sh"
8. "${TEST_DIRECTORY}/lib-terminal.sh"
9
10GIT_TEST_MULTI_PACK_INDEX=0
11GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL=0
12
13commit_and_pack () {
14 test_commit "$@" 1>&2 &&
15 incrpackid=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) &&
16 # Remove any loose object(s) created by test_commit, since they have
17 # already been packed. Leaving these around can create subtly different
18 # packs with `pack-objects`'s `--unpacked` option.
19 git prune-packed 1>&2 &&
20 echo pack-${incrpackid}.pack
21}
22
23test_no_missing_in_packs () {
24 myidx=$(ls -1 .git/objects/pack/*.idx) &&
25 test_path_is_file "$myidx" &&
26 git verify-pack -v alt_objects/pack/*.idx >orig.raw &&
27 sed -n -e "s/^\($OID_REGEX\).*/\1/p" orig.raw | sort >orig &&
28 git verify-pack -v $myidx >dest.raw &&
29 cut -d" " -f1 dest.raw | sort >dest &&
30 comm -23 orig dest >missing &&
31 test_must_be_empty missing
32}
33
34# we expect $packid and $oid to be defined
35test_has_duplicate_object () {
36 want_duplicate_object="$1"
37 found_duplicate_object=false
38 for p in .git/objects/pack/*.idx
39 do
40 idx=$(basename $p)
41 test "pack-$packid.idx" = "$idx" && continue
42 git verify-pack -v $p >packlist || return $?
43 if grep "^$oid" packlist
44 then
45 found_duplicate_object=true
46 echo "DUPLICATE OBJECT FOUND"
47 break
48 fi
49 done &&
50 test "$want_duplicate_object" = "$found_duplicate_object"
51}
52
53test_expect_success 'objects in packs marked .keep are not repacked' '
54 echo content1 >file1 &&
55 echo content2 >file2 &&
56 git add . &&
57 test_tick &&
58 git commit -m initial_commit &&
59 # Create two packs
60 # The first pack will contain all of the objects except one
61 git rev-list --objects --all >objs &&
62 grep -v file2 objs | git pack-objects pack &&
63 # The second pack will contain the excluded object
64 packid=$(grep file2 objs | git pack-objects pack) &&
65 >pack-$packid.keep &&
66 git verify-pack -v pack-$packid.idx >packlist &&
67 oid=$(head -n 1 packlist | sed -e "s/^\($OID_REGEX\).*/\1/") &&
68 mv pack-* .git/objects/pack/ &&
69 git repack -A -d -l &&
70 git prune-packed &&
71 test_has_duplicate_object false
72'
73
74test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' '
75 # build on $oid, $packid, and .keep state from previous
76 git repack -Adbl &&
77 test_has_duplicate_object true
78'
79
80test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
81 # build on $oid, $packid, and .keep state from previous
82 git -c repack.writebitmaps=true repack -Adl &&
83 test_has_duplicate_object true
84'
85
86test_expect_success 'loose objects in alternate ODB are not repacked' '
87 mkdir alt_objects &&
88 echo $(pwd)/alt_objects >.git/objects/info/alternates &&
89 echo content3 >file3 &&
90 oid=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
91 git add file3 &&
92 test_tick &&
93 git commit -m commit_file3 &&
94 git repack -a -d -l &&
95 git prune-packed &&
96 test_has_duplicate_object false
97'
98
99test_expect_success SYMLINKS '--local keeps packs when alternate is objectdir ' '
100 test_when_finished "rm -rf repo" &&
101 git init repo &&
102 test_commit -C repo A &&
103 (
104 cd repo &&
105 git repack -a &&
106 ls .git/objects/pack/*.pack >../expect &&
107 ln -s objects .git/alt_objects &&
108 echo "$(pwd)/.git/alt_objects" >.git/objects/info/alternates &&
109 git repack -a -d -l &&
110 ls .git/objects/pack/*.pack >../actual
111 ) &&
112 test_cmp expect actual
113'
114
115test_expect_success '--local disables writing bitmaps when connected to alternate ODB' '
116 test_when_finished "rm -rf shared member" &&
117
118 git init shared &&
119 git clone --shared shared member &&
120 (
121 cd member &&
122 test_commit "object" &&
123 git repack -Adl --write-bitmap-index 2>err &&
124 cat >expect <<-EOF &&
125 warning: disabling bitmap writing, as some objects are not being packed
126 EOF
127 test_cmp expect err &&
128 test_path_is_missing .git/objects/pack-*.bitmap
129 )
130'
131
132test_expect_success 'packed obs in alt ODB are repacked even when local repo is packless' '
133 mkdir alt_objects/pack &&
134 mv .git/objects/pack/* alt_objects/pack &&
135 git repack -a &&
136 test_no_missing_in_packs
137'
138
139test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' '
140 rm -f .git/objects/pack/* &&
141 echo new_content >>file1 &&
142 git add file1 &&
143 test_tick &&
144 git commit -m more_content &&
145 git repack &&
146 git repack -a -d &&
147 test_no_missing_in_packs
148'
149
150test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
151 # swap the .keep so the commit object is in the pack with .keep
152 for p in alt_objects/pack/*.pack
153 do
154 base_name=$(basename $p .pack) &&
155 if test_path_is_file alt_objects/pack/$base_name.keep
156 then
157 rm alt_objects/pack/$base_name.keep
158 else
159 touch alt_objects/pack/$base_name.keep
160 fi || return 1
161 done &&
162 git repack -a -d &&
163 test_no_missing_in_packs
164'
165
166test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
167 rm -f alt_objects/pack/*.keep &&
168 mv .git/objects/pack/* alt_objects/pack/ &&
169 coid=$(git rev-parse HEAD^{commit}) &&
170 git reset --hard HEAD^ &&
171 test_tick &&
172 git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
173 # The pack-objects call on the next line is equivalent to
174 # git repack -A -d without the call to prune-packed
175 git pack-objects --honor-pack-keep --non-empty --all --reflog \
176 --unpack-unreachable </dev/null pack &&
177 rm -f .git/objects/pack/* &&
178 mv pack-* .git/objects/pack/ &&
179 git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
180 ! grep "^$coid " packlist &&
181 echo >.git/objects/info/alternates &&
182 test_must_fail git show $coid
183'
184
185test_expect_success 'local packed unreachable obs that exist in alternate ODB are not loosened' '
186 echo $(pwd)/alt_objects >.git/objects/info/alternates &&
187 echo "$coid" | git pack-objects --non-empty --all --reflog pack &&
188 rm -f .git/objects/pack/* &&
189 mv pack-* .git/objects/pack/ &&
190 # The pack-objects call on the next line is equivalent to
191 # git repack -A -d without the call to prune-packed
192 git pack-objects --honor-pack-keep --non-empty --all --reflog \
193 --unpack-unreachable </dev/null pack &&
194 rm -f .git/objects/pack/* &&
195 mv pack-* .git/objects/pack/ &&
196 git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
197 ! grep "^$coid " &&
198 echo >.git/objects/info/alternates &&
199 test_must_fail git show $coid
200'
201
202test_expect_success 'objects made unreachable by grafts only are kept' '
203 test_tick &&
204 git commit --allow-empty -m "commit 4" &&
205 H0=$(git rev-parse HEAD) &&
206 H1=$(git rev-parse HEAD^) &&
207 H2=$(git rev-parse HEAD^^) &&
208 echo "$H0 $H2" >.git/info/grafts &&
209 git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
210 git repack -a -d &&
211 git cat-file -t $H1
212'
213
214test_expect_success 'repack --keep-pack' '
215 test_create_repo keep-pack &&
216 (
217 cd keep-pack &&
218 # avoid producing different packs due to delta/base choices
219 git config pack.window 0 &&
220 P1=$(commit_and_pack 1) &&
221 P2=$(commit_and_pack 2) &&
222 P3=$(commit_and_pack 3) &&
223 P4=$(commit_and_pack 4) &&
224 ls .git/objects/pack/*.pack >old-counts &&
225 test_line_count = 4 old-counts &&
226 git repack -a -d --keep-pack $P1 --keep-pack $P4 &&
227 ls .git/objects/pack/*.pack >new-counts &&
228 grep -q $P1 new-counts &&
229 grep -q $P4 new-counts &&
230 test_line_count = 3 new-counts &&
231 git fsck &&
232
233 P5=$(commit_and_pack --no-tag 5) &&
234 git reset --hard HEAD^ &&
235 git reflog expire --all --expire=all &&
236 rm -f ".git/objects/pack/${P5%.pack}.idx" &&
237 rm -f ".git/objects/info/commit-graph" &&
238 for from in $(find .git/objects/pack -type f -name "${P5%.pack}.*")
239 do
240 to="$(dirname "$from")/.tmp-1234-$(basename "$from")" &&
241 mv "$from" "$to" || return 1
242 done &&
243
244 # A .idx file without a .pack should not stop us from
245 # repacking what we can.
246 touch .git/objects/pack/pack-does-not-exist.idx &&
247
248 git repack --cruft -d --keep-pack $P1 --keep-pack $P4 &&
249
250 ls .git/objects/pack/*.pack >newer-counts &&
251 test_cmp new-counts newer-counts &&
252 git fsck
253 )
254'
255
256test_expect_success 'repacking fails when missing .pack actually means missing objects' '
257 test_create_repo idx-without-pack &&
258 (
259 cd idx-without-pack &&
260
261 # Avoid producing different packs due to delta/base choices
262 git config pack.window 0 &&
263 P1=$(commit_and_pack 1) &&
264 P2=$(commit_and_pack 2) &&
265 P3=$(commit_and_pack 3) &&
266 P4=$(commit_and_pack 4) &&
267 ls .git/objects/pack/*.pack >old-counts &&
268 test_line_count = 4 old-counts &&
269
270 # Remove one .pack file
271 rm .git/objects/pack/$P2 &&
272
273 ls .git/objects/pack/*.pack >before-pack-dir &&
274
275 test_must_fail git fsck &&
276 test_must_fail env GIT_COMMIT_GRAPH_PARANOIA=true git repack --cruft -d 2>err &&
277 grep "bad object" err &&
278
279 # Before failing, the repack did not modify the
280 # pack directory.
281 ls .git/objects/pack/*.pack >after-pack-dir &&
282 test_cmp before-pack-dir after-pack-dir
283 )
284'
285
286test_expect_success 'bitmaps are created by default in bare repos' '
287 git clone --bare .git bare.git &&
288 rm -f bare.git/objects/pack/*.bitmap &&
289 git -C bare.git repack -ad &&
290 bitmap=$(ls bare.git/objects/pack/*.bitmap) &&
291 test_path_is_file "$bitmap"
292'
293
294test_expect_success 'incremental repack does not complain' '
295 git -C bare.git repack -q 2>repack.err &&
296 test_must_be_empty repack.err
297'
298
299test_expect_success 'bitmaps can be disabled on bare repos' '
300 git -c repack.writeBitmaps=false -C bare.git repack -ad &&
301 bitmap=$(ls bare.git/objects/pack/*.bitmap || :) &&
302 test -z "$bitmap"
303'
304
305test_expect_success 'no bitmaps created if .keep files present' '
306 pack=$(ls bare.git/objects/pack/*.pack) &&
307 test_path_is_file "$pack" &&
308 keep=${pack%.pack}.keep &&
309 test_when_finished "rm -f \"\$keep\"" &&
310 >"$keep" &&
311
312 # Disable --name-hash-version test due to stderr comparison.
313 GIT_TEST_NAME_HASH_VERSION=1 \
314 git -C bare.git repack -ad 2>stderr &&
315 test_must_be_empty stderr &&
316 find bare.git/objects/pack/ -type f -name "*.bitmap" >actual &&
317 test_must_be_empty actual
318'
319
320test_expect_success 'auto-bitmaps do not complain if unavailable' '
321 test_config -C bare.git pack.packSizeLimit 1M &&
322 blob=$(test-tool genrandom big $((1024*1024)) |
323 git -C bare.git hash-object -w --stdin) &&
324 git -C bare.git update-ref refs/tags/big $blob &&
325
326 # Disable --name-hash-version test due to stderr comparison.
327 GIT_TEST_NAME_HASH_VERSION=1 \
328 git -C bare.git repack -ad 2>stderr &&
329 test_must_be_empty stderr &&
330 find bare.git/objects/pack -type f -name "*.bitmap" >actual &&
331 test_must_be_empty actual
332'
333
334test_expect_success 'repacking with a filter works' '
335 git -C bare.git repack -a -d &&
336 test_stdout_line_count = 1 ls bare.git/objects/pack/*.pack &&
337 git -C bare.git -c repack.writebitmaps=false repack -a -d --filter=blob:none &&
338 test_stdout_line_count = 2 ls bare.git/objects/pack/*.pack &&
339 commit_pack=$(test-tool -C bare.git find-pack -c 1 HEAD) &&
340 blob_pack=$(test-tool -C bare.git find-pack -c 1 HEAD:file1) &&
341 test "$commit_pack" != "$blob_pack" &&
342 tree_pack=$(test-tool -C bare.git find-pack -c 1 HEAD^{tree}) &&
343 test "$tree_pack" = "$commit_pack" &&
344 blob_pack2=$(test-tool -C bare.git find-pack -c 1 HEAD:file2) &&
345 test "$blob_pack2" = "$blob_pack"
346'
347
348test_expect_success '--filter fails with --write-bitmap-index' '
349 test_must_fail git -C bare.git repack -a -d --write-bitmap-index --filter=blob:none
350'
351
352test_expect_success 'repacking with two filters works' '
353 git init two-filters &&
354 (
355 cd two-filters &&
356 mkdir subdir &&
357 test_commit foo &&
358 test_commit subdir_bar subdir/bar &&
359 test_commit subdir_baz subdir/baz
360 ) &&
361 git clone --no-local --bare two-filters two-filters.git &&
362 (
363 cd two-filters.git &&
364 test_stdout_line_count = 1 ls objects/pack/*.pack &&
365 git -c repack.writebitmaps=false repack -a -d \
366 --filter=blob:none --filter=tree:1 &&
367 test_stdout_line_count = 2 ls objects/pack/*.pack &&
368 commit_pack=$(test-tool find-pack -c 1 HEAD) &&
369 blob_pack=$(test-tool find-pack -c 1 HEAD:foo.t) &&
370 root_tree_pack=$(test-tool find-pack -c 1 HEAD^{tree}) &&
371 subdir_tree_hash=$(git ls-tree --object-only HEAD -- subdir) &&
372 subdir_tree_pack=$(test-tool find-pack -c 1 "$subdir_tree_hash") &&
373
374 # Root tree and subdir tree are not in the same packfiles
375 test "$commit_pack" != "$blob_pack" &&
376 test "$commit_pack" = "$root_tree_pack" &&
377 test "$blob_pack" = "$subdir_tree_pack"
378 )
379'
380
381prepare_for_keep_packs () {
382 git init keep-packs &&
383 (
384 cd keep-packs &&
385 test_commit foo &&
386 test_commit bar
387 ) &&
388 git clone --no-local --bare keep-packs keep-packs.git &&
389 (
390 cd keep-packs.git &&
391
392 # Create two packs
393 # The first pack will contain all of the objects except one blob
394 git rev-list --objects --all >objs &&
395 grep -v "bar.t" objs | git pack-objects pack &&
396 # The second pack will contain the excluded object and be kept
397 packid=$(grep "bar.t" objs | git pack-objects pack) &&
398 >pack-$packid.keep &&
399
400 # Replace the existing pack with the 2 new ones
401 rm -f objects/pack/pack* &&
402 mv pack-* objects/pack/
403 )
404}
405
406test_expect_success '--filter works with .keep packs' '
407 prepare_for_keep_packs &&
408 (
409 cd keep-packs.git &&
410
411 foo_pack=$(test-tool find-pack -c 1 HEAD:foo.t) &&
412 bar_pack=$(test-tool find-pack -c 1 HEAD:bar.t) &&
413 head_pack=$(test-tool find-pack -c 1 HEAD) &&
414
415 test "$foo_pack" != "$bar_pack" &&
416 test "$foo_pack" = "$head_pack" &&
417
418 git -c repack.writebitmaps=false repack -a -d --filter=blob:none &&
419
420 foo_pack_1=$(test-tool find-pack -c 1 HEAD:foo.t) &&
421 bar_pack_1=$(test-tool find-pack -c 1 HEAD:bar.t) &&
422 head_pack_1=$(test-tool find-pack -c 1 HEAD) &&
423
424 # Object bar is still only in the old .keep pack
425 test "$foo_pack_1" != "$foo_pack" &&
426 test "$bar_pack_1" = "$bar_pack" &&
427 test "$head_pack_1" != "$head_pack" &&
428
429 test "$foo_pack_1" != "$bar_pack_1" &&
430 test "$foo_pack_1" != "$head_pack_1" &&
431 test "$bar_pack_1" != "$head_pack_1"
432 )
433'
434
435test_expect_success '--filter works with --pack-kept-objects and .keep packs' '
436 rm -rf keep-packs keep-packs.git &&
437 prepare_for_keep_packs &&
438 (
439 cd keep-packs.git &&
440
441 foo_pack=$(test-tool find-pack -c 1 HEAD:foo.t) &&
442 bar_pack=$(test-tool find-pack -c 1 HEAD:bar.t) &&
443 head_pack=$(test-tool find-pack -c 1 HEAD) &&
444
445 test "$foo_pack" != "$bar_pack" &&
446 test "$foo_pack" = "$head_pack" &&
447
448 git -c repack.writebitmaps=false repack -a -d --filter=blob:none \
449 --pack-kept-objects &&
450
451 foo_pack_1=$(test-tool find-pack -c 1 HEAD:foo.t) &&
452 test-tool find-pack -c 2 HEAD:bar.t >bar_pack_1 &&
453 head_pack_1=$(test-tool find-pack -c 1 HEAD) &&
454
455 test "$foo_pack_1" != "$foo_pack" &&
456 test "$foo_pack_1" != "$bar_pack" &&
457 test "$head_pack_1" != "$head_pack" &&
458
459 # Object bar is in both the old .keep pack and the new
460 # pack that contained the filtered out objects
461 grep "$bar_pack" bar_pack_1 &&
462 grep "$foo_pack_1" bar_pack_1 &&
463 test "$foo_pack_1" != "$head_pack_1"
464 )
465'
466
467test_expect_success '--filter-to stores filtered out objects' '
468 git -C bare.git repack -a -d &&
469 test_stdout_line_count = 1 ls bare.git/objects/pack/*.pack &&
470
471 git init --bare filtered.git &&
472 git -C bare.git -c repack.writebitmaps=false repack -a -d \
473 --filter=blob:none \
474 --filter-to=../filtered.git/objects/pack/pack &&
475 test_stdout_line_count = 1 ls bare.git/objects/pack/pack-*.pack &&
476 test_stdout_line_count = 1 ls filtered.git/objects/pack/pack-*.pack &&
477
478 commit_pack=$(test-tool -C bare.git find-pack -c 1 HEAD) &&
479 blob_pack=$(test-tool -C bare.git find-pack -c 0 HEAD:file1) &&
480 blob_hash=$(git -C bare.git rev-parse HEAD:file1) &&
481 test -n "$blob_hash" &&
482 blob_pack=$(test-tool -C filtered.git find-pack -c 1 $blob_hash) &&
483
484 echo $(pwd)/filtered.git/objects >bare.git/objects/info/alternates &&
485 blob_pack=$(test-tool -C bare.git find-pack -c 1 HEAD:file1) &&
486 blob_content=$(git -C bare.git show $blob_hash) &&
487 test "$blob_content" = "content1"
488'
489
490test_expect_success '--filter works with --max-pack-size' '
491 rm -rf filtered.git &&
492 git init --bare filtered.git &&
493 git init max-pack-size &&
494 (
495 cd max-pack-size &&
496 test_commit base &&
497 # two blobs which exceed the maximum pack size
498 test-tool genrandom foo 1048576 >foo &&
499 git hash-object -w foo &&
500 test-tool genrandom bar 1048576 >bar &&
501 git hash-object -w bar &&
502 git add foo bar &&
503 git commit -m "adding foo and bar"
504 ) &&
505 git clone --no-local --bare max-pack-size max-pack-size.git &&
506 (
507 cd max-pack-size.git &&
508 git -c repack.writebitmaps=false repack -a -d --filter=blob:none \
509 --max-pack-size=1M \
510 --filter-to=../filtered.git/objects/pack/pack &&
511 echo $(cd .. && pwd)/filtered.git/objects >objects/info/alternates &&
512
513 # Check that the 3 blobs are in different packfiles in filtered.git
514 test_stdout_line_count = 3 ls ../filtered.git/objects/pack/pack-*.pack &&
515 test_stdout_line_count = 1 ls objects/pack/pack-*.pack &&
516 foo_pack=$(test-tool find-pack -c 1 HEAD:foo) &&
517 bar_pack=$(test-tool find-pack -c 1 HEAD:bar) &&
518 base_pack=$(test-tool find-pack -c 1 HEAD:base.t) &&
519 test "$foo_pack" != "$bar_pack" &&
520 test "$foo_pack" != "$base_pack" &&
521 test "$bar_pack" != "$base_pack" &&
522 for pack in "$foo_pack" "$bar_pack" "$base_pack"
523 do
524 case "$foo_pack" in */filtered.git/objects/pack/*) true ;; *) return 1 ;; esac
525 done
526 )
527'
528
529objdir=.git/objects
530midx=$objdir/pack/multi-pack-index
531
532test_expect_success 'setup for --write-midx tests' '
533 git init midx &&
534 (
535 cd midx &&
536 git config core.multiPackIndex true &&
537
538 test_commit base
539 )
540'
541
542test_expect_success '--write-midx unchanged' '
543 (
544 cd midx &&
545 git repack &&
546 test_path_is_missing $midx &&
547 test_path_is_missing $midx-*.bitmap &&
548
549 git repack --write-midx &&
550
551 test_path_is_file $midx &&
552 test_path_is_missing $midx-*.bitmap &&
553 test_midx_consistent $objdir
554 )
555'
556
557test_expect_success '--write-midx with a new pack' '
558 (
559 cd midx &&
560 test_commit loose &&
561
562 git repack --write-midx &&
563
564 test_path_is_file $midx &&
565 test_path_is_missing $midx-*.bitmap &&
566 test_midx_consistent $objdir
567 )
568'
569
570test_expect_success '--write-midx with -b' '
571 (
572 cd midx &&
573 git repack -mb &&
574
575 test_path_is_file $midx &&
576 test_path_is_file $midx-*.bitmap &&
577 test_midx_consistent $objdir
578 )
579'
580
581test_expect_success '--write-midx with -d' '
582 (
583 cd midx &&
584 test_commit repack &&
585
586 git repack -Ad --write-midx &&
587
588 test_path_is_file $midx &&
589 test_path_is_missing $midx-*.bitmap &&
590 test_midx_consistent $objdir
591 )
592'
593
594test_expect_success 'cleans up MIDX when appropriate' '
595 (
596 cd midx &&
597
598 test_commit repack-2 &&
599 git repack -Adb --write-midx &&
600
601 checksum=$(midx_checksum $objdir) &&
602 test_path_is_file $midx &&
603 test_path_is_file $midx-$checksum.bitmap &&
604
605 test_commit repack-3 &&
606 git repack -Adb --write-midx &&
607
608 test_path_is_file $midx &&
609 test_path_is_missing $midx-$checksum.bitmap &&
610 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
611
612 test_commit repack-4 &&
613 git repack -Adb &&
614
615 find $objdir/pack -type f -name "multi-pack-index*" >files &&
616 test_must_be_empty files
617 )
618'
619
620test_expect_success '--write-midx with preferred bitmap tips' '
621 git init midx-preferred-tips &&
622 test_when_finished "rm -fr midx-preferred-tips" &&
623 (
624 cd midx-preferred-tips &&
625
626 test_commit_bulk --message="%s" 103 &&
627
628 git log --format="%H" >commits.raw &&
629 sort <commits.raw >commits &&
630
631 git log --format="create refs/tags/%s/%s %H" HEAD >refs &&
632 git update-ref --stdin <refs &&
633
634 git repack --write-midx --write-bitmap-index &&
635 test_path_is_file $midx &&
636 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
637
638 test-tool bitmap list-commits | sort >bitmaps &&
639 comm -13 bitmaps commits >before &&
640 test_line_count = 1 before &&
641
642 rm -fr $midx-$(midx_checksum $objdir).bitmap &&
643 rm -fr $midx &&
644
645 # instead of constructing the snapshot ourselves (c.f., the test
646 # "write a bitmap with --refs-snapshot (preferred tips)" in
647 # t5326), mark the missing commit as preferred by adding it to
648 # the pack.preferBitmapTips configuration.
649 git for-each-ref --format="%(refname:rstrip=1)" \
650 --points-at="$(cat before)" >missing &&
651 git config pack.preferBitmapTips "$(cat missing)" &&
652 git repack --write-midx --write-bitmap-index &&
653
654 test-tool bitmap list-commits | sort >bitmaps &&
655 comm -13 bitmaps commits >after &&
656
657 ! test_cmp before after
658 )
659'
660
661# The first argument is expected to be a filename
662# and that file should contain the name of a .idx
663# file. Send the list of objects in that .idx file
664# into stdout.
665get_sorted_objects_from_pack () {
666 git show-index <$(cat "$1") >raw &&
667 cut -d" " -f2 raw
668}
669
670test_expect_success '--write-midx -b packs non-kept objects' '
671 git init repo &&
672 test_when_finished "rm -fr repo" &&
673 (
674 cd repo &&
675
676 # Create a kept pack-file
677 test_commit base &&
678 git repack -ad &&
679 find $objdir/pack -name "*.idx" >before &&
680 test_line_count = 1 before &&
681 before_name=$(cat before) &&
682 >${before_name%.idx}.keep &&
683
684 # Create a non-kept pack-file
685 test_commit other &&
686 git repack &&
687
688 # Create loose objects
689 test_commit loose &&
690
691 # Repack everything
692 git repack --write-midx -a -b -d &&
693
694 # There should be two pack-files now, the
695 # old, kept pack and the new, non-kept pack.
696 find $objdir/pack -name "*.idx" | sort >after &&
697 test_line_count = 2 after &&
698 find $objdir/pack -name "*.keep" >kept &&
699 kept_name=$(cat kept) &&
700 echo ${kept_name%.keep}.idx >kept-idx &&
701 test_cmp before kept-idx &&
702
703 # Get object list from the kept pack.
704 get_sorted_objects_from_pack before >old.objects &&
705
706 # Get object list from the one non-kept pack-file
707 comm -13 before after >new-pack &&
708 test_line_count = 1 new-pack &&
709 get_sorted_objects_from_pack new-pack >new.objects &&
710
711 # None of the objects in the new pack should
712 # exist within the kept pack.
713 comm -12 old.objects new.objects >shared.objects &&
714 test_must_be_empty shared.objects
715 )
716'
717
718test_expect_success '--write-midx removes stale pack-based bitmaps' '
719 rm -fr repo &&
720 git init repo &&
721 test_when_finished "rm -fr repo" &&
722 (
723 cd repo &&
724 test_commit base &&
725 git repack -Ab &&
726
727 pack_bitmap=$(ls $objdir/pack/pack-*.bitmap) &&
728 test_path_is_file "$pack_bitmap" &&
729
730 test_commit tip &&
731 git repack -bm &&
732
733 test_path_is_file $midx &&
734 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
735 test_path_is_missing $pack_bitmap
736 )
737'
738
739test_expect_success '--write-midx with --pack-kept-objects' '
740 git init repo &&
741 test_when_finished "rm -fr repo" &&
742 (
743 cd repo &&
744
745 test_commit one &&
746 test_commit two &&
747
748 one="$(echo "one" | git pack-objects --revs $objdir/pack/pack)" &&
749 two="$(echo "one..two" | git pack-objects --revs $objdir/pack/pack)" &&
750
751 keep="$objdir/pack/pack-$one.keep" &&
752 touch "$keep" &&
753
754 git repack --write-midx --write-bitmap-index --geometric=2 -d \
755 --pack-kept-objects &&
756
757 test_path_is_file $keep &&
758 test_path_is_file $midx &&
759 test_path_is_file $midx-$(midx_checksum $objdir).bitmap
760 )
761'
762
763test_expect_success TTY '--quiet disables progress' '
764 test_terminal env GIT_PROGRESS_DELAY=0 \
765 git -C midx repack -ad --quiet --write-midx 2>stderr &&
766 test_must_be_empty stderr
767'
768
769test_expect_success 'clean up .tmp-* packs on error' '
770 test_must_fail ok=sigpipe git \
771 -c repack.cruftwindow=bogus \
772 repack -ad --cruft &&
773 find $objdir/pack -name '.tmp-*' >tmpfiles &&
774 test_must_be_empty tmpfiles
775'
776
777test_expect_success 'repack -ad cleans up old .tmp-* packs' '
778 git rev-parse HEAD >input &&
779 git pack-objects $objdir/pack/.tmp-1234 <input &&
780 git repack -ad &&
781 find $objdir/pack -name '.tmp-*' >tmpfiles &&
782 test_must_be_empty tmpfiles
783'
784
785test_expect_success '--name-hash-version option passes through to pack-objects' '
786 GIT_TRACE2_EVENT="$(pwd)/hash-trace.txt" \
787 git repack -a --name-hash-version=2 &&
788 test_subcommand_flex git pack-objects --name-hash-version=2 <hash-trace.txt
789'
790
791test_expect_success 'setup for update-server-info' '
792 git init update-server-info &&
793 test_commit -C update-server-info message
794'
795
796test_server_info_present () {
797 test_path_is_file update-server-info/.git/objects/info/packs &&
798 test_path_is_file update-server-info/.git/info/refs
799}
800
801test_server_info_missing () {
802 test_path_is_missing update-server-info/.git/objects/info/packs &&
803 test_path_is_missing update-server-info/.git/info/refs
804}
805
806test_server_info_cleanup () {
807 rm -f update-server-info/.git/objects/info/packs update-server-info/.git/info/refs &&
808 test_server_info_missing
809}
810
811test_expect_success 'updates server info by default' '
812 test_server_info_cleanup &&
813 git -C update-server-info repack &&
814 test_server_info_present
815'
816
817test_expect_success '-n skips updating server info' '
818 test_server_info_cleanup &&
819 git -C update-server-info repack -n &&
820 test_server_info_missing
821'
822
823test_expect_success 'repack.updateServerInfo=true updates server info' '
824 test_server_info_cleanup &&
825 git -C update-server-info -c repack.updateServerInfo=true repack &&
826 test_server_info_present
827'
828
829test_expect_success 'repack.updateServerInfo=false skips updating server info' '
830 test_server_info_cleanup &&
831 git -C update-server-info -c repack.updateServerInfo=false repack &&
832 test_server_info_missing
833'
834
835test_expect_success '-n overrides repack.updateServerInfo=true' '
836 test_server_info_cleanup &&
837 git -C update-server-info -c repack.updateServerInfo=true repack -n &&
838 test_server_info_missing
839'
840
841test_expect_success 'pending objects are repacked appropriately' '
842 test_when_finished rm -rf pending &&
843 git init pending &&
844
845 (
846 cd pending &&
847
848 # Commit file, a/b/c and never change them.
849 mkdir -p a/b &&
850 echo singleton >file &&
851 echo stuff >a/b/c &&
852 echo more >a/d &&
853 git add file a &&
854 git commit -m "single blobs" &&
855
856 # Files a/d and a/e will not be singletons.
857 echo d >a/d &&
858 echo e >a/e &&
859 git add a &&
860 git commit -m "more blobs" &&
861
862 # This use of a sparse index helps to force
863 # test that the cache-tree is walked, too.
864 git sparse-checkout set --sparse-index a x &&
865
866 # Create staged changes:
867 # * a/e now has multiple versions.
868 # * a/i now has only one version.
869 echo f >a/d &&
870 echo h >a/e &&
871 echo i >a/i &&
872 git add a &&
873
874 # Stage and unstage a change to make use of
875 # resolve-undo cache and how that impacts fsck.
876 mkdir x &&
877 echo y >x/y &&
878 git add x &&
879 xy=$(git rev-parse :x/y) &&
880 git rm --cached x/y &&
881
882 # The blob for x/y must persist through repacks,
883 # but fsck currently ignores the REUC extension
884 # for finding links to the blob.
885 cat >expect <<-EOF &&
886 dangling blob $xy
887 EOF
888
889 # Bring the loose objects into a packfile to avoid
890 # leftovers in next test. Without this, the loose
891 # objects persist and the test succeeds for other
892 # reasons.
893 git repack -adf &&
894 git fsck >out &&
895 test_cmp expect out &&
896
897 # Test path walk version with pack.useSparse.
898 git -c pack.useSparse=true repack -adf --path-walk &&
899 git fsck >out &&
900 test_cmp expect out
901 )
902'
903
904test_done