t5325: mark as leak-free
[git.git] / t / t5325-reverse-index.sh
blob48c14d85764fff3e431a8722d87dd427399bc067
1 #!/bin/sh
3 test_description='on-disk reverse index'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 # The below tests want control over the 'pack.writeReverseIndex' setting
9 # themselves to assert various combinations of it with other options.
10 sane_unset GIT_TEST_WRITE_REV_INDEX
12 packdir=.git/objects/pack
14 test_expect_success 'setup' '
15 test_commit base &&
17 pack=$(git pack-objects --all $packdir/pack) &&
18 rev=$packdir/pack-$pack.rev &&
20 test_path_is_missing $rev
23 test_index_pack () {
24 rm -f $rev &&
25 conf=$1 &&
26 shift &&
27 # remove the index since Windows won't overwrite an existing file
28 rm $packdir/pack-$pack.idx &&
29 git -c pack.writeReverseIndex=$conf index-pack "$@" \
30 $packdir/pack-$pack.pack
33 test_expect_success 'index-pack with pack.writeReverseIndex' '
34 test_index_pack "" &&
35 test_path_is_missing $rev &&
37 test_index_pack false &&
38 test_path_is_missing $rev &&
40 test_index_pack true &&
41 test_path_is_file $rev
44 test_expect_success 'index-pack with --[no-]rev-index' '
45 for conf in "" true false
47 test_index_pack "$conf" --rev-index &&
48 test_path_exists $rev &&
50 test_index_pack "$conf" --no-rev-index &&
51 test_path_is_missing $rev || return 1
52 done
55 test_expect_success 'index-pack can verify reverse indexes' '
56 test_when_finished "rm -f $rev" &&
57 test_index_pack true &&
59 test_path_is_file $rev &&
60 git index-pack --rev-index --verify $packdir/pack-$pack.pack &&
62 # Intentionally corrupt the reverse index.
63 chmod u+w $rev &&
64 printf "xxxx" | dd of=$rev bs=1 count=4 conv=notrunc &&
66 test_must_fail git index-pack --rev-index --verify \
67 $packdir/pack-$pack.pack 2>err &&
68 grep "validation error" err
71 test_expect_success 'index-pack infers reverse index name with -o' '
72 git index-pack --rev-index -o other.idx $packdir/pack-$pack.pack &&
73 test_path_is_file other.idx &&
74 test_path_is_file other.rev
77 test_expect_success 'pack-objects respects pack.writeReverseIndex' '
78 test_when_finished "rm -fr pack-1-*" &&
80 git -c pack.writeReverseIndex= pack-objects --all pack-1 &&
81 test_path_is_missing pack-1-*.rev &&
83 git -c pack.writeReverseIndex=false pack-objects --all pack-1 &&
84 test_path_is_missing pack-1-*.rev &&
86 git -c pack.writeReverseIndex=true pack-objects --all pack-1 &&
87 test_path_is_file pack-1-*.rev
90 test_expect_success 'reverse index is not generated when available on disk' '
91 test_index_pack true &&
92 test_path_is_file $rev &&
94 git rev-parse HEAD >tip &&
95 GIT_TEST_REV_INDEX_DIE_IN_MEMORY=1 git cat-file \
96 --batch-check="%(objectsize:disk)" <tip
99 test_expect_success 'revindex in-memory vs on-disk' '
100 git init repo &&
101 test_when_finished "rm -fr repo" &&
103 cd repo &&
105 test_commit commit &&
107 git rev-list --objects --no-object-names --all >objects &&
109 git -c pack.writeReverseIndex=false repack -ad &&
110 test_path_is_missing $packdir/pack-*.rev &&
111 git cat-file --batch-check="%(objectsize:disk) %(objectname)" \
112 <objects >in-core &&
114 git -c pack.writeReverseIndex=true repack -ad &&
115 test_path_is_file $packdir/pack-*.rev &&
116 git cat-file --batch-check="%(objectsize:disk) %(objectname)" \
117 <objects >on-disk &&
119 test_cmp on-disk in-core
122 test_done