parse-options: recognize abbreviated negated option with arg
[git.git] / t / t7700-repack.sh
blob94f9f4a1dac5621fbd340b6425d2f2ea7f042016
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 commit_and_pack () {
11 test_commit "$@" 1>&2 &&
12 incrpackid=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) &&
13 # Remove any loose object(s) created by test_commit, since they have
14 # already been packed. Leaving these around can create subtly different
15 # packs with `pack-objects`'s `--unpacked` option.
16 git prune-packed 1>&2 &&
17 echo pack-${incrpackid}.pack
20 test_no_missing_in_packs () {
21 myidx=$(ls -1 .git/objects/pack/*.idx) &&
22 test_path_is_file "$myidx" &&
23 git verify-pack -v alt_objects/pack/*.idx >orig.raw &&
24 sed -n -e "s/^\($OID_REGEX\).*/\1/p" orig.raw | sort >orig &&
25 git verify-pack -v $myidx >dest.raw &&
26 cut -d" " -f1 dest.raw | sort >dest &&
27 comm -23 orig dest >missing &&
28 test_must_be_empty missing
31 # we expect $packid and $oid to be defined
32 test_has_duplicate_object () {
33 want_duplicate_object="$1"
34 found_duplicate_object=false
35 for p in .git/objects/pack/*.idx
37 idx=$(basename $p)
38 test "pack-$packid.idx" = "$idx" && continue
39 git verify-pack -v $p >packlist || return $?
40 if grep "^$oid" packlist
41 then
42 found_duplicate_object=true
43 echo "DUPLICATE OBJECT FOUND"
44 break
46 done &&
47 test "$want_duplicate_object" = "$found_duplicate_object"
50 test_expect_success 'objects in packs marked .keep are not repacked' '
51 echo content1 >file1 &&
52 echo content2 >file2 &&
53 git add . &&
54 test_tick &&
55 git commit -m initial_commit &&
56 # Create two packs
57 # The first pack will contain all of the objects except one
58 git rev-list --objects --all >objs &&
59 grep -v file2 objs | git pack-objects pack &&
60 # The second pack will contain the excluded object
61 packid=$(grep file2 objs | git pack-objects pack) &&
62 >pack-$packid.keep &&
63 git verify-pack -v pack-$packid.idx >packlist &&
64 oid=$(head -n 1 packlist | sed -e "s/^\($OID_REGEX\).*/\1/") &&
65 mv pack-* .git/objects/pack/ &&
66 git repack -A -d -l &&
67 git prune-packed &&
68 test_has_duplicate_object false
71 test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' '
72 # build on $oid, $packid, and .keep state from previous
73 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 git repack -Adbl &&
74 test_has_duplicate_object true
77 test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
78 # build on $oid, $packid, and .keep state from previous
79 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
80 git -c repack.writebitmaps=true repack -Adl &&
81 test_has_duplicate_object true
84 test_expect_success 'loose objects in alternate ODB are not repacked' '
85 mkdir alt_objects &&
86 echo $(pwd)/alt_objects >.git/objects/info/alternates &&
87 echo content3 >file3 &&
88 oid=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
89 git add file3 &&
90 test_tick &&
91 git commit -m commit_file3 &&
92 git repack -a -d -l &&
93 git prune-packed &&
94 test_has_duplicate_object false
97 test_expect_success SYMLINKS '--local keeps packs when alternate is objectdir ' '
98 test_when_finished "rm -rf repo" &&
99 git init repo &&
100 test_commit -C repo A &&
102 cd repo &&
103 git repack -a &&
104 ls .git/objects/pack/*.pack >../expect &&
105 ln -s objects .git/alt_objects &&
106 echo "$(pwd)/.git/alt_objects" >.git/objects/info/alternates &&
107 git repack -a -d -l &&
108 ls .git/objects/pack/*.pack >../actual
109 ) &&
110 test_cmp expect actual
113 test_expect_success '--local disables writing bitmaps when connected to alternate ODB' '
114 test_when_finished "rm -rf shared member" &&
116 git init shared &&
117 git clone --shared shared member &&
119 cd member &&
120 test_commit "object" &&
121 GIT_TEST_MULTI_PACK_INDEX=0 git repack -Adl --write-bitmap-index 2>err &&
122 cat >expect <<-EOF &&
123 warning: disabling bitmap writing, as some objects are not being packed
125 test_cmp expect err &&
126 test_path_is_missing .git/objects/pack-*.bitmap
130 test_expect_success 'packed obs in alt ODB are repacked even when local repo is packless' '
131 mkdir alt_objects/pack &&
132 mv .git/objects/pack/* alt_objects/pack &&
133 git repack -a &&
134 test_no_missing_in_packs
137 test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' '
138 rm -f .git/objects/pack/* &&
139 echo new_content >>file1 &&
140 git add file1 &&
141 test_tick &&
142 git commit -m more_content &&
143 git repack &&
144 git repack -a -d &&
145 test_no_missing_in_packs
148 test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
149 # swap the .keep so the commit object is in the pack with .keep
150 for p in alt_objects/pack/*.pack
152 base_name=$(basename $p .pack) &&
153 if test_path_is_file alt_objects/pack/$base_name.keep
154 then
155 rm alt_objects/pack/$base_name.keep
156 else
157 touch alt_objects/pack/$base_name.keep
158 fi || return 1
159 done &&
160 git repack -a -d &&
161 test_no_missing_in_packs
164 test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
165 rm -f alt_objects/pack/*.keep &&
166 mv .git/objects/pack/* alt_objects/pack/ &&
167 coid=$(git rev-parse HEAD^{commit}) &&
168 git reset --hard HEAD^ &&
169 test_tick &&
170 git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
171 # The pack-objects call on the next line is equivalent to
172 # git repack -A -d without the call to prune-packed
173 git pack-objects --honor-pack-keep --non-empty --all --reflog \
174 --unpack-unreachable </dev/null pack &&
175 rm -f .git/objects/pack/* &&
176 mv pack-* .git/objects/pack/ &&
177 git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
178 ! grep "^$coid " packlist &&
179 echo >.git/objects/info/alternates &&
180 test_must_fail git show $coid
183 test_expect_success 'local packed unreachable obs that exist in alternate ODB are not loosened' '
184 echo $(pwd)/alt_objects >.git/objects/info/alternates &&
185 echo "$coid" | git pack-objects --non-empty --all --reflog pack &&
186 rm -f .git/objects/pack/* &&
187 mv pack-* .git/objects/pack/ &&
188 # The pack-objects call on the next line is equivalent to
189 # git repack -A -d without the call to prune-packed
190 git pack-objects --honor-pack-keep --non-empty --all --reflog \
191 --unpack-unreachable </dev/null pack &&
192 rm -f .git/objects/pack/* &&
193 mv pack-* .git/objects/pack/ &&
194 git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
195 ! grep "^$coid " &&
196 echo >.git/objects/info/alternates &&
197 test_must_fail git show $coid
200 test_expect_success 'objects made unreachable by grafts only are kept' '
201 test_tick &&
202 git commit --allow-empty -m "commit 4" &&
203 H0=$(git rev-parse HEAD) &&
204 H1=$(git rev-parse HEAD^) &&
205 H2=$(git rev-parse HEAD^^) &&
206 echo "$H0 $H2" >.git/info/grafts &&
207 git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
208 git repack -a -d &&
209 git cat-file -t $H1
212 test_expect_success 'repack --keep-pack' '
213 test_create_repo keep-pack &&
215 cd keep-pack &&
216 # avoid producing different packs due to delta/base choices
217 git config pack.window 0 &&
218 P1=$(commit_and_pack 1) &&
219 P2=$(commit_and_pack 2) &&
220 P3=$(commit_and_pack 3) &&
221 P4=$(commit_and_pack 4) &&
222 ls .git/objects/pack/*.pack >old-counts &&
223 test_line_count = 4 old-counts &&
224 git repack -a -d --keep-pack $P1 --keep-pack $P4 &&
225 ls .git/objects/pack/*.pack >new-counts &&
226 grep -q $P1 new-counts &&
227 grep -q $P4 new-counts &&
228 test_line_count = 3 new-counts &&
229 git fsck &&
231 P5=$(commit_and_pack --no-tag 5) &&
232 git reset --hard HEAD^ &&
233 git reflog expire --all --expire=all &&
234 rm -f ".git/objects/pack/${P5%.pack}.idx" &&
235 rm -f ".git/objects/info/commit-graph" &&
236 for from in $(find .git/objects/pack -type f -name "${P5%.pack}.*")
238 to="$(dirname "$from")/.tmp-1234-$(basename "$from")" &&
239 mv "$from" "$to" || return 1
240 done &&
242 # A .idx file without a .pack should not stop us from
243 # repacking what we can.
244 touch .git/objects/pack/pack-does-not-exist.idx &&
246 git repack --cruft -d --keep-pack $P1 --keep-pack $P4 &&
248 ls .git/objects/pack/*.pack >newer-counts &&
249 test_cmp new-counts newer-counts &&
250 git fsck
254 test_expect_success 'repacking fails when missing .pack actually means missing objects' '
255 test_create_repo idx-without-pack &&
257 cd idx-without-pack &&
259 # Avoid producing different packs due to delta/base choices
260 git config pack.window 0 &&
261 P1=$(commit_and_pack 1) &&
262 P2=$(commit_and_pack 2) &&
263 P3=$(commit_and_pack 3) &&
264 P4=$(commit_and_pack 4) &&
265 ls .git/objects/pack/*.pack >old-counts &&
266 test_line_count = 4 old-counts &&
268 # Remove one .pack file
269 rm .git/objects/pack/$P2 &&
271 ls .git/objects/pack/*.pack >before-pack-dir &&
273 test_must_fail git fsck &&
274 test_must_fail env GIT_COMMIT_GRAPH_PARANOIA=true git repack --cruft -d 2>err &&
275 grep "bad object" err &&
277 # Before failing, the repack did not modify the
278 # pack directory.
279 ls .git/objects/pack/*.pack >after-pack-dir &&
280 test_cmp before-pack-dir after-pack-dir
284 test_expect_success 'bitmaps are created by default in bare repos' '
285 git clone --bare .git bare.git &&
286 rm -f bare.git/objects/pack/*.bitmap &&
287 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
288 git -C bare.git repack -ad &&
289 bitmap=$(ls bare.git/objects/pack/*.bitmap) &&
290 test_path_is_file "$bitmap"
293 test_expect_success 'incremental repack does not complain' '
294 git -C bare.git repack -q 2>repack.err &&
295 test_must_be_empty repack.err
298 test_expect_success 'bitmaps can be disabled on bare repos' '
299 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
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_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
312 git -C bare.git repack -ad 2>stderr &&
313 test_must_be_empty stderr &&
314 find bare.git/objects/pack/ -type f -name "*.bitmap" >actual &&
315 test_must_be_empty actual
318 test_expect_success 'auto-bitmaps do not complain if unavailable' '
319 test_config -C bare.git pack.packSizeLimit 1M &&
320 blob=$(test-tool genrandom big $((1024*1024)) |
321 git -C bare.git hash-object -w --stdin) &&
322 git -C bare.git update-ref refs/tags/big $blob &&
323 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
324 git -C bare.git repack -ad 2>stderr &&
325 test_must_be_empty stderr &&
326 find bare.git/objects/pack -type f -name "*.bitmap" >actual &&
327 test_must_be_empty actual
330 test_expect_success 'repacking with a filter works' '
331 git -C bare.git repack -a -d &&
332 test_stdout_line_count = 1 ls bare.git/objects/pack/*.pack &&
333 git -C bare.git -c repack.writebitmaps=false repack -a -d --filter=blob:none &&
334 test_stdout_line_count = 2 ls bare.git/objects/pack/*.pack &&
335 commit_pack=$(test-tool -C bare.git find-pack -c 1 HEAD) &&
336 blob_pack=$(test-tool -C bare.git find-pack -c 1 HEAD:file1) &&
337 test "$commit_pack" != "$blob_pack" &&
338 tree_pack=$(test-tool -C bare.git find-pack -c 1 HEAD^{tree}) &&
339 test "$tree_pack" = "$commit_pack" &&
340 blob_pack2=$(test-tool -C bare.git find-pack -c 1 HEAD:file2) &&
341 test "$blob_pack2" = "$blob_pack"
344 test_expect_success '--filter fails with --write-bitmap-index' '
345 test_must_fail \
346 env GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
347 git -C bare.git repack -a -d --write-bitmap-index --filter=blob:none
350 test_expect_success 'repacking with two filters works' '
351 git init two-filters &&
353 cd two-filters &&
354 mkdir subdir &&
355 test_commit foo &&
356 test_commit subdir_bar subdir/bar &&
357 test_commit subdir_baz subdir/baz
358 ) &&
359 git clone --no-local --bare two-filters two-filters.git &&
361 cd two-filters.git &&
362 test_stdout_line_count = 1 ls objects/pack/*.pack &&
363 git -c repack.writebitmaps=false repack -a -d \
364 --filter=blob:none --filter=tree:1 &&
365 test_stdout_line_count = 2 ls objects/pack/*.pack &&
366 commit_pack=$(test-tool find-pack -c 1 HEAD) &&
367 blob_pack=$(test-tool find-pack -c 1 HEAD:foo.t) &&
368 root_tree_pack=$(test-tool find-pack -c 1 HEAD^{tree}) &&
369 subdir_tree_hash=$(git ls-tree --object-only HEAD -- subdir) &&
370 subdir_tree_pack=$(test-tool find-pack -c 1 "$subdir_tree_hash") &&
372 # Root tree and subdir tree are not in the same packfiles
373 test "$commit_pack" != "$blob_pack" &&
374 test "$commit_pack" = "$root_tree_pack" &&
375 test "$blob_pack" = "$subdir_tree_pack"
379 prepare_for_keep_packs () {
380 git init keep-packs &&
382 cd keep-packs &&
383 test_commit foo &&
384 test_commit bar
385 ) &&
386 git clone --no-local --bare keep-packs keep-packs.git &&
388 cd keep-packs.git &&
390 # Create two packs
391 # The first pack will contain all of the objects except one blob
392 git rev-list --objects --all >objs &&
393 grep -v "bar.t" objs | git pack-objects pack &&
394 # The second pack will contain the excluded object and be kept
395 packid=$(grep "bar.t" objs | git pack-objects pack) &&
396 >pack-$packid.keep &&
398 # Replace the existing pack with the 2 new ones
399 rm -f objects/pack/pack* &&
400 mv pack-* objects/pack/
404 test_expect_success '--filter works with .keep packs' '
405 prepare_for_keep_packs &&
407 cd keep-packs.git &&
409 foo_pack=$(test-tool find-pack -c 1 HEAD:foo.t) &&
410 bar_pack=$(test-tool find-pack -c 1 HEAD:bar.t) &&
411 head_pack=$(test-tool find-pack -c 1 HEAD) &&
413 test "$foo_pack" != "$bar_pack" &&
414 test "$foo_pack" = "$head_pack" &&
416 git -c repack.writebitmaps=false repack -a -d --filter=blob:none &&
418 foo_pack_1=$(test-tool find-pack -c 1 HEAD:foo.t) &&
419 bar_pack_1=$(test-tool find-pack -c 1 HEAD:bar.t) &&
420 head_pack_1=$(test-tool find-pack -c 1 HEAD) &&
422 # Object bar is still only in the old .keep pack
423 test "$foo_pack_1" != "$foo_pack" &&
424 test "$bar_pack_1" = "$bar_pack" &&
425 test "$head_pack_1" != "$head_pack" &&
427 test "$foo_pack_1" != "$bar_pack_1" &&
428 test "$foo_pack_1" != "$head_pack_1" &&
429 test "$bar_pack_1" != "$head_pack_1"
433 test_expect_success '--filter works with --pack-kept-objects and .keep packs' '
434 rm -rf keep-packs keep-packs.git &&
435 prepare_for_keep_packs &&
437 cd keep-packs.git &&
439 foo_pack=$(test-tool find-pack -c 1 HEAD:foo.t) &&
440 bar_pack=$(test-tool find-pack -c 1 HEAD:bar.t) &&
441 head_pack=$(test-tool find-pack -c 1 HEAD) &&
443 test "$foo_pack" != "$bar_pack" &&
444 test "$foo_pack" = "$head_pack" &&
446 git -c repack.writebitmaps=false repack -a -d --filter=blob:none \
447 --pack-kept-objects &&
449 foo_pack_1=$(test-tool find-pack -c 1 HEAD:foo.t) &&
450 test-tool find-pack -c 2 HEAD:bar.t >bar_pack_1 &&
451 head_pack_1=$(test-tool find-pack -c 1 HEAD) &&
453 test "$foo_pack_1" != "$foo_pack" &&
454 test "$foo_pack_1" != "$bar_pack" &&
455 test "$head_pack_1" != "$head_pack" &&
457 # Object bar is in both the old .keep pack and the new
458 # pack that contained the filtered out objects
459 grep "$bar_pack" bar_pack_1 &&
460 grep "$foo_pack_1" bar_pack_1 &&
461 test "$foo_pack_1" != "$head_pack_1"
465 test_expect_success '--filter-to stores filtered out objects' '
466 git -C bare.git repack -a -d &&
467 test_stdout_line_count = 1 ls bare.git/objects/pack/*.pack &&
469 git init --bare filtered.git &&
470 git -C bare.git -c repack.writebitmaps=false repack -a -d \
471 --filter=blob:none \
472 --filter-to=../filtered.git/objects/pack/pack &&
473 test_stdout_line_count = 1 ls bare.git/objects/pack/pack-*.pack &&
474 test_stdout_line_count = 1 ls filtered.git/objects/pack/pack-*.pack &&
476 commit_pack=$(test-tool -C bare.git find-pack -c 1 HEAD) &&
477 blob_pack=$(test-tool -C bare.git find-pack -c 0 HEAD:file1) &&
478 blob_hash=$(git -C bare.git rev-parse HEAD:file1) &&
479 test -n "$blob_hash" &&
480 blob_pack=$(test-tool -C filtered.git find-pack -c 1 $blob_hash) &&
482 echo $(pwd)/filtered.git/objects >bare.git/objects/info/alternates &&
483 blob_pack=$(test-tool -C bare.git find-pack -c 1 HEAD:file1) &&
484 blob_content=$(git -C bare.git show $blob_hash) &&
485 test "$blob_content" = "content1"
488 test_expect_success '--filter works with --max-pack-size' '
489 rm -rf filtered.git &&
490 git init --bare filtered.git &&
491 git init max-pack-size &&
493 cd max-pack-size &&
494 test_commit base &&
495 # two blobs which exceed the maximum pack size
496 test-tool genrandom foo 1048576 >foo &&
497 git hash-object -w foo &&
498 test-tool genrandom bar 1048576 >bar &&
499 git hash-object -w bar &&
500 git add foo bar &&
501 git commit -m "adding foo and bar"
502 ) &&
503 git clone --no-local --bare max-pack-size max-pack-size.git &&
505 cd max-pack-size.git &&
506 git -c repack.writebitmaps=false repack -a -d --filter=blob:none \
507 --max-pack-size=1M \
508 --filter-to=../filtered.git/objects/pack/pack &&
509 echo $(cd .. && pwd)/filtered.git/objects >objects/info/alternates &&
511 # Check that the 3 blobs are in different packfiles in filtered.git
512 test_stdout_line_count = 3 ls ../filtered.git/objects/pack/pack-*.pack &&
513 test_stdout_line_count = 1 ls objects/pack/pack-*.pack &&
514 foo_pack=$(test-tool find-pack -c 1 HEAD:foo) &&
515 bar_pack=$(test-tool find-pack -c 1 HEAD:bar) &&
516 base_pack=$(test-tool find-pack -c 1 HEAD:base.t) &&
517 test "$foo_pack" != "$bar_pack" &&
518 test "$foo_pack" != "$base_pack" &&
519 test "$bar_pack" != "$base_pack" &&
520 for pack in "$foo_pack" "$bar_pack" "$base_pack"
522 case "$foo_pack" in */filtered.git/objects/pack/*) true ;; *) return 1 ;; esac
523 done
527 objdir=.git/objects
528 midx=$objdir/pack/multi-pack-index
530 test_expect_success 'setup for --write-midx tests' '
531 git init midx &&
533 cd midx &&
534 git config core.multiPackIndex true &&
536 test_commit base
540 test_expect_success '--write-midx unchanged' '
542 cd midx &&
543 GIT_TEST_MULTI_PACK_INDEX=0 git repack &&
544 test_path_is_missing $midx &&
545 test_path_is_missing $midx-*.bitmap &&
547 GIT_TEST_MULTI_PACK_INDEX=0 git repack --write-midx &&
549 test_path_is_file $midx &&
550 test_path_is_missing $midx-*.bitmap &&
551 test_midx_consistent $objdir
555 test_expect_success '--write-midx with a new pack' '
557 cd midx &&
558 test_commit loose &&
560 GIT_TEST_MULTI_PACK_INDEX=0 git repack --write-midx &&
562 test_path_is_file $midx &&
563 test_path_is_missing $midx-*.bitmap &&
564 test_midx_consistent $objdir
568 test_expect_success '--write-midx with -b' '
570 cd midx &&
571 GIT_TEST_MULTI_PACK_INDEX=0 git repack -mb &&
573 test_path_is_file $midx &&
574 test_path_is_file $midx-*.bitmap &&
575 test_midx_consistent $objdir
579 test_expect_success '--write-midx with -d' '
581 cd midx &&
582 test_commit repack &&
584 GIT_TEST_MULTI_PACK_INDEX=0 git repack -Ad --write-midx &&
586 test_path_is_file $midx &&
587 test_path_is_missing $midx-*.bitmap &&
588 test_midx_consistent $objdir
592 test_expect_success 'cleans up MIDX when appropriate' '
594 cd midx &&
596 test_commit repack-2 &&
597 GIT_TEST_MULTI_PACK_INDEX=0 git repack -Adb --write-midx &&
599 checksum=$(midx_checksum $objdir) &&
600 test_path_is_file $midx &&
601 test_path_is_file $midx-$checksum.bitmap &&
603 test_commit repack-3 &&
604 GIT_TEST_MULTI_PACK_INDEX=0 git repack -Adb --write-midx &&
606 test_path_is_file $midx &&
607 test_path_is_missing $midx-$checksum.bitmap &&
608 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
610 test_commit repack-4 &&
611 GIT_TEST_MULTI_PACK_INDEX=0 git repack -Adb &&
613 find $objdir/pack -type f -name "multi-pack-index*" >files &&
614 test_must_be_empty files
618 test_expect_success '--write-midx with preferred bitmap tips' '
619 git init midx-preferred-tips &&
620 test_when_finished "rm -fr midx-preferred-tips" &&
622 cd midx-preferred-tips &&
624 test_commit_bulk --message="%s" 103 &&
626 git log --format="%H" >commits.raw &&
627 sort <commits.raw >commits &&
629 git log --format="create refs/tags/%s/%s %H" HEAD >refs &&
630 git update-ref --stdin <refs &&
632 git repack --write-midx --write-bitmap-index &&
633 test_path_is_file $midx &&
634 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
636 test-tool bitmap list-commits | sort >bitmaps &&
637 comm -13 bitmaps commits >before &&
638 test_line_count = 1 before &&
640 rm -fr $midx-$(midx_checksum $objdir).bitmap &&
641 rm -fr $midx &&
643 # instead of constructing the snapshot ourselves (c.f., the test
644 # "write a bitmap with --refs-snapshot (preferred tips)" in
645 # t5326), mark the missing commit as preferred by adding it to
646 # the pack.preferBitmapTips configuration.
647 git for-each-ref --format="%(refname:rstrip=1)" \
648 --points-at="$(cat before)" >missing &&
649 git config pack.preferBitmapTips "$(cat missing)" &&
650 git repack --write-midx --write-bitmap-index &&
652 test-tool bitmap list-commits | sort >bitmaps &&
653 comm -13 bitmaps commits >after &&
655 ! test_cmp before after
659 # The first argument is expected to be a filename
660 # and that file should contain the name of a .idx
661 # file. Send the list of objects in that .idx file
662 # into stdout.
663 get_sorted_objects_from_pack () {
664 git show-index <$(cat "$1") >raw &&
665 cut -d" " -f2 raw
668 test_expect_success '--write-midx -b packs non-kept objects' '
669 git init repo &&
670 test_when_finished "rm -fr repo" &&
672 cd repo &&
674 # Create a kept pack-file
675 test_commit base &&
676 git repack -ad &&
677 find $objdir/pack -name "*.idx" >before &&
678 test_line_count = 1 before &&
679 before_name=$(cat before) &&
680 >${before_name%.idx}.keep &&
682 # Create a non-kept pack-file
683 test_commit other &&
684 git repack &&
686 # Create loose objects
687 test_commit loose &&
689 # Repack everything
690 git repack --write-midx -a -b -d &&
692 # There should be two pack-files now, the
693 # old, kept pack and the new, non-kept pack.
694 find $objdir/pack -name "*.idx" | sort >after &&
695 test_line_count = 2 after &&
696 find $objdir/pack -name "*.keep" >kept &&
697 kept_name=$(cat kept) &&
698 echo ${kept_name%.keep}.idx >kept-idx &&
699 test_cmp before kept-idx &&
701 # Get object list from the kept pack.
702 get_sorted_objects_from_pack before >old.objects &&
704 # Get object list from the one non-kept pack-file
705 comm -13 before after >new-pack &&
706 test_line_count = 1 new-pack &&
707 get_sorted_objects_from_pack new-pack >new.objects &&
709 # None of the objects in the new pack should
710 # exist within the kept pack.
711 comm -12 old.objects new.objects >shared.objects &&
712 test_must_be_empty shared.objects
716 test_expect_success '--write-midx removes stale pack-based bitmaps' '
717 rm -fr repo &&
718 git init repo &&
719 test_when_finished "rm -fr repo" &&
721 cd repo &&
722 test_commit base &&
723 GIT_TEST_MULTI_PACK_INDEX=0 git repack -Ab &&
725 pack_bitmap=$(ls $objdir/pack/pack-*.bitmap) &&
726 test_path_is_file "$pack_bitmap" &&
728 test_commit tip &&
729 GIT_TEST_MULTI_PACK_INDEX=0 git repack -bm &&
731 test_path_is_file $midx &&
732 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
733 test_path_is_missing $pack_bitmap
737 test_expect_success '--write-midx with --pack-kept-objects' '
738 git init repo &&
739 test_when_finished "rm -fr repo" &&
741 cd repo &&
743 test_commit one &&
744 test_commit two &&
746 one="$(echo "one" | git pack-objects --revs $objdir/pack/pack)" &&
747 two="$(echo "one..two" | git pack-objects --revs $objdir/pack/pack)" &&
749 keep="$objdir/pack/pack-$one.keep" &&
750 touch "$keep" &&
752 git repack --write-midx --write-bitmap-index --geometric=2 -d \
753 --pack-kept-objects &&
755 test_path_is_file $keep &&
756 test_path_is_file $midx &&
757 test_path_is_file $midx-$(midx_checksum $objdir).bitmap
761 test_expect_success TTY '--quiet disables progress' '
762 test_terminal env GIT_PROGRESS_DELAY=0 \
763 git -C midx repack -ad --quiet --write-midx 2>stderr &&
764 test_must_be_empty stderr
767 test_expect_success 'clean up .tmp-* packs on error' '
768 test_must_fail ok=sigpipe git \
769 -c repack.cruftwindow=bogus \
770 repack -ad --cruft &&
771 find $objdir/pack -name '.tmp-*' >tmpfiles &&
772 test_must_be_empty tmpfiles
775 test_expect_success 'repack -ad cleans up old .tmp-* packs' '
776 git rev-parse HEAD >input &&
777 git pack-objects $objdir/pack/.tmp-1234 <input &&
778 git repack -ad &&
779 find $objdir/pack -name '.tmp-*' >tmpfiles &&
780 test_must_be_empty tmpfiles
783 test_expect_success 'setup for update-server-info' '
784 git init update-server-info &&
785 test_commit -C update-server-info message
788 test_server_info_present () {
789 test_path_is_file update-server-info/.git/objects/info/packs &&
790 test_path_is_file update-server-info/.git/info/refs
793 test_server_info_missing () {
794 test_path_is_missing update-server-info/.git/objects/info/packs &&
795 test_path_is_missing update-server-info/.git/info/refs
798 test_server_info_cleanup () {
799 rm -f update-server-info/.git/objects/info/packs update-server-info/.git/info/refs &&
800 test_server_info_missing
803 test_expect_success 'updates server info by default' '
804 test_server_info_cleanup &&
805 git -C update-server-info repack &&
806 test_server_info_present
809 test_expect_success '-n skips updating server info' '
810 test_server_info_cleanup &&
811 git -C update-server-info repack -n &&
812 test_server_info_missing
815 test_expect_success 'repack.updateServerInfo=true updates server info' '
816 test_server_info_cleanup &&
817 git -C update-server-info -c repack.updateServerInfo=true repack &&
818 test_server_info_present
821 test_expect_success 'repack.updateServerInfo=false skips updating server info' '
822 test_server_info_cleanup &&
823 git -C update-server-info -c repack.updateServerInfo=false repack &&
824 test_server_info_missing
827 test_expect_success '-n overrides repack.updateServerInfo=true' '
828 test_server_info_cleanup &&
829 git -C update-server-info -c repack.updateServerInfo=true repack -n &&
830 test_server_info_missing
833 test_done