mktree: do not check type of remote objects
[git/debian.git] / t / t7703-repack-geometric.sh
blobbdbbcbf1eca88fef1c2dcd6632d880d3848c842d
1 #!/bin/sh
3 test_description='git repack --geometric works correctly'
5 . ./test-lib.sh
7 GIT_TEST_MULTI_PACK_INDEX=0
9 objdir=.git/objects
10 midx=$objdir/pack/multi-pack-index
12 test_expect_success '--geometric with no packs' '
13 git init geometric &&
14 test_when_finished "rm -fr geometric" &&
16 cd geometric &&
18 git repack --write-midx --geometric 2 >out &&
19 test_i18ngrep "Nothing new to pack" out
23 test_expect_success '--geometric with one pack' '
24 git init geometric &&
25 test_when_finished "rm -fr geometric" &&
27 cd geometric &&
29 test_commit "base" &&
30 git repack -d &&
32 git repack --geometric 2 >out &&
34 test_i18ngrep "Nothing new to pack" out
38 test_expect_success '--geometric with an intact progression' '
39 git init geometric &&
40 test_when_finished "rm -fr geometric" &&
42 cd geometric &&
44 # These packs already form a geometric progression.
45 test_commit_bulk --start=1 1 && # 3 objects
46 test_commit_bulk --start=2 2 && # 6 objects
47 test_commit_bulk --start=4 4 && # 12 objects
49 find $objdir/pack -name "*.pack" | sort >expect &&
50 git repack --geometric 2 -d &&
51 find $objdir/pack -name "*.pack" | sort >actual &&
53 test_cmp expect actual
57 test_expect_success '--geometric with loose objects' '
58 git init geometric &&
59 test_when_finished "rm -fr geometric" &&
61 cd geometric &&
63 # These packs already form a geometric progression.
64 test_commit_bulk --start=1 1 && # 3 objects
65 test_commit_bulk --start=2 2 && # 6 objects
66 # The loose objects are packed together, breaking the
67 # progression.
68 test_commit loose && # 3 objects
70 find $objdir/pack -name "*.pack" | sort >before &&
71 git repack --geometric 2 -d &&
72 find $objdir/pack -name "*.pack" | sort >after &&
74 comm -13 before after >new &&
75 comm -23 before after >removed &&
77 test_line_count = 1 new &&
78 test_must_be_empty removed &&
80 git repack --geometric 2 -d &&
81 find $objdir/pack -name "*.pack" | sort >after &&
83 # The progression (3, 3, 6) is combined into one new pack.
84 test_line_count = 1 after
88 test_expect_success '--geometric with small-pack rollup' '
89 git init geometric &&
90 test_when_finished "rm -fr geometric" &&
92 cd geometric &&
94 test_commit_bulk --start=1 1 && # 3 objects
95 test_commit_bulk --start=2 1 && # 3 objects
96 find $objdir/pack -name "*.pack" | sort >small &&
97 test_commit_bulk --start=3 4 && # 12 objects
98 test_commit_bulk --start=7 8 && # 24 objects
99 find $objdir/pack -name "*.pack" | sort >before &&
101 git repack --geometric 2 -d &&
103 # Three packs in total; two of the existing large ones, and one
104 # new one.
105 find $objdir/pack -name "*.pack" | sort >after &&
106 test_line_count = 3 after &&
107 comm -3 small before | tr -d "\t" >large &&
108 grep -qFf large after
112 test_expect_success '--geometric with small- and large-pack rollup' '
113 git init geometric &&
114 test_when_finished "rm -fr geometric" &&
116 cd geometric &&
118 # size(small1) + size(small2) > size(medium) / 2
119 test_commit_bulk --start=1 1 && # 3 objects
120 test_commit_bulk --start=2 1 && # 3 objects
121 test_commit_bulk --start=2 3 && # 7 objects
122 test_commit_bulk --start=6 9 && # 27 objects &&
124 find $objdir/pack -name "*.pack" | sort >before &&
126 git repack --geometric 2 -d &&
128 find $objdir/pack -name "*.pack" | sort >after &&
129 comm -12 before after >untouched &&
131 # Two packs in total; the largest pack from before running "git
132 # repack", and one new one.
133 test_line_count = 1 untouched &&
134 test_line_count = 2 after
138 test_expect_success '--geometric ignores kept packs' '
139 git init geometric &&
140 test_when_finished "rm -fr geometric" &&
142 cd geometric &&
144 test_commit kept && # 3 objects
145 test_commit pack && # 3 objects
147 KEPT=$(git pack-objects --revs $objdir/pack/pack <<-EOF
148 refs/tags/kept
150 ) &&
151 PACK=$(git pack-objects --revs $objdir/pack/pack <<-EOF
152 refs/tags/pack
153 ^refs/tags/kept
155 ) &&
157 # neither pack contains more than twice the number of objects in
158 # the other, so they should be combined. but, marking one as
159 # .kept on disk will "freeze" it, so the pack structure should
160 # remain unchanged.
161 touch $objdir/pack/pack-$KEPT.keep &&
163 find $objdir/pack -name "*.pack" | sort >before &&
164 git repack --geometric 2 -d &&
165 find $objdir/pack -name "*.pack" | sort >after &&
167 # both packs should still exist
168 test_path_is_file $objdir/pack/pack-$KEPT.pack &&
169 test_path_is_file $objdir/pack/pack-$PACK.pack &&
171 # and no new packs should be created
172 test_cmp before after &&
174 # Passing --pack-kept-objects causes packs with a .keep file to
175 # be repacked, too.
176 git repack --geometric 2 -d --pack-kept-objects &&
178 find $objdir/pack -name "*.pack" >after &&
179 test_line_count = 1 after
183 test_expect_success '--geometric chooses largest MIDX preferred pack' '
184 git init geometric &&
185 test_when_finished "rm -fr geometric" &&
187 cd geometric &&
189 # These packs already form a geometric progression.
190 test_commit_bulk --start=1 1 && # 3 objects
191 test_commit_bulk --start=2 2 && # 6 objects
192 ls $objdir/pack/pack-*.idx >before &&
193 test_commit_bulk --start=4 4 && # 12 objects
194 ls $objdir/pack/pack-*.idx >after &&
196 git repack --geometric 2 -dbm &&
198 comm -3 before after | xargs -n 1 basename >expect &&
199 test-tool read-midx --preferred-pack $objdir >actual &&
201 test_cmp expect actual
205 test_done