Skip to content

Commit f148620

Browse files
derrickstoleettaylorr
authored andcommitted
t7700: check post-condition in kept-pack test
The '--write-midx -b packs non-kept objects' test in t7700-repack.sh uses test_subcommand_inexact to check that 'git repack' properly adds the '--honor-pack-keep' flag to the 'git pack-objects' subcommand. However, the test_subcommand_inexact helper is more flexible than initially designed, and this instance is the only one that makes use of it: there are additional arguments between 'git pack-objects' and the '--honor-pack-keep' flag. In order to make test_subcommand_inexact more strict, we need to fix this instance. This test checks that 'git repack --write-midx -a -b -d' will create a new pack-file that does not contain the objects within the kept pack. This behavior is possible because of the multi-pack-index bitmap that will bitmap objects against multiple packs. Without --write-midx, the objects in the kept pack would be duplicated so the resulting pack is closed under reachability and bitmaps can be created against it. This is discussed in more detail in e4d0c11 (repack: respect kept objects with '--write-midx -b', 2021-12-20) which also introduced this instance of test_subcommand_inexact. To better verify the intended post-conditions while also removing this instance of test_subcommand_inexact, rewrite the test to check the list of packed objects in the kept pack and the list of the objects in the newly-repacked pack-file _other_ than the kept pack. These lists should be disjoint. Be sure to include a non-kept pack-file and loose objects to be extra careful that this is properly behaving with kept packs and not just avoiding repacking all pack-files. Co-authored-by: Taylor Blau <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a68dfad commit f148620

File tree

1 file changed

+54
-3
lines changed

1 file changed

+54
-3
lines changed

t/t7700-repack.sh

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,61 @@ test_expect_success '--write-midx with preferred bitmap tips' '
369369
)
370370
'
371371

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
375+
# into stdout.
376+
get_sorted_objects_from_pack () {
377+
git show-index <$(cat "$1") >raw &&
378+
cut -d" " -f2 raw
379+
}
380+
372381
test_expect_success '--write-midx -b packs non-kept objects' '
373-
GIT_TRACE2_EVENT="$(pwd)/trace.txt" \
374-
git repack --write-midx -a -b &&
375-
test_subcommand_inexact git pack-objects --honor-pack-keep <trace.txt
382+
git init repo &&
383+
test_when_finished "rm -fr repo" &&
384+
(
385+
cd repo &&
386+
387+
# Create a kept pack-file
388+
test_commit base &&
389+
git repack -ad &&
390+
find $objdir/pack -name "*.idx" >before &&
391+
test_line_count = 1 before &&
392+
before_name=$(cat before) &&
393+
>${before_name%.idx}.keep &&
394+
395+
# Create a non-kept pack-file
396+
test_commit other &&
397+
git repack &&
398+
399+
# Create loose objects
400+
test_commit loose &&
401+
402+
# Repack everything
403+
git repack --write-midx -a -b -d &&
404+
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 &&
413+
414+
# Get object list from the kept pack.
415+
get_sorted_objects_from_pack before >old.objects &&
416+
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 &&
421+
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
426+
)
376427
'
377428

378429
test_expect_success TTY '--quiet disables progress' '

0 commit comments

Comments
 (0)