573
)
574
'
575
576
-test_expect_success 'cruft repack ignores --max-pack-size' '
576
+write_blob () {
577
+ test-tool genrandom "$@" >in &&
578
+ git hash-object -w -t blob in
579
+}
580
+
581
+find_pack () {
582
+ for idx in $(ls $packdir/pack-*.idx)
583
+ do
584
+ git show-index <$idx >out &&
585
+ if grep -q "$1" out
586
+ then
587
+ echo $idx
588
+ fi || return 1
589
+ done
590
+}
591
+
592
+test_expect_success 'cruft repack with --max-pack-size' '
593
git init max-pack-size &&
594
(
595
cd max-pack-size &&
596
test_commit base &&
597
+
598
# two cruft objects which exceed the maximum pack size
582
- test-tool genrandom foo 1048576 | git hash-object --stdin -w &&
583
- test-tool genrandom bar 1048576 | git hash-object --stdin -w &&
599
+ foo=$(write_blob foo 1048576) &&
600
+ bar=$(write_blob bar 1048576) &&
601
+ test-tool chmtime --get -1000 \
602
+ "$objdir/$(test_oid_to_path $foo)" >foo.mtime &&
603
+ test-tool chmtime --get -2000 \
604
+ "$objdir/$(test_oid_to_path $bar)" >bar.mtime &&
605
git repack --cruft --max-pack-size=1M &&
606
find $packdir -name "*.mtimes" >cruft &&
586
- test_line_count = 1 cruft &&
587
- test-tool pack-mtimes "$(basename "$(cat cruft)")" >objects &&
588
- test_line_count = 2 objects
607
+ test_line_count = 2 cruft &&
608
+
609
+ foo_mtimes="$(basename $(find_pack $foo) .idx).mtimes" &&
610
+ bar_mtimes="$(basename $(find_pack $bar) .idx).mtimes" &&
611
+ test-tool pack-mtimes $foo_mtimes >foo.actual &&
612
+ test-tool pack-mtimes $bar_mtimes >bar.actual &&
613
+
614
+ echo "$foo $(cat foo.mtime)" >foo.expect &&
615
+ echo "$bar $(cat bar.mtime)" >bar.expect &&
616
+
617
+ test_cmp foo.expect foo.actual &&
618
+ test_cmp bar.expect bar.actual &&
619
+ test "$foo_mtimes" != "$bar_mtimes"
620
)
621
'
622
592
-test_expect_success 'cruft repack ignores pack.packSizeLimit' '
623
+test_expect_success 'cruft repack with pack.packSizeLimit' '
624
(
625
cd max-pack-size &&
626
# repack everything back together to remove the existing cruft
630
# ensure the same post condition is met when --max-pack-size
631
# would otherwise be inferred from the configuration
632
find $packdir -name "*.mtimes" >cruft &&
602
- test_line_count = 1 cruft &&
603
- test-tool pack-mtimes "$(basename "$(cat cruft)")" >objects &&
604
- test_line_count = 2 objects
633
+ test_line_count = 2 cruft &&
634
+ for pack in $(cat cruft)
635
+ do
636
+ test-tool pack-mtimes "$(basename $pack)" >objects &&
637
+ test_line_count = 1 objects || return 1
638
+ done
639
)
640
'
641