3 test_description
='git repack works correctly'
6 .
"${TEST_DIRECTORY}/lib-bitmap.sh"
7 .
"${TEST_DIRECTORY}/lib-midx.sh"
8 .
"${TEST_DIRECTORY}/lib-terminal.sh"
11 test_commit
"$@" 1>&2 &&
12 incrpackid
=$
(git pack-objects
--all --unpacked --incremental .git
/objects
/pack
/pack
</dev
/null
) &&
13 echo pack-
${incrpackid}.pack
16 test_no_missing_in_packs
() {
17 myidx
=$
(ls -1 .git
/objects
/pack
/*.idx
) &&
18 test_path_is_file
"$myidx" &&
19 git verify-pack
-v alt_objects
/pack
/*.idx
>orig.raw
&&
20 sed -n -e "s/^\($OID_REGEX\).*/\1/p" orig.raw |
sort >orig
&&
21 git verify-pack
-v $myidx >dest.raw
&&
22 cut
-d" " -f1 dest.raw |
sort >dest
&&
23 comm -23 orig dest
>missing
&&
24 test_must_be_empty missing
27 # we expect $packid and $oid to be defined
28 test_has_duplicate_object
() {
29 want_duplicate_object
="$1"
30 found_duplicate_object
=false
31 for p
in .git
/objects
/pack
/*.idx
34 test "pack-$packid.idx" = "$idx" && continue
35 git verify-pack
-v $p >packlist ||
return $?
36 if grep "^$oid" packlist
38 found_duplicate_object
=true
39 echo "DUPLICATE OBJECT FOUND"
43 test "$want_duplicate_object" = "$found_duplicate_object"
46 test_expect_success
'objects in packs marked .keep are not repacked' '
47 echo content1 >file1 &&
48 echo content2 >file2 &&
51 git commit -m initial_commit &&
53 # The first pack will contain all of the objects except one
54 git rev-list --objects --all >objs &&
55 grep -v file2 objs | git pack-objects pack &&
56 # The second pack will contain the excluded object
57 packid=$(grep file2 objs | git pack-objects pack) &&
59 git verify-pack -v pack-$packid.idx >packlist &&
60 oid=$(head -n 1 packlist | sed -e "s/^\($OID_REGEX\).*/\1/") &&
61 mv pack-* .git/objects/pack/ &&
62 git repack -A -d -l &&
64 test_has_duplicate_object false
67 test_expect_success
'writing bitmaps via command-line can duplicate .keep objects' '
68 # build on $oid, $packid, and .keep state from previous
69 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 git repack -Adbl &&
70 test_has_duplicate_object true
73 test_expect_success
'writing bitmaps via config can duplicate .keep objects' '
74 # build on $oid, $packid, and .keep state from previous
75 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
76 git -c repack.writebitmaps=true repack -Adl &&
77 test_has_duplicate_object true
80 test_expect_success
'loose objects in alternate ODB are not repacked' '
82 echo $(pwd)/alt_objects >.git/objects/info/alternates &&
83 echo content3 >file3 &&
84 oid=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
87 git commit -m commit_file3 &&
88 git repack -a -d -l &&
90 test_has_duplicate_object false
93 test_expect_success
'packed obs in alt ODB are repacked even when local repo is packless' '
94 mkdir alt_objects/pack &&
95 mv .git/objects/pack/* alt_objects/pack &&
97 test_no_missing_in_packs
100 test_expect_success
'packed obs in alt ODB are repacked when local repo has packs' '
101 rm -f .git/objects/pack/* &&
102 echo new_content >>file1 &&
105 git commit -m more_content &&
108 test_no_missing_in_packs
111 test_expect_success
'packed obs in alternate ODB kept pack are repacked' '
112 # swap the .keep so the commit object is in the pack with .keep
113 for p in alt_objects/pack/*.pack
115 base_name=$(basename $p .pack) &&
116 if test_path_is_file alt_objects/pack/$base_name.keep
118 rm alt_objects/pack/$base_name.keep
120 touch alt_objects/pack/$base_name.keep
124 test_no_missing_in_packs
127 test_expect_success
'packed unreachable obs in alternate ODB are not loosened' '
128 rm -f alt_objects/pack/*.keep &&
129 mv .git/objects/pack/* alt_objects/pack/ &&
130 coid=$(git rev-parse HEAD^{commit}) &&
131 git reset --hard HEAD^ &&
133 git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
134 # The pack-objects call on the next line is equivalent to
135 # git repack -A -d without the call to prune-packed
136 git pack-objects --honor-pack-keep --non-empty --all --reflog \
137 --unpack-unreachable </dev/null pack &&
138 rm -f .git/objects/pack/* &&
139 mv pack-* .git/objects/pack/ &&
140 git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
141 ! grep "^$coid " packlist &&
142 echo >.git/objects/info/alternates &&
143 test_must_fail git show $coid
146 test_expect_success
'local packed unreachable obs that exist in alternate ODB are not loosened' '
147 echo $(pwd)/alt_objects >.git/objects/info/alternates &&
148 echo "$coid" | git pack-objects --non-empty --all --reflog pack &&
149 rm -f .git/objects/pack/* &&
150 mv pack-* .git/objects/pack/ &&
151 # The pack-objects call on the next line is equivalent to
152 # git repack -A -d without the call to prune-packed
153 git pack-objects --honor-pack-keep --non-empty --all --reflog \
154 --unpack-unreachable </dev/null pack &&
155 rm -f .git/objects/pack/* &&
156 mv pack-* .git/objects/pack/ &&
157 git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
159 echo >.git/objects/info/alternates &&
160 test_must_fail git show $coid
163 test_expect_success
'objects made unreachable by grafts only are kept' '
165 git commit --allow-empty -m "commit 4" &&
166 H0=$(git rev-parse HEAD) &&
167 H1=$(git rev-parse HEAD^) &&
168 H2=$(git rev-parse HEAD^^) &&
169 echo "$H0 $H2" >.git/info/grafts &&
170 git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
175 test_expect_success
'repack --keep-pack' '
176 test_create_repo keep-pack &&
179 P1=$(commit_and_pack 1) &&
180 P2=$(commit_and_pack 2) &&
181 P3=$(commit_and_pack 3) &&
182 P4=$(commit_and_pack 4) &&
183 ls .git/objects/pack/*.pack >old-counts &&
184 test_line_count = 4 old-counts &&
185 git repack -a -d --keep-pack $P1 --keep-pack $P4 &&
186 ls .git/objects/pack/*.pack >new-counts &&
187 grep -q $P1 new-counts &&
188 grep -q $P4 new-counts &&
189 test_line_count = 3 new-counts &&
194 test_expect_success
'bitmaps are created by default in bare repos' '
195 git clone --bare .git bare.git &&
196 rm -f bare.git/objects/pack/*.bitmap &&
197 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
198 git -C bare.git repack -ad &&
199 bitmap=$(ls bare.git/objects/pack/*.bitmap) &&
200 test_path_is_file "$bitmap"
203 test_expect_success
'incremental repack does not complain' '
204 git -C bare.git repack -q 2>repack.err &&
205 test_must_be_empty repack.err
208 test_expect_success
'bitmaps can be disabled on bare repos' '
209 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
210 git -c repack.writeBitmaps=false -C bare.git repack -ad &&
211 bitmap=$(ls bare.git/objects/pack/*.bitmap || :) &&
215 test_expect_success
'no bitmaps created if .keep files present' '
216 pack=$(ls bare.git/objects/pack/*.pack) &&
217 test_path_is_file "$pack" &&
218 keep=${pack%.pack}.keep &&
219 test_when_finished "rm -f \"\$keep\"" &&
221 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
222 git -C bare.git repack -ad 2>stderr &&
223 test_must_be_empty stderr &&
224 find bare.git/objects/pack/ -type f -name "*.bitmap" >actual &&
225 test_must_be_empty actual
228 test_expect_success
'auto-bitmaps do not complain if unavailable' '
229 test_config -C bare.git pack.packSizeLimit 1M &&
230 blob=$(test-tool genrandom big $((1024*1024)) |
231 git -C bare.git hash-object -w --stdin) &&
232 git -C bare.git update-ref refs/tags/big $blob &&
233 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
234 git -C bare.git repack -ad 2>stderr &&
235 test_must_be_empty stderr &&
236 find bare.git/objects/pack -type f -name "*.bitmap" >actual &&
237 test_must_be_empty actual
241 midx
=$objdir/pack
/multi-pack-index
243 test_expect_success
'setup for --write-midx tests' '
247 git config core.multiPackIndex true &&
253 test_expect_success
'--write-midx unchanged' '
256 GIT_TEST_MULTI_PACK_INDEX=0 git repack &&
257 test_path_is_missing $midx &&
258 test_path_is_missing $midx-*.bitmap &&
260 GIT_TEST_MULTI_PACK_INDEX=0 git repack --write-midx &&
262 test_path_is_file $midx &&
263 test_path_is_missing $midx-*.bitmap &&
264 test_midx_consistent $objdir
268 test_expect_success
'--write-midx with a new pack' '
273 GIT_TEST_MULTI_PACK_INDEX=0 git repack --write-midx &&
275 test_path_is_file $midx &&
276 test_path_is_missing $midx-*.bitmap &&
277 test_midx_consistent $objdir
281 test_expect_success
'--write-midx with -b' '
284 GIT_TEST_MULTI_PACK_INDEX=0 git repack -mb &&
286 test_path_is_file $midx &&
287 test_path_is_file $midx-*.bitmap &&
288 test_midx_consistent $objdir
292 test_expect_success
'--write-midx with -d' '
295 test_commit repack &&
297 GIT_TEST_MULTI_PACK_INDEX=0 git repack -Ad --write-midx &&
299 test_path_is_file $midx &&
300 test_path_is_missing $midx-*.bitmap &&
301 test_midx_consistent $objdir
305 test_expect_success
'cleans up MIDX when appropriate' '
309 test_commit repack-2 &&
310 GIT_TEST_MULTI_PACK_INDEX=0 git repack -Adb --write-midx &&
312 checksum=$(midx_checksum $objdir) &&
313 test_path_is_file $midx &&
314 test_path_is_file $midx-$checksum.bitmap &&
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_file $midx-$(midx_checksum $objdir).bitmap &&
323 test_commit repack-4 &&
324 GIT_TEST_MULTI_PACK_INDEX=0 git repack -Adb &&
326 find $objdir/pack -type f -name "multi-pack-index*" >files &&
327 test_must_be_empty files
331 test_expect_success
'--write-midx with preferred bitmap tips' '
332 git init midx-preferred-tips &&
333 test_when_finished "rm -fr midx-preferred-tips" &&
335 cd midx-preferred-tips &&
337 test_commit_bulk --message="%s" 103 &&
339 git log --format="%H" >commits.raw &&
340 sort <commits.raw >commits &&
342 git log --format="create refs/tags/%s/%s %H" HEAD >refs &&
343 git update-ref --stdin <refs &&
345 git repack --write-midx --write-bitmap-index &&
346 test_path_is_file $midx &&
347 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
349 test-tool bitmap list-commits | sort >bitmaps &&
350 comm -13 bitmaps commits >before &&
351 test_line_count = 1 before &&
353 rm -fr $midx-$(midx_checksum $objdir).bitmap &&
356 # instead of constructing the snapshot ourselves (c.f., the test
357 # "write a bitmap with --refs-snapshot (preferred tips)" in
358 # t5326), mark the missing commit as preferred by adding it to
359 # the pack.preferBitmapTips configuration.
360 git for-each-ref --format="%(refname:rstrip=1)" \
361 --points-at="$(cat before)" >missing &&
362 git config pack.preferBitmapTips "$(cat missing)" &&
363 git repack --write-midx --write-bitmap-index &&
365 test-tool bitmap list-commits | sort >bitmaps &&
366 comm -13 bitmaps commits >after &&
368 ! test_cmp before after
372 # The first argument is expected to be a filename
373 # and that file should contain the name of a .idx
374 # file. Send the list of objects in that .idx file
376 get_sorted_objects_from_pack
() {
377 git show-index
<$
(cat "$1") >raw
&&
381 test_expect_success
'--write-midx -b packs non-kept objects' '
383 test_when_finished "rm -fr repo" &&
387 # Create a kept pack-file
390 find $objdir/pack -name "*.idx" >before &&
391 test_line_count = 1 before &&
392 before_name=$(cat before) &&
393 >${before_name%.idx}.keep &&
395 # Create a non-kept pack-file
399 # Create loose objects
403 git repack --write-midx -a -b -d &&
405 # There should be two pack-files now, the
406 # old, kept pack and the new, non-kept pack.
407 find $objdir/pack -name "*.idx" | sort >after &&
408 test_line_count = 2 after &&
409 find $objdir/pack -name "*.keep" >kept &&
410 kept_name=$(cat kept) &&
411 echo ${kept_name%.keep}.idx >kept-idx &&
412 test_cmp before kept-idx &&
414 # Get object list from the kept pack.
415 get_sorted_objects_from_pack before >old.objects &&
417 # Get object list from the one non-kept pack-file
418 comm -13 before after >new-pack &&
419 test_line_count = 1 new-pack &&
420 get_sorted_objects_from_pack new-pack >new.objects &&
422 # None of the objects in the new pack should
423 # exist within the kept pack.
424 comm -12 old.objects new.objects >shared.objects &&
425 test_must_be_empty shared.objects
429 test_expect_success TTY
'--quiet disables progress' '
430 test_terminal env GIT_PROGRESS_DELAY=0 \
431 git -C midx repack -ad --quiet --write-midx 2>stderr &&
432 test_must_be_empty stderr
435 test_expect_success
'setup for update-server-info' '
436 git init update-server-info &&
437 test_commit -C update-server-info message
440 test_server_info_present
() {
441 test_path_is_file update-server-info
/.git
/objects
/info
/packs
&&
442 test_path_is_file update-server-info
/.git
/info
/refs
445 test_server_info_missing
() {
446 test_path_is_missing update-server-info
/.git
/objects
/info
/packs
&&
447 test_path_is_missing update-server-info
/.git
/info
/refs
450 test_server_info_cleanup
() {
451 rm -f update-server-info
/.git
/objects
/info
/packs update-server-info
/.git
/info
/refs
&&
452 test_server_info_missing
455 test_expect_success
'updates server info by default' '
456 test_server_info_cleanup &&
457 git -C update-server-info repack &&
458 test_server_info_present
461 test_expect_success
'-n skips updating server info' '
462 test_server_info_cleanup &&
463 git -C update-server-info repack -n &&
464 test_server_info_missing
467 test_expect_success
'repack.updateServerInfo=true updates server info' '
468 test_server_info_cleanup &&
469 git -C update-server-info -c repack.updateServerInfo=true repack &&
470 test_server_info_present
473 test_expect_success
'repack.updateServerInfo=false skips updating server info' '
474 test_server_info_cleanup &&
475 git -C update-server-info -c repack.updateServerInfo=false repack &&
476 test_server_info_missing
479 test_expect_success
'-n overrides repack.updateServerInfo=true' '
480 test_server_info_cleanup &&
481 git -C update-server-info -c repack.updateServerInfo=true repack -n &&
482 test_server_info_missing