The eighteenth batch
[git.git] / t / t7700-repack.sh
blobbe1188e7365b19cdf7fb96115ae83efc23038a11
1 #!/bin/sh
3 test_description='git repack works correctly'
5 . ./test-lib.sh
6 . "${TEST_DIRECTORY}/lib-bitmap.sh"
7 . "${TEST_DIRECTORY}/lib-midx.sh"
8 . "${TEST_DIRECTORY}/lib-terminal.sh"
10 GIT_TEST_MULTI_PACK_INDEX=0
11 GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL=0
13 commit_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
23 test_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
34 # we expect $packid and $oid to be defined
35 test_has_duplicate_object () {
36 want_duplicate_object="$1"
37 found_duplicate_object=false
38 for p in .git/objects/pack/*.idx
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
49 done &&
50 test "$want_duplicate_object" = "$found_duplicate_object"
53 test_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
74 test_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
80 test_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
86 test_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
99 test_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 &&
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
115 test_expect_success '--local disables writing bitmaps when connected to alternate ODB' '
116 test_when_finished "rm -rf shared member" &&
118 git init shared &&
119 git clone --shared shared member &&
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
127 test_cmp expect err &&
128 test_path_is_missing .git/objects/pack-*.bitmap
132 test_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
139 test_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
150 test_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
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
166 test_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
185 test_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
202 test_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
214 test_expect_success 'repack --keep-pack' '
215 test_create_repo keep-pack &&
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 &&
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}.*")
240 to="$(dirname "$from")/.tmp-1234-$(basename "$from")" &&
241 mv "$from" "$to" || return 1
242 done &&
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 &&
248 git repack --cruft -d --keep-pack $P1 --keep-pack $P4 &&
250 ls .git/objects/pack/*.pack >newer-counts &&
251 test_cmp new-counts newer-counts &&
252 git fsck
256 test_expect_success 'repacking fails when missing .pack actually means missing objects' '
257 test_create_repo idx-without-pack &&
259 cd idx-without-pack &&
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 &&
270 # Remove one .pack file
271 rm .git/objects/pack/$P2 &&
273 ls .git/objects/pack/*.pack >before-pack-dir &&
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 &&
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
286 test_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"
294 test_expect_success 'incremental repack does not complain' '
295 git -C bare.git repack -q 2>repack.err &&
296 test_must_be_empty repack.err
299 test_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"
305 test_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 git -C bare.git repack -ad 2>stderr &&
312 test_must_be_empty stderr &&
313 find bare.git/objects/pack/ -type f -name "*.bitmap" >actual &&
314 test_must_be_empty actual
317 test_expect_success 'auto-bitmaps do not complain if unavailable' '
318 test_config -C bare.git pack.packSizeLimit 1M &&
319 blob=$(test-tool genrandom big $((1024*1024)) |
320 git -C bare.git hash-object -w --stdin) &&
321 git -C bare.git update-ref refs/tags/big $blob &&
322 git -C bare.git repack -ad 2>stderr &&
323 test_must_be_empty stderr &&
324 find bare.git/objects/pack -type f -name "*.bitmap" >actual &&
325 test_must_be_empty actual
328 test_expect_success 'repacking with a filter works' '
329 git -C bare.git repack -a -d &&
330 test_stdout_line_count = 1 ls bare.git/objects/pack/*.pack &&
331 git -C bare.git -c repack.writebitmaps=false repack -a -d --filter=blob:none &&
332 test_stdout_line_count = 2 ls bare.git/objects/pack/*.pack &&
333 commit_pack=$(test-tool -C bare.git find-pack -c 1 HEAD) &&
334 blob_pack=$(test-tool -C bare.git find-pack -c 1 HEAD:file1) &&
335 test "$commit_pack" != "$blob_pack" &&
336 tree_pack=$(test-tool -C bare.git find-pack -c 1 HEAD^{tree}) &&
337 test "$tree_pack" = "$commit_pack" &&
338 blob_pack2=$(test-tool -C bare.git find-pack -c 1 HEAD:file2) &&
339 test "$blob_pack2" = "$blob_pack"
342 test_expect_success '--filter fails with --write-bitmap-index' '
343 test_must_fail git -C bare.git repack -a -d --write-bitmap-index --filter=blob:none
346 test_expect_success 'repacking with two filters works' '
347 git init two-filters &&
349 cd two-filters &&
350 mkdir subdir &&
351 test_commit foo &&
352 test_commit subdir_bar subdir/bar &&
353 test_commit subdir_baz subdir/baz
354 ) &&
355 git clone --no-local --bare two-filters two-filters.git &&
357 cd two-filters.git &&
358 test_stdout_line_count = 1 ls objects/pack/*.pack &&
359 git -c repack.writebitmaps=false repack -a -d \
360 --filter=blob:none --filter=tree:1 &&
361 test_stdout_line_count = 2 ls objects/pack/*.pack &&
362 commit_pack=$(test-tool find-pack -c 1 HEAD) &&
363 blob_pack=$(test-tool find-pack -c 1 HEAD:foo.t) &&
364 root_tree_pack=$(test-tool find-pack -c 1 HEAD^{tree}) &&
365 subdir_tree_hash=$(git ls-tree --object-only HEAD -- subdir) &&
366 subdir_tree_pack=$(test-tool find-pack -c 1 "$subdir_tree_hash") &&
368 # Root tree and subdir tree are not in the same packfiles
369 test "$commit_pack" != "$blob_pack" &&
370 test "$commit_pack" = "$root_tree_pack" &&
371 test "$blob_pack" = "$subdir_tree_pack"
375 prepare_for_keep_packs () {
376 git init keep-packs &&
378 cd keep-packs &&
379 test_commit foo &&
380 test_commit bar
381 ) &&
382 git clone --no-local --bare keep-packs keep-packs.git &&
384 cd keep-packs.git &&
386 # Create two packs
387 # The first pack will contain all of the objects except one blob
388 git rev-list --objects --all >objs &&
389 grep -v "bar.t" objs | git pack-objects pack &&
390 # The second pack will contain the excluded object and be kept
391 packid=$(grep "bar.t" objs | git pack-objects pack) &&
392 >pack-$packid.keep &&
394 # Replace the existing pack with the 2 new ones
395 rm -f objects/pack/pack* &&
396 mv pack-* objects/pack/
400 test_expect_success '--filter works with .keep packs' '
401 prepare_for_keep_packs &&
403 cd keep-packs.git &&
405 foo_pack=$(test-tool find-pack -c 1 HEAD:foo.t) &&
406 bar_pack=$(test-tool find-pack -c 1 HEAD:bar.t) &&
407 head_pack=$(test-tool find-pack -c 1 HEAD) &&
409 test "$foo_pack" != "$bar_pack" &&
410 test "$foo_pack" = "$head_pack" &&
412 git -c repack.writebitmaps=false repack -a -d --filter=blob:none &&
414 foo_pack_1=$(test-tool find-pack -c 1 HEAD:foo.t) &&
415 bar_pack_1=$(test-tool find-pack -c 1 HEAD:bar.t) &&
416 head_pack_1=$(test-tool find-pack -c 1 HEAD) &&
418 # Object bar is still only in the old .keep pack
419 test "$foo_pack_1" != "$foo_pack" &&
420 test "$bar_pack_1" = "$bar_pack" &&
421 test "$head_pack_1" != "$head_pack" &&
423 test "$foo_pack_1" != "$bar_pack_1" &&
424 test "$foo_pack_1" != "$head_pack_1" &&
425 test "$bar_pack_1" != "$head_pack_1"
429 test_expect_success '--filter works with --pack-kept-objects and .keep packs' '
430 rm -rf keep-packs keep-packs.git &&
431 prepare_for_keep_packs &&
433 cd keep-packs.git &&
435 foo_pack=$(test-tool find-pack -c 1 HEAD:foo.t) &&
436 bar_pack=$(test-tool find-pack -c 1 HEAD:bar.t) &&
437 head_pack=$(test-tool find-pack -c 1 HEAD) &&
439 test "$foo_pack" != "$bar_pack" &&
440 test "$foo_pack" = "$head_pack" &&
442 git -c repack.writebitmaps=false repack -a -d --filter=blob:none \
443 --pack-kept-objects &&
445 foo_pack_1=$(test-tool find-pack -c 1 HEAD:foo.t) &&
446 test-tool find-pack -c 2 HEAD:bar.t >bar_pack_1 &&
447 head_pack_1=$(test-tool find-pack -c 1 HEAD) &&
449 test "$foo_pack_1" != "$foo_pack" &&
450 test "$foo_pack_1" != "$bar_pack" &&
451 test "$head_pack_1" != "$head_pack" &&
453 # Object bar is in both the old .keep pack and the new
454 # pack that contained the filtered out objects
455 grep "$bar_pack" bar_pack_1 &&
456 grep "$foo_pack_1" bar_pack_1 &&
457 test "$foo_pack_1" != "$head_pack_1"
461 test_expect_success '--filter-to stores filtered out objects' '
462 git -C bare.git repack -a -d &&
463 test_stdout_line_count = 1 ls bare.git/objects/pack/*.pack &&
465 git init --bare filtered.git &&
466 git -C bare.git -c repack.writebitmaps=false repack -a -d \
467 --filter=blob:none \
468 --filter-to=../filtered.git/objects/pack/pack &&
469 test_stdout_line_count = 1 ls bare.git/objects/pack/pack-*.pack &&
470 test_stdout_line_count = 1 ls filtered.git/objects/pack/pack-*.pack &&
472 commit_pack=$(test-tool -C bare.git find-pack -c 1 HEAD) &&
473 blob_pack=$(test-tool -C bare.git find-pack -c 0 HEAD:file1) &&
474 blob_hash=$(git -C bare.git rev-parse HEAD:file1) &&
475 test -n "$blob_hash" &&
476 blob_pack=$(test-tool -C filtered.git find-pack -c 1 $blob_hash) &&
478 echo $(pwd)/filtered.git/objects >bare.git/objects/info/alternates &&
479 blob_pack=$(test-tool -C bare.git find-pack -c 1 HEAD:file1) &&
480 blob_content=$(git -C bare.git show $blob_hash) &&
481 test "$blob_content" = "content1"
484 test_expect_success '--filter works with --max-pack-size' '
485 rm -rf filtered.git &&
486 git init --bare filtered.git &&
487 git init max-pack-size &&
489 cd max-pack-size &&
490 test_commit base &&
491 # two blobs which exceed the maximum pack size
492 test-tool genrandom foo 1048576 >foo &&
493 git hash-object -w foo &&
494 test-tool genrandom bar 1048576 >bar &&
495 git hash-object -w bar &&
496 git add foo bar &&
497 git commit -m "adding foo and bar"
498 ) &&
499 git clone --no-local --bare max-pack-size max-pack-size.git &&
501 cd max-pack-size.git &&
502 git -c repack.writebitmaps=false repack -a -d --filter=blob:none \
503 --max-pack-size=1M \
504 --filter-to=../filtered.git/objects/pack/pack &&
505 echo $(cd .. && pwd)/filtered.git/objects >objects/info/alternates &&
507 # Check that the 3 blobs are in different packfiles in filtered.git
508 test_stdout_line_count = 3 ls ../filtered.git/objects/pack/pack-*.pack &&
509 test_stdout_line_count = 1 ls objects/pack/pack-*.pack &&
510 foo_pack=$(test-tool find-pack -c 1 HEAD:foo) &&
511 bar_pack=$(test-tool find-pack -c 1 HEAD:bar) &&
512 base_pack=$(test-tool find-pack -c 1 HEAD:base.t) &&
513 test "$foo_pack" != "$bar_pack" &&
514 test "$foo_pack" != "$base_pack" &&
515 test "$bar_pack" != "$base_pack" &&
516 for pack in "$foo_pack" "$bar_pack" "$base_pack"
518 case "$foo_pack" in */filtered.git/objects/pack/*) true ;; *) return 1 ;; esac
519 done
523 objdir=.git/objects
524 midx=$objdir/pack/multi-pack-index
526 test_expect_success 'setup for --write-midx tests' '
527 git init midx &&
529 cd midx &&
530 git config core.multiPackIndex true &&
532 test_commit base
536 test_expect_success '--write-midx unchanged' '
538 cd midx &&
539 git repack &&
540 test_path_is_missing $midx &&
541 test_path_is_missing $midx-*.bitmap &&
543 git repack --write-midx &&
545 test_path_is_file $midx &&
546 test_path_is_missing $midx-*.bitmap &&
547 test_midx_consistent $objdir
551 test_expect_success '--write-midx with a new pack' '
553 cd midx &&
554 test_commit loose &&
556 git repack --write-midx &&
558 test_path_is_file $midx &&
559 test_path_is_missing $midx-*.bitmap &&
560 test_midx_consistent $objdir
564 test_expect_success '--write-midx with -b' '
566 cd midx &&
567 git repack -mb &&
569 test_path_is_file $midx &&
570 test_path_is_file $midx-*.bitmap &&
571 test_midx_consistent $objdir
575 test_expect_success '--write-midx with -d' '
577 cd midx &&
578 test_commit repack &&
580 git repack -Ad --write-midx &&
582 test_path_is_file $midx &&
583 test_path_is_missing $midx-*.bitmap &&
584 test_midx_consistent $objdir
588 test_expect_success 'cleans up MIDX when appropriate' '
590 cd midx &&
592 test_commit repack-2 &&
593 git repack -Adb --write-midx &&
595 checksum=$(midx_checksum $objdir) &&
596 test_path_is_file $midx &&
597 test_path_is_file $midx-$checksum.bitmap &&
599 test_commit repack-3 &&
600 git repack -Adb --write-midx &&
602 test_path_is_file $midx &&
603 test_path_is_missing $midx-$checksum.bitmap &&
604 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
606 test_commit repack-4 &&
607 git repack -Adb &&
609 find $objdir/pack -type f -name "multi-pack-index*" >files &&
610 test_must_be_empty files
614 test_expect_success '--write-midx with preferred bitmap tips' '
615 git init midx-preferred-tips &&
616 test_when_finished "rm -fr midx-preferred-tips" &&
618 cd midx-preferred-tips &&
620 test_commit_bulk --message="%s" 103 &&
622 git log --format="%H" >commits.raw &&
623 sort <commits.raw >commits &&
625 git log --format="create refs/tags/%s/%s %H" HEAD >refs &&
626 git update-ref --stdin <refs &&
628 git repack --write-midx --write-bitmap-index &&
629 test_path_is_file $midx &&
630 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
632 test-tool bitmap list-commits | sort >bitmaps &&
633 comm -13 bitmaps commits >before &&
634 test_line_count = 1 before &&
636 rm -fr $midx-$(midx_checksum $objdir).bitmap &&
637 rm -fr $midx &&
639 # instead of constructing the snapshot ourselves (c.f., the test
640 # "write a bitmap with --refs-snapshot (preferred tips)" in
641 # t5326), mark the missing commit as preferred by adding it to
642 # the pack.preferBitmapTips configuration.
643 git for-each-ref --format="%(refname:rstrip=1)" \
644 --points-at="$(cat before)" >missing &&
645 git config pack.preferBitmapTips "$(cat missing)" &&
646 git repack --write-midx --write-bitmap-index &&
648 test-tool bitmap list-commits | sort >bitmaps &&
649 comm -13 bitmaps commits >after &&
651 ! test_cmp before after
655 # The first argument is expected to be a filename
656 # and that file should contain the name of a .idx
657 # file. Send the list of objects in that .idx file
658 # into stdout.
659 get_sorted_objects_from_pack () {
660 git show-index <$(cat "$1") >raw &&
661 cut -d" " -f2 raw
664 test_expect_success '--write-midx -b packs non-kept objects' '
665 git init repo &&
666 test_when_finished "rm -fr repo" &&
668 cd repo &&
670 # Create a kept pack-file
671 test_commit base &&
672 git repack -ad &&
673 find $objdir/pack -name "*.idx" >before &&
674 test_line_count = 1 before &&
675 before_name=$(cat before) &&
676 >${before_name%.idx}.keep &&
678 # Create a non-kept pack-file
679 test_commit other &&
680 git repack &&
682 # Create loose objects
683 test_commit loose &&
685 # Repack everything
686 git repack --write-midx -a -b -d &&
688 # There should be two pack-files now, the
689 # old, kept pack and the new, non-kept pack.
690 find $objdir/pack -name "*.idx" | sort >after &&
691 test_line_count = 2 after &&
692 find $objdir/pack -name "*.keep" >kept &&
693 kept_name=$(cat kept) &&
694 echo ${kept_name%.keep}.idx >kept-idx &&
695 test_cmp before kept-idx &&
697 # Get object list from the kept pack.
698 get_sorted_objects_from_pack before >old.objects &&
700 # Get object list from the one non-kept pack-file
701 comm -13 before after >new-pack &&
702 test_line_count = 1 new-pack &&
703 get_sorted_objects_from_pack new-pack >new.objects &&
705 # None of the objects in the new pack should
706 # exist within the kept pack.
707 comm -12 old.objects new.objects >shared.objects &&
708 test_must_be_empty shared.objects
712 test_expect_success '--write-midx removes stale pack-based bitmaps' '
713 rm -fr repo &&
714 git init repo &&
715 test_when_finished "rm -fr repo" &&
717 cd repo &&
718 test_commit base &&
719 git repack -Ab &&
721 pack_bitmap=$(ls $objdir/pack/pack-*.bitmap) &&
722 test_path_is_file "$pack_bitmap" &&
724 test_commit tip &&
725 git repack -bm &&
727 test_path_is_file $midx &&
728 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
729 test_path_is_missing $pack_bitmap
733 test_expect_success '--write-midx with --pack-kept-objects' '
734 git init repo &&
735 test_when_finished "rm -fr repo" &&
737 cd repo &&
739 test_commit one &&
740 test_commit two &&
742 one="$(echo "one" | git pack-objects --revs $objdir/pack/pack)" &&
743 two="$(echo "one..two" | git pack-objects --revs $objdir/pack/pack)" &&
745 keep="$objdir/pack/pack-$one.keep" &&
746 touch "$keep" &&
748 git repack --write-midx --write-bitmap-index --geometric=2 -d \
749 --pack-kept-objects &&
751 test_path_is_file $keep &&
752 test_path_is_file $midx &&
753 test_path_is_file $midx-$(midx_checksum $objdir).bitmap
757 test_expect_success TTY '--quiet disables progress' '
758 test_terminal env GIT_PROGRESS_DELAY=0 \
759 git -C midx repack -ad --quiet --write-midx 2>stderr &&
760 test_must_be_empty stderr
763 test_expect_success 'clean up .tmp-* packs on error' '
764 test_must_fail ok=sigpipe git \
765 -c repack.cruftwindow=bogus \
766 repack -ad --cruft &&
767 find $objdir/pack -name '.tmp-*' >tmpfiles &&
768 test_must_be_empty tmpfiles
771 test_expect_success 'repack -ad cleans up old .tmp-* packs' '
772 git rev-parse HEAD >input &&
773 git pack-objects $objdir/pack/.tmp-1234 <input &&
774 git repack -ad &&
775 find $objdir/pack -name '.tmp-*' >tmpfiles &&
776 test_must_be_empty tmpfiles
779 test_expect_success 'setup for update-server-info' '
780 git init update-server-info &&
781 test_commit -C update-server-info message
784 test_server_info_present () {
785 test_path_is_file update-server-info/.git/objects/info/packs &&
786 test_path_is_file update-server-info/.git/info/refs
789 test_server_info_missing () {
790 test_path_is_missing update-server-info/.git/objects/info/packs &&
791 test_path_is_missing update-server-info/.git/info/refs
794 test_server_info_cleanup () {
795 rm -f update-server-info/.git/objects/info/packs update-server-info/.git/info/refs &&
796 test_server_info_missing
799 test_expect_success 'updates server info by default' '
800 test_server_info_cleanup &&
801 git -C update-server-info repack &&
802 test_server_info_present
805 test_expect_success '-n skips updating server info' '
806 test_server_info_cleanup &&
807 git -C update-server-info repack -n &&
808 test_server_info_missing
811 test_expect_success 'repack.updateServerInfo=true updates server info' '
812 test_server_info_cleanup &&
813 git -C update-server-info -c repack.updateServerInfo=true repack &&
814 test_server_info_present
817 test_expect_success 'repack.updateServerInfo=false skips updating server info' '
818 test_server_info_cleanup &&
819 git -C update-server-info -c repack.updateServerInfo=false repack &&
820 test_server_info_missing
823 test_expect_success '-n overrides repack.updateServerInfo=true' '
824 test_server_info_cleanup &&
825 git -C update-server-info -c repack.updateServerInfo=true repack -n &&
826 test_server_info_missing
829 test_done