3 test_description
='git repack works correctly'
6 .
"${TEST_DIRECTORY}/lib-bitmap.sh"
7 .
"${TEST_DIRECTORY}/lib-midx.sh"
10 test_commit
"$@" 1>&2 &&
11 incrpackid
=$
(git pack-objects
--all --unpacked --incremental .git
/objects
/pack
/pack
</dev
/null
) &&
12 echo pack-
${incrpackid}.pack
15 test_no_missing_in_packs
() {
16 myidx
=$
(ls -1 .git
/objects
/pack
/*.idx
) &&
17 test_path_is_file
"$myidx" &&
18 git verify-pack
-v alt_objects
/pack
/*.idx
>orig.raw
&&
19 sed -n -e "s/^\($OID_REGEX\).*/\1/p" orig.raw |
sort >orig
&&
20 git verify-pack
-v $myidx >dest.raw
&&
21 cut
-d" " -f1 dest.raw |
sort >dest
&&
22 comm -23 orig dest
>missing
&&
23 test_must_be_empty missing
26 # we expect $packid and $oid to be defined
27 test_has_duplicate_object
() {
28 want_duplicate_object
="$1"
29 found_duplicate_object
=false
30 for p
in .git
/objects
/pack
/*.idx
33 test "pack-$packid.idx" = "$idx" && continue
34 git verify-pack
-v $p >packlist ||
return $?
35 if grep "^$oid" packlist
37 found_duplicate_object
=true
38 echo "DUPLICATE OBJECT FOUND"
42 test "$want_duplicate_object" = "$found_duplicate_object"
45 test_expect_success
'objects in packs marked .keep are not repacked' '
46 echo content1 >file1 &&
47 echo content2 >file2 &&
50 git commit -m initial_commit &&
52 # The first pack will contain all of the objects except one
53 git rev-list --objects --all >objs &&
54 grep -v file2 objs | git pack-objects pack &&
55 # The second pack will contain the excluded object
56 packid=$(grep file2 objs | git pack-objects pack) &&
58 git verify-pack -v pack-$packid.idx >packlist &&
59 oid=$(head -n 1 packlist | sed -e "s/^\($OID_REGEX\).*/\1/") &&
60 mv pack-* .git/objects/pack/ &&
61 git repack -A -d -l &&
63 test_has_duplicate_object false
66 test_expect_success
'writing bitmaps via command-line can duplicate .keep objects' '
67 # build on $oid, $packid, and .keep state from previous
68 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 git repack -Adbl &&
69 test_has_duplicate_object true
72 test_expect_success
'writing bitmaps via config can duplicate .keep objects' '
73 # build on $oid, $packid, and .keep state from previous
74 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
75 git -c repack.writebitmaps=true repack -Adl &&
76 test_has_duplicate_object true
79 test_expect_success
'loose objects in alternate ODB are not repacked' '
81 echo $(pwd)/alt_objects >.git/objects/info/alternates &&
82 echo content3 >file3 &&
83 oid=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
86 git commit -m commit_file3 &&
87 git repack -a -d -l &&
89 test_has_duplicate_object false
92 test_expect_success
'packed obs in alt ODB are repacked even when local repo is packless' '
93 mkdir alt_objects/pack &&
94 mv .git/objects/pack/* alt_objects/pack &&
96 test_no_missing_in_packs
99 test_expect_success
'packed obs in alt ODB are repacked when local repo has packs' '
100 rm -f .git/objects/pack/* &&
101 echo new_content >>file1 &&
104 git commit -m more_content &&
107 test_no_missing_in_packs
110 test_expect_success
'packed obs in alternate ODB kept pack are repacked' '
111 # swap the .keep so the commit object is in the pack with .keep
112 for p in alt_objects/pack/*.pack
114 base_name=$(basename $p .pack) &&
115 if test_path_is_file alt_objects/pack/$base_name.keep
117 rm alt_objects/pack/$base_name.keep
119 touch alt_objects/pack/$base_name.keep
123 test_no_missing_in_packs
126 test_expect_success
'packed unreachable obs in alternate ODB are not loosened' '
127 rm -f alt_objects/pack/*.keep &&
128 mv .git/objects/pack/* alt_objects/pack/ &&
129 coid=$(git rev-parse HEAD^{commit}) &&
130 git reset --hard HEAD^ &&
132 git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
133 # The pack-objects call on the next line is equivalent to
134 # git repack -A -d without the call to prune-packed
135 git pack-objects --honor-pack-keep --non-empty --all --reflog \
136 --unpack-unreachable </dev/null pack &&
137 rm -f .git/objects/pack/* &&
138 mv pack-* .git/objects/pack/ &&
139 git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
140 ! grep "^$coid " packlist &&
141 echo >.git/objects/info/alternates &&
142 test_must_fail git show $coid
145 test_expect_success
'local packed unreachable obs that exist in alternate ODB are not loosened' '
146 echo $(pwd)/alt_objects >.git/objects/info/alternates &&
147 echo "$coid" | git pack-objects --non-empty --all --reflog pack &&
148 rm -f .git/objects/pack/* &&
149 mv pack-* .git/objects/pack/ &&
150 # The pack-objects call on the next line is equivalent to
151 # git repack -A -d without the call to prune-packed
152 git pack-objects --honor-pack-keep --non-empty --all --reflog \
153 --unpack-unreachable </dev/null pack &&
154 rm -f .git/objects/pack/* &&
155 mv pack-* .git/objects/pack/ &&
156 git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
158 echo >.git/objects/info/alternates &&
159 test_must_fail git show $coid
162 test_expect_success
'objects made unreachable by grafts only are kept' '
164 git commit --allow-empty -m "commit 4" &&
165 H0=$(git rev-parse HEAD) &&
166 H1=$(git rev-parse HEAD^) &&
167 H2=$(git rev-parse HEAD^^) &&
168 echo "$H0 $H2" >.git/info/grafts &&
169 git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
174 test_expect_success
'repack --keep-pack' '
175 test_create_repo keep-pack &&
178 P1=$(commit_and_pack 1) &&
179 P2=$(commit_and_pack 2) &&
180 P3=$(commit_and_pack 3) &&
181 P4=$(commit_and_pack 4) &&
182 ls .git/objects/pack/*.pack >old-counts &&
183 test_line_count = 4 old-counts &&
184 git repack -a -d --keep-pack $P1 --keep-pack $P4 &&
185 ls .git/objects/pack/*.pack >new-counts &&
186 grep -q $P1 new-counts &&
187 grep -q $P4 new-counts &&
188 test_line_count = 3 new-counts &&
193 test_expect_success
'bitmaps are created by default in bare repos' '
194 git clone --bare .git bare.git &&
195 rm -f bare.git/objects/pack/*.bitmap &&
196 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
197 git -C bare.git repack -ad &&
198 bitmap=$(ls bare.git/objects/pack/*.bitmap) &&
199 test_path_is_file "$bitmap"
202 test_expect_success
'incremental repack does not complain' '
203 git -C bare.git repack -q 2>repack.err &&
204 test_must_be_empty repack.err
207 test_expect_success
'bitmaps can be disabled on bare repos' '
208 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
209 git -c repack.writeBitmaps=false -C bare.git repack -ad &&
210 bitmap=$(ls bare.git/objects/pack/*.bitmap || :) &&
214 test_expect_success
'no bitmaps created if .keep files present' '
215 pack=$(ls bare.git/objects/pack/*.pack) &&
216 test_path_is_file "$pack" &&
217 keep=${pack%.pack}.keep &&
218 test_when_finished "rm -f \"\$keep\"" &&
220 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
221 git -C bare.git repack -ad 2>stderr &&
222 test_must_be_empty stderr &&
223 find bare.git/objects/pack/ -type f -name "*.bitmap" >actual &&
224 test_must_be_empty actual
227 test_expect_success
'auto-bitmaps do not complain if unavailable' '
228 test_config -C bare.git pack.packSizeLimit 1M &&
229 blob=$(test-tool genrandom big $((1024*1024)) |
230 git -C bare.git hash-object -w --stdin) &&
231 git -C bare.git update-ref refs/tags/big $blob &&
232 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
233 git -C bare.git repack -ad 2>stderr &&
234 test_must_be_empty stderr &&
235 find bare.git/objects/pack -type f -name "*.bitmap" >actual &&
236 test_must_be_empty actual
240 midx
=$objdir/pack
/multi-pack-index
242 test_expect_success
'setup for --write-midx tests' '
246 git config core.multiPackIndex true &&
252 test_expect_success
'--write-midx unchanged' '
255 GIT_TEST_MULTI_PACK_INDEX=0 git repack &&
256 test_path_is_missing $midx &&
257 test_path_is_missing $midx-*.bitmap &&
259 GIT_TEST_MULTI_PACK_INDEX=0 git repack --write-midx &&
261 test_path_is_file $midx &&
262 test_path_is_missing $midx-*.bitmap &&
263 test_midx_consistent $objdir
267 test_expect_success
'--write-midx with a new pack' '
272 GIT_TEST_MULTI_PACK_INDEX=0 git repack --write-midx &&
274 test_path_is_file $midx &&
275 test_path_is_missing $midx-*.bitmap &&
276 test_midx_consistent $objdir
280 test_expect_success
'--write-midx with -b' '
283 GIT_TEST_MULTI_PACK_INDEX=0 git repack -mb &&
285 test_path_is_file $midx &&
286 test_path_is_file $midx-*.bitmap &&
287 test_midx_consistent $objdir
291 test_expect_success
'--write-midx with -d' '
294 test_commit repack &&
296 GIT_TEST_MULTI_PACK_INDEX=0 git repack -Ad --write-midx &&
298 test_path_is_file $midx &&
299 test_path_is_missing $midx-*.bitmap &&
300 test_midx_consistent $objdir
304 test_expect_success
'cleans up MIDX when appropriate' '
308 test_commit repack-2 &&
309 GIT_TEST_MULTI_PACK_INDEX=0 git repack -Adb --write-midx &&
311 checksum=$(midx_checksum $objdir) &&
312 test_path_is_file $midx &&
313 test_path_is_file $midx-$checksum.bitmap &&
314 test_path_is_file $midx-$checksum.rev &&
316 test_commit repack-3 &&
317 GIT_TEST_MULTI_PACK_INDEX=0 git repack -Adb --write-midx &&
319 test_path_is_file $midx &&
320 test_path_is_missing $midx-$checksum.bitmap &&
321 test_path_is_missing $midx-$checksum.rev &&
322 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
323 test_path_is_file $midx-$(midx_checksum $objdir).rev &&
325 test_commit repack-4 &&
326 GIT_TEST_MULTI_PACK_INDEX=0 git repack -Adb &&
328 find $objdir/pack -type f -name "multi-pack-index*" >files &&
329 test_must_be_empty files
333 test_expect_success
'--write-midx with preferred bitmap tips' '
334 git init midx-preferred-tips &&
335 test_when_finished "rm -fr midx-preferred-tips" &&
337 cd midx-preferred-tips &&
339 test_commit_bulk --message="%s" 103 &&
341 git log --format="%H" >commits.raw &&
342 sort <commits.raw >commits &&
344 git log --format="create refs/tags/%s/%s %H" HEAD >refs &&
345 git update-ref --stdin <refs &&
347 git repack --write-midx --write-bitmap-index &&
348 test_path_is_file $midx &&
349 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
351 test-tool bitmap list-commits | sort >bitmaps &&
352 comm -13 bitmaps commits >before &&
353 test_line_count = 1 before &&
355 rm -fr $midx-$(midx_checksum $objdir).bitmap &&
356 rm -fr $midx-$(midx_checksum $objdir).rev &&
359 # instead of constructing the snapshot ourselves (c.f., the test
360 # "write a bitmap with --refs-snapshot (preferred tips)" in
361 # t5326), mark the missing commit as preferred by adding it to
362 # the pack.preferBitmapTips configuration.
363 git for-each-ref --format="%(refname:rstrip=1)" \
364 --points-at="$(cat before)" >missing &&
365 git config pack.preferBitmapTips "$(cat missing)" &&
366 git repack --write-midx --write-bitmap-index &&
368 test-tool bitmap list-commits | sort >bitmaps &&
369 comm -13 bitmaps commits >after &&
371 ! test_cmp before after