t7700: split cruft-related tests to t7704
A small handful of the tests in t7700 (the main script for testing functionality of 'git repack') are specifically related to cruft pack operations. Prepare for adding new cruft pack-related tests by moving the existing set into a new test script. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Taylor Blau committed
Oct 2, 2023 at 20:44 UTC
78de1c6c327b00ec9ed97c478e5f9e56d03c1db8
2 files changed
+130
-121
t/t7700-repack.sh
-121
@@ -633,125 +633,4 @@ test_expect_success '-n overrides repack.updateServerInfo=true' '
633
test_server_info_missing
634
'
635
636
-test_expect_success '--expire-to stores pruned objects (now)' '
637
- git init expire-to-now &&
638
- (
639
- cd expire-to-now &&
640
-
641
- git branch -M main &&
642
-
643
- test_commit base &&
644
-
645
- git checkout -b cruft &&
646
- test_commit --no-tag cruft &&
647
-
648
- git rev-list --objects --no-object-names main..cruft >moved.raw &&
649
- sort moved.raw >moved.want &&
650
-
651
- git rev-list --all --objects --no-object-names >expect.raw &&
652
- sort expect.raw >expect &&
653
-
654
- git checkout main &&
655
- git branch -D cruft &&
656
- git reflog expire --all --expire=all &&
657
-
658
- git init --bare expired.git &&
659
- git repack -d \
660
- --cruft --cruft-expiration="now" \
661
- --expire-to="expired.git/objects/pack/pack" &&
662
-
663
- expired="$(ls expired.git/objects/pack/pack-*.idx)" &&
664
- test_path_is_file "${expired%.idx}.mtimes" &&
665
-
666
- # Since the `--cruft-expiration` is "now", the effective
667
- # behavior is to move _all_ unreachable objects out to
668
- # the location in `--expire-to`.
669
- git show-index <$expired >expired.raw &&
670
- cut -d" " -f2 expired.raw | sort >expired.objects &&
671
- git rev-list --all --objects --no-object-names \
672
- >remaining.objects &&
673
-
674
- # ...in other words, the combined contents of this
675
- # repository and expired.git should be the same as the
676
- # set of objects we started with.
677
- cat expired.objects remaining.objects | sort >actual &&
678
- test_cmp expect actual &&
679
-
680
- # The "moved" objects (i.e., those in expired.git)
681
- # should be the same as the cruft objects which were
682
- # expired in the previous step.
683
- test_cmp moved.want expired.objects
684
- )
685
-'
686
-
687
-test_expect_success '--expire-to stores pruned objects (5.minutes.ago)' '
688
- git init expire-to-5.minutes.ago &&
689
- (
690
- cd expire-to-5.minutes.ago &&
691
-
692
- git branch -M main &&
693
-
694
- test_commit base &&
695
-
696
- # Create two classes of unreachable objects, one which
697
- # is older than 5 minutes (stale), and another which is
698
- # newer (recent).
699
- for kind in stale recent
700
- do
701
- git checkout -b $kind main &&
702
- test_commit --no-tag $kind || return 1
703
- done &&
704
-
705
- git rev-list --objects --no-object-names main..stale >in &&
706
- stale="$(git pack-objects $objdir/pack/pack <in)" &&
707
- mtime="$(test-tool chmtime --get =-600 $objdir/pack/pack-$stale.pack)" &&
708
-
709
- # expect holds the set of objects we expect to find in
710
- # this repository after repacking
711
- git rev-list --objects --no-object-names recent >expect.raw &&
712
- sort expect.raw >expect &&
713
-
714
- # moved.want holds the set of objects we expect to find
715
- # in expired.git
716
- git rev-list --objects --no-object-names main..stale >out &&
717
- sort out >moved.want &&
718
-
719
- git checkout main &&
720
- git branch -D stale recent &&
721
- git reflog expire --all --expire=all &&
722
- git prune-packed &&
723
-
724
- git init --bare expired.git &&
725
- git repack -d \
726
- --cruft --cruft-expiration=5.minutes.ago \
727
- --expire-to="expired.git/objects/pack/pack" &&
728
-
729
- # Some of the remaining objects in this repository are
730
- # unreachable, so use `cat-file --batch-all-objects`
731
- # instead of `rev-list` to get their names
732
- git cat-file --batch-all-objects --batch-check="%(objectname)" \
733
- >remaining.objects &&
734
- sort remaining.objects >actual &&
735
- test_cmp expect actual &&
736
-
737
- (
738
- cd expired.git &&
739
-
740
- expired="$(ls objects/pack/pack-*.mtimes)" &&
741
- test-tool pack-mtimes $(basename $expired) >out &&
742
- cut -d" " -f1 out | sort >../moved.got &&
743
-
744
- # Ensure that there are as many objects with the
745
- # expected mtime as were moved to expired.git.
746
- #
747
- # In other words, ensure that the recorded
748
- # mtimes of any moved objects was written
749
- # correctly.
750
- grep " $mtime$" out >matching &&
751
- test_line_count = $(wc -l <../moved.want) matching
752
- ) &&
753
- test_cmp moved.want moved.got
754
- )
755
-'
756
-
636
test_done
t/t7704-repack-cruft.sh
new
+130
@@ -0,0 +1,130 @@
1
+#!/bin/sh
2
+
3
+test_description='git repack works correctly'
4
+
5
+. ./test-lib.sh
6
+
7
+objdir=.git/objects
8
+
9
+test_expect_success '--expire-to stores pruned objects (now)' '
10
+ git init expire-to-now &&
11
+ (
12
+ cd expire-to-now &&
13
+
14
+ git branch -M main &&
15
+
16
+ test_commit base &&
17
+
18
+ git checkout -b cruft &&
19
+ test_commit --no-tag cruft &&
20
+
21
+ git rev-list --objects --no-object-names main..cruft >moved.raw &&
22
+ sort moved.raw >moved.want &&
23
+
24
+ git rev-list --all --objects --no-object-names >expect.raw &&
25
+ sort expect.raw >expect &&
26
+
27
+ git checkout main &&
28
+ git branch -D cruft &&
29
+ git reflog expire --all --expire=all &&
30
+
31
+ git init --bare expired.git &&
32
+ git repack -d \
33
+ --cruft --cruft-expiration="now" \
34
+ --expire-to="expired.git/objects/pack/pack" &&
35
+
36
+ expired="$(ls expired.git/objects/pack/pack-*.idx)" &&
37
+ test_path_is_file "${expired%.idx}.mtimes" &&
38
+
39
+ # Since the `--cruft-expiration` is "now", the effective
40
+ # behavior is to move _all_ unreachable objects out to
41
+ # the location in `--expire-to`.
42
+ git show-index <$expired >expired.raw &&
43
+ cut -d" " -f2 expired.raw | sort >expired.objects &&
44
+ git rev-list --all --objects --no-object-names \
45
+ >remaining.objects &&
46
+
47
+ # ...in other words, the combined contents of this
48
+ # repository and expired.git should be the same as the
49
+ # set of objects we started with.
50
+ cat expired.objects remaining.objects | sort >actual &&
51
+ test_cmp expect actual &&
52
+
53
+ # The "moved" objects (i.e., those in expired.git)
54
+ # should be the same as the cruft objects which were
55
+ # expired in the previous step.
56
+ test_cmp moved.want expired.objects
57
+ )
58
+'
59
+
60
+test_expect_success '--expire-to stores pruned objects (5.minutes.ago)' '
61
+ git init expire-to-5.minutes.ago &&
62
+ (
63
+ cd expire-to-5.minutes.ago &&
64
+
65
+ git branch -M main &&
66
+
67
+ test_commit base &&
68
+
69
+ # Create two classes of unreachable objects, one which
70
+ # is older than 5 minutes (stale), and another which is
71
+ # newer (recent).
72
+ for kind in stale recent
73
+ do
74
+ git checkout -b $kind main &&
75
+ test_commit --no-tag $kind || return 1
76
+ done &&
77
+
78
+ git rev-list --objects --no-object-names main..stale >in &&
79
+ stale="$(git pack-objects $objdir/pack/pack <in)" &&
80
+ mtime="$(test-tool chmtime --get =-600 $objdir/pack/pack-$stale.pack)" &&
81
+
82
+ # expect holds the set of objects we expect to find in
83
+ # this repository after repacking
84
+ git rev-list --objects --no-object-names recent >expect.raw &&
85
+ sort expect.raw >expect &&
86
+
87
+ # moved.want holds the set of objects we expect to find
88
+ # in expired.git
89
+ git rev-list --objects --no-object-names main..stale >out &&
90
+ sort out >moved.want &&
91
+
92
+ git checkout main &&
93
+ git branch -D stale recent &&
94
+ git reflog expire --all --expire=all &&
95
+ git prune-packed &&
96
+
97
+ git init --bare expired.git &&
98
+ git repack -d \
99
+ --cruft --cruft-expiration=5.minutes.ago \
100
+ --expire-to="expired.git/objects/pack/pack" &&
101
+
102
+ # Some of the remaining objects in this repository are
103
+ # unreachable, so use `cat-file --batch-all-objects`
104
+ # instead of `rev-list` to get their names
105
+ git cat-file --batch-all-objects --batch-check="%(objectname)" \
106
+ >remaining.objects &&
107
+ sort remaining.objects >actual &&
108
+ test_cmp expect actual &&
109
+
110
+ (
111
+ cd expired.git &&
112
+
113
+ expired="$(ls objects/pack/pack-*.mtimes)" &&
114
+ test-tool pack-mtimes $(basename $expired) >out &&
115
+ cut -d" " -f1 out | sort >../moved.got &&
116
+
117
+ # Ensure that there are as many objects with the
118
+ # expected mtime as were moved to expired.git.
119
+ #
120
+ # In other words, ensure that the recorded
121
+ # mtimes of any moved objects was written
122
+ # correctly.
123
+ grep " $mtime$" out >matching &&
124
+ test_line_count = $(wc -l <../moved.want) matching
125
+ ) &&
126
+ test_cmp moved.want moved.got
127
+ )
128
+'
129
+
130
+test_done