A few more topics before -rc1
[alt-git.git] / t / t7700-repack.sh
blob27b66807cd82cbb93c4985905a8de7945cc17cbc
1 #!/bin/sh
3 test_description='git repack works correctly'
5 . ./test-lib.sh
6 . "${TEST_DIRECTORY}/lib-bitmap.sh"
7 . "${TEST_DIRECTORY}/lib-midx.sh"
8 . "${TEST_DIRECTORY}/lib-terminal.sh"
10 commit_and_pack () {
11 test_commit "$@" 1>&2 &&
12 incrpackid=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) &&
13 # Remove any loose object(s) created by test_commit, since they have
14 # already been packed. Leaving these around can create subtly different
15 # packs with `pack-objects`'s `--unpacked` option.
16 git prune-packed 1>&2 &&
17 echo pack-${incrpackid}.pack
20 test_no_missing_in_packs () {
21 myidx=$(ls -1 .git/objects/pack/*.idx) &&
22 test_path_is_file "$myidx" &&
23 git verify-pack -v alt_objects/pack/*.idx >orig.raw &&
24 sed -n -e "s/^\($OID_REGEX\).*/\1/p" orig.raw | sort >orig &&
25 git verify-pack -v $myidx >dest.raw &&
26 cut -d" " -f1 dest.raw | sort >dest &&
27 comm -23 orig dest >missing &&
28 test_must_be_empty missing
31 # we expect $packid and $oid to be defined
32 test_has_duplicate_object () {
33 want_duplicate_object="$1"
34 found_duplicate_object=false
35 for p in .git/objects/pack/*.idx
37 idx=$(basename $p)
38 test "pack-$packid.idx" = "$idx" && continue
39 git verify-pack -v $p >packlist || return $?
40 if grep "^$oid" packlist
41 then
42 found_duplicate_object=true
43 echo "DUPLICATE OBJECT FOUND"
44 break
46 done &&
47 test "$want_duplicate_object" = "$found_duplicate_object"
50 test_expect_success 'objects in packs marked .keep are not repacked' '
51 echo content1 >file1 &&
52 echo content2 >file2 &&
53 git add . &&
54 test_tick &&
55 git commit -m initial_commit &&
56 # Create two packs
57 # The first pack will contain all of the objects except one
58 git rev-list --objects --all >objs &&
59 grep -v file2 objs | git pack-objects pack &&
60 # The second pack will contain the excluded object
61 packid=$(grep file2 objs | git pack-objects pack) &&
62 >pack-$packid.keep &&
63 git verify-pack -v pack-$packid.idx >packlist &&
64 oid=$(head -n 1 packlist | sed -e "s/^\($OID_REGEX\).*/\1/") &&
65 mv pack-* .git/objects/pack/ &&
66 git repack -A -d -l &&
67 git prune-packed &&
68 test_has_duplicate_object false
71 test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' '
72 # build on $oid, $packid, and .keep state from previous
73 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 git repack -Adbl &&
74 test_has_duplicate_object true
77 test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
78 # build on $oid, $packid, and .keep state from previous
79 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
80 git -c repack.writebitmaps=true repack -Adl &&
81 test_has_duplicate_object true
84 test_expect_success 'loose objects in alternate ODB are not repacked' '
85 mkdir alt_objects &&
86 echo $(pwd)/alt_objects >.git/objects/info/alternates &&
87 echo content3 >file3 &&
88 oid=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
89 git add file3 &&
90 test_tick &&
91 git commit -m commit_file3 &&
92 git repack -a -d -l &&
93 git prune-packed &&
94 test_has_duplicate_object false
97 test_expect_success SYMLINKS '--local keeps packs when alternate is objectdir ' '
98 test_when_finished "rm -rf repo" &&
99 git init repo &&
100 test_commit -C repo A &&
102 cd repo &&
103 git repack -a &&
104 ls .git/objects/pack/*.pack >../expect &&
105 ln -s objects .git/alt_objects &&
106 echo "$(pwd)/.git/alt_objects" >.git/objects/info/alternates &&
107 git repack -a -d -l &&
108 ls .git/objects/pack/*.pack >../actual
109 ) &&
110 test_cmp expect actual
113 test_expect_success '--local disables writing bitmaps when connected to alternate ODB' '
114 test_when_finished "rm -rf shared member" &&
116 git init shared &&
117 git clone --shared shared member &&
119 cd member &&
120 test_commit "object" &&
121 GIT_TEST_MULTI_PACK_INDEX=0 git repack -Adl --write-bitmap-index 2>err &&
122 cat >expect <<-EOF &&
123 warning: disabling bitmap writing, as some objects are not being packed
125 test_cmp expect err &&
126 test_path_is_missing .git/objects/pack-*.bitmap
130 test_expect_success 'packed obs in alt ODB are repacked even when local repo is packless' '
131 mkdir alt_objects/pack &&
132 mv .git/objects/pack/* alt_objects/pack &&
133 git repack -a &&
134 test_no_missing_in_packs
137 test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' '
138 rm -f .git/objects/pack/* &&
139 echo new_content >>file1 &&
140 git add file1 &&
141 test_tick &&
142 git commit -m more_content &&
143 git repack &&
144 git repack -a -d &&
145 test_no_missing_in_packs
148 test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
149 # swap the .keep so the commit object is in the pack with .keep
150 for p in alt_objects/pack/*.pack
152 base_name=$(basename $p .pack) &&
153 if test_path_is_file alt_objects/pack/$base_name.keep
154 then
155 rm alt_objects/pack/$base_name.keep
156 else
157 touch alt_objects/pack/$base_name.keep
158 fi || return 1
159 done &&
160 git repack -a -d &&
161 test_no_missing_in_packs
164 test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
165 rm -f alt_objects/pack/*.keep &&
166 mv .git/objects/pack/* alt_objects/pack/ &&
167 coid=$(git rev-parse HEAD^{commit}) &&
168 git reset --hard HEAD^ &&
169 test_tick &&
170 git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
171 # The pack-objects call on the next line is equivalent to
172 # git repack -A -d without the call to prune-packed
173 git pack-objects --honor-pack-keep --non-empty --all --reflog \
174 --unpack-unreachable </dev/null pack &&
175 rm -f .git/objects/pack/* &&
176 mv pack-* .git/objects/pack/ &&
177 git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
178 ! grep "^$coid " packlist &&
179 echo >.git/objects/info/alternates &&
180 test_must_fail git show $coid
183 test_expect_success 'local packed unreachable obs that exist in alternate ODB are not loosened' '
184 echo $(pwd)/alt_objects >.git/objects/info/alternates &&
185 echo "$coid" | git pack-objects --non-empty --all --reflog pack &&
186 rm -f .git/objects/pack/* &&
187 mv pack-* .git/objects/pack/ &&
188 # The pack-objects call on the next line is equivalent to
189 # git repack -A -d without the call to prune-packed
190 git pack-objects --honor-pack-keep --non-empty --all --reflog \
191 --unpack-unreachable </dev/null pack &&
192 rm -f .git/objects/pack/* &&
193 mv pack-* .git/objects/pack/ &&
194 git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
195 ! grep "^$coid " &&
196 echo >.git/objects/info/alternates &&
197 test_must_fail git show $coid
200 test_expect_success 'objects made unreachable by grafts only are kept' '
201 test_tick &&
202 git commit --allow-empty -m "commit 4" &&
203 H0=$(git rev-parse HEAD) &&
204 H1=$(git rev-parse HEAD^) &&
205 H2=$(git rev-parse HEAD^^) &&
206 echo "$H0 $H2" >.git/info/grafts &&
207 git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
208 git repack -a -d &&
209 git cat-file -t $H1
212 test_expect_success 'repack --keep-pack' '
213 test_create_repo keep-pack &&
215 cd keep-pack &&
216 # avoid producing different packs due to delta/base choices
217 git config pack.window 0 &&
218 P1=$(commit_and_pack 1) &&
219 P2=$(commit_and_pack 2) &&
220 P3=$(commit_and_pack 3) &&
221 P4=$(commit_and_pack 4) &&
222 ls .git/objects/pack/*.pack >old-counts &&
223 test_line_count = 4 old-counts &&
224 git repack -a -d --keep-pack $P1 --keep-pack $P4 &&
225 ls .git/objects/pack/*.pack >new-counts &&
226 grep -q $P1 new-counts &&
227 grep -q $P4 new-counts &&
228 test_line_count = 3 new-counts &&
229 git fsck &&
231 P5=$(commit_and_pack --no-tag 5) &&
232 git reset --hard HEAD^ &&
233 git reflog expire --all --expire=all &&
234 rm -f ".git/objects/pack/${P5%.pack}.idx" &&
235 rm -f ".git/objects/info/commit-graph" &&
236 for from in $(find .git/objects/pack -type f -name "${P5%.pack}.*")
238 to="$(dirname "$from")/.tmp-1234-$(basename "$from")" &&
239 mv "$from" "$to" || return 1
240 done &&
242 # A .idx file without a .pack should not stop us from
243 # repacking what we can.
244 touch .git/objects/pack/pack-does-not-exist.idx &&
246 git repack --cruft -d --keep-pack $P1 --keep-pack $P4 &&
248 ls .git/objects/pack/*.pack >newer-counts &&
249 test_cmp new-counts newer-counts &&
250 git fsck
254 test_expect_success 'repacking fails when missing .pack actually means missing objects' '
255 test_create_repo idx-without-pack &&
257 cd idx-without-pack &&
259 # Avoid producing different packs due to delta/base choices
260 git config pack.window 0 &&
261 P1=$(commit_and_pack 1) &&
262 P2=$(commit_and_pack 2) &&
263 P3=$(commit_and_pack 3) &&
264 P4=$(commit_and_pack 4) &&
265 ls .git/objects/pack/*.pack >old-counts &&
266 test_line_count = 4 old-counts &&
268 # Remove one .pack file
269 rm .git/objects/pack/$P2 &&
271 ls .git/objects/pack/*.pack >before-pack-dir &&
273 test_must_fail git fsck &&
274 test_must_fail git repack --cruft -d 2>err &&
275 grep "bad object" err &&
277 # Before failing, the repack did not modify the
278 # pack directory.
279 ls .git/objects/pack/*.pack >after-pack-dir &&
280 test_cmp before-pack-dir after-pack-dir
284 test_expect_success 'bitmaps are created by default in bare repos' '
285 git clone --bare .git bare.git &&
286 rm -f bare.git/objects/pack/*.bitmap &&
287 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
288 git -C bare.git repack -ad &&
289 bitmap=$(ls bare.git/objects/pack/*.bitmap) &&
290 test_path_is_file "$bitmap"
293 test_expect_success 'incremental repack does not complain' '
294 git -C bare.git repack -q 2>repack.err &&
295 test_must_be_empty repack.err
298 test_expect_success 'bitmaps can be disabled on bare repos' '
299 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
300 git -c repack.writeBitmaps=false -C bare.git repack -ad &&
301 bitmap=$(ls bare.git/objects/pack/*.bitmap || :) &&
302 test -z "$bitmap"
305 test_expect_success 'no bitmaps created if .keep files present' '
306 pack=$(ls bare.git/objects/pack/*.pack) &&
307 test_path_is_file "$pack" &&
308 keep=${pack%.pack}.keep &&
309 test_when_finished "rm -f \"\$keep\"" &&
310 >"$keep" &&
311 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
312 git -C bare.git repack -ad 2>stderr &&
313 test_must_be_empty stderr &&
314 find bare.git/objects/pack/ -type f -name "*.bitmap" >actual &&
315 test_must_be_empty actual
318 test_expect_success 'auto-bitmaps do not complain if unavailable' '
319 test_config -C bare.git pack.packSizeLimit 1M &&
320 blob=$(test-tool genrandom big $((1024*1024)) |
321 git -C bare.git hash-object -w --stdin) &&
322 git -C bare.git update-ref refs/tags/big $blob &&
323 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
324 git -C bare.git repack -ad 2>stderr &&
325 test_must_be_empty stderr &&
326 find bare.git/objects/pack -type f -name "*.bitmap" >actual &&
327 test_must_be_empty actual
330 objdir=.git/objects
331 midx=$objdir/pack/multi-pack-index
333 test_expect_success 'setup for --write-midx tests' '
334 git init midx &&
336 cd midx &&
337 git config core.multiPackIndex true &&
339 test_commit base
343 test_expect_success '--write-midx unchanged' '
345 cd midx &&
346 GIT_TEST_MULTI_PACK_INDEX=0 git repack &&
347 test_path_is_missing $midx &&
348 test_path_is_missing $midx-*.bitmap &&
350 GIT_TEST_MULTI_PACK_INDEX=0 git repack --write-midx &&
352 test_path_is_file $midx &&
353 test_path_is_missing $midx-*.bitmap &&
354 test_midx_consistent $objdir
358 test_expect_success '--write-midx with a new pack' '
360 cd midx &&
361 test_commit loose &&
363 GIT_TEST_MULTI_PACK_INDEX=0 git repack --write-midx &&
365 test_path_is_file $midx &&
366 test_path_is_missing $midx-*.bitmap &&
367 test_midx_consistent $objdir
371 test_expect_success '--write-midx with -b' '
373 cd midx &&
374 GIT_TEST_MULTI_PACK_INDEX=0 git repack -mb &&
376 test_path_is_file $midx &&
377 test_path_is_file $midx-*.bitmap &&
378 test_midx_consistent $objdir
382 test_expect_success '--write-midx with -d' '
384 cd midx &&
385 test_commit repack &&
387 GIT_TEST_MULTI_PACK_INDEX=0 git repack -Ad --write-midx &&
389 test_path_is_file $midx &&
390 test_path_is_missing $midx-*.bitmap &&
391 test_midx_consistent $objdir
395 test_expect_success 'cleans up MIDX when appropriate' '
397 cd midx &&
399 test_commit repack-2 &&
400 GIT_TEST_MULTI_PACK_INDEX=0 git repack -Adb --write-midx &&
402 checksum=$(midx_checksum $objdir) &&
403 test_path_is_file $midx &&
404 test_path_is_file $midx-$checksum.bitmap &&
406 test_commit repack-3 &&
407 GIT_TEST_MULTI_PACK_INDEX=0 git repack -Adb --write-midx &&
409 test_path_is_file $midx &&
410 test_path_is_missing $midx-$checksum.bitmap &&
411 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
413 test_commit repack-4 &&
414 GIT_TEST_MULTI_PACK_INDEX=0 git repack -Adb &&
416 find $objdir/pack -type f -name "multi-pack-index*" >files &&
417 test_must_be_empty files
421 test_expect_success '--write-midx with preferred bitmap tips' '
422 git init midx-preferred-tips &&
423 test_when_finished "rm -fr midx-preferred-tips" &&
425 cd midx-preferred-tips &&
427 test_commit_bulk --message="%s" 103 &&
429 git log --format="%H" >commits.raw &&
430 sort <commits.raw >commits &&
432 git log --format="create refs/tags/%s/%s %H" HEAD >refs &&
433 git update-ref --stdin <refs &&
435 git repack --write-midx --write-bitmap-index &&
436 test_path_is_file $midx &&
437 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
439 test-tool bitmap list-commits | sort >bitmaps &&
440 comm -13 bitmaps commits >before &&
441 test_line_count = 1 before &&
443 rm -fr $midx-$(midx_checksum $objdir).bitmap &&
444 rm -fr $midx &&
446 # instead of constructing the snapshot ourselves (c.f., the test
447 # "write a bitmap with --refs-snapshot (preferred tips)" in
448 # t5326), mark the missing commit as preferred by adding it to
449 # the pack.preferBitmapTips configuration.
450 git for-each-ref --format="%(refname:rstrip=1)" \
451 --points-at="$(cat before)" >missing &&
452 git config pack.preferBitmapTips "$(cat missing)" &&
453 git repack --write-midx --write-bitmap-index &&
455 test-tool bitmap list-commits | sort >bitmaps &&
456 comm -13 bitmaps commits >after &&
458 ! test_cmp before after
462 # The first argument is expected to be a filename
463 # and that file should contain the name of a .idx
464 # file. Send the list of objects in that .idx file
465 # into stdout.
466 get_sorted_objects_from_pack () {
467 git show-index <$(cat "$1") >raw &&
468 cut -d" " -f2 raw
471 test_expect_success '--write-midx -b packs non-kept objects' '
472 git init repo &&
473 test_when_finished "rm -fr repo" &&
475 cd repo &&
477 # Create a kept pack-file
478 test_commit base &&
479 git repack -ad &&
480 find $objdir/pack -name "*.idx" >before &&
481 test_line_count = 1 before &&
482 before_name=$(cat before) &&
483 >${before_name%.idx}.keep &&
485 # Create a non-kept pack-file
486 test_commit other &&
487 git repack &&
489 # Create loose objects
490 test_commit loose &&
492 # Repack everything
493 git repack --write-midx -a -b -d &&
495 # There should be two pack-files now, the
496 # old, kept pack and the new, non-kept pack.
497 find $objdir/pack -name "*.idx" | sort >after &&
498 test_line_count = 2 after &&
499 find $objdir/pack -name "*.keep" >kept &&
500 kept_name=$(cat kept) &&
501 echo ${kept_name%.keep}.idx >kept-idx &&
502 test_cmp before kept-idx &&
504 # Get object list from the kept pack.
505 get_sorted_objects_from_pack before >old.objects &&
507 # Get object list from the one non-kept pack-file
508 comm -13 before after >new-pack &&
509 test_line_count = 1 new-pack &&
510 get_sorted_objects_from_pack new-pack >new.objects &&
512 # None of the objects in the new pack should
513 # exist within the kept pack.
514 comm -12 old.objects new.objects >shared.objects &&
515 test_must_be_empty shared.objects
519 test_expect_success '--write-midx removes stale pack-based bitmaps' '
520 rm -fr repo &&
521 git init repo &&
522 test_when_finished "rm -fr repo" &&
524 cd repo &&
525 test_commit base &&
526 GIT_TEST_MULTI_PACK_INDEX=0 git repack -Ab &&
528 pack_bitmap=$(ls $objdir/pack/pack-*.bitmap) &&
529 test_path_is_file "$pack_bitmap" &&
531 test_commit tip &&
532 GIT_TEST_MULTI_PACK_INDEX=0 git repack -bm &&
534 test_path_is_file $midx &&
535 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
536 test_path_is_missing $pack_bitmap
540 test_expect_success '--write-midx with --pack-kept-objects' '
541 git init repo &&
542 test_when_finished "rm -fr repo" &&
544 cd repo &&
546 test_commit one &&
547 test_commit two &&
549 one="$(echo "one" | git pack-objects --revs $objdir/pack/pack)" &&
550 two="$(echo "one..two" | git pack-objects --revs $objdir/pack/pack)" &&
552 keep="$objdir/pack/pack-$one.keep" &&
553 touch "$keep" &&
555 git repack --write-midx --write-bitmap-index --geometric=2 -d \
556 --pack-kept-objects &&
558 test_path_is_file $keep &&
559 test_path_is_file $midx &&
560 test_path_is_file $midx-$(midx_checksum $objdir).bitmap
564 test_expect_success TTY '--quiet disables progress' '
565 test_terminal env GIT_PROGRESS_DELAY=0 \
566 git -C midx repack -ad --quiet --write-midx 2>stderr &&
567 test_must_be_empty stderr
570 test_expect_success 'clean up .tmp-* packs on error' '
571 test_must_fail ok=sigpipe git \
572 -c repack.cruftwindow=bogus \
573 repack -ad --cruft &&
574 find $objdir/pack -name '.tmp-*' >tmpfiles &&
575 test_must_be_empty tmpfiles
578 test_expect_success 'repack -ad cleans up old .tmp-* packs' '
579 git rev-parse HEAD >input &&
580 git pack-objects $objdir/pack/.tmp-1234 <input &&
581 git repack -ad &&
582 find $objdir/pack -name '.tmp-*' >tmpfiles &&
583 test_must_be_empty tmpfiles
586 test_expect_success 'setup for update-server-info' '
587 git init update-server-info &&
588 test_commit -C update-server-info message
591 test_server_info_present () {
592 test_path_is_file update-server-info/.git/objects/info/packs &&
593 test_path_is_file update-server-info/.git/info/refs
596 test_server_info_missing () {
597 test_path_is_missing update-server-info/.git/objects/info/packs &&
598 test_path_is_missing update-server-info/.git/info/refs
601 test_server_info_cleanup () {
602 rm -f update-server-info/.git/objects/info/packs update-server-info/.git/info/refs &&
603 test_server_info_missing
606 test_expect_success 'updates server info by default' '
607 test_server_info_cleanup &&
608 git -C update-server-info repack &&
609 test_server_info_present
612 test_expect_success '-n skips updating server info' '
613 test_server_info_cleanup &&
614 git -C update-server-info repack -n &&
615 test_server_info_missing
618 test_expect_success 'repack.updateServerInfo=true updates server info' '
619 test_server_info_cleanup &&
620 git -C update-server-info -c repack.updateServerInfo=true repack &&
621 test_server_info_present
624 test_expect_success 'repack.updateServerInfo=false skips updating server info' '
625 test_server_info_cleanup &&
626 git -C update-server-info -c repack.updateServerInfo=false repack &&
627 test_server_info_missing
630 test_expect_success '-n overrides repack.updateServerInfo=true' '
631 test_server_info_cleanup &&
632 git -C update-server-info -c repack.updateServerInfo=true repack -n &&
633 test_server_info_missing
636 test_expect_success '--expire-to stores pruned objects (now)' '
637 git init expire-to-now &&
639 cd expire-to-now &&
641 git branch -M main &&
643 test_commit base &&
645 git checkout -b cruft &&
646 test_commit --no-tag cruft &&
648 git rev-list --objects --no-object-names main..cruft >moved.raw &&
649 sort moved.raw >moved.want &&
651 git rev-list --all --objects --no-object-names >expect.raw &&
652 sort expect.raw >expect &&
654 git checkout main &&
655 git branch -D cruft &&
656 git reflog expire --all --expire=all &&
658 git init --bare expired.git &&
659 git repack -d \
660 --cruft --cruft-expiration="now" \
661 --expire-to="expired.git/objects/pack/pack" &&
663 expired="$(ls expired.git/objects/pack/pack-*.idx)" &&
664 test_path_is_file "${expired%.idx}.mtimes" &&
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 &&
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 &&
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
687 test_expect_success '--expire-to stores pruned objects (5.minutes.ago)' '
688 git init expire-to-5.minutes.ago &&
690 cd expire-to-5.minutes.ago &&
692 git branch -M main &&
694 test_commit base &&
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
701 git checkout -b $kind main &&
702 test_commit --no-tag $kind || return 1
703 done &&
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)" &&
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 &&
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 &&
719 git checkout main &&
720 git branch -D stale recent &&
721 git reflog expire --all --expire=all &&
722 git prune-packed &&
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" &&
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 &&
738 cd expired.git &&
740 expired="$(ls objects/pack/pack-*.mtimes)" &&
741 test-tool pack-mtimes $(basename $expired) >out &&
742 cut -d" " -f1 out | sort >../moved.got &&
744 # Ensure that there are as many objects with the
745 # expected mtime as were moved to expired.git.
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
757 test_done