config: enable `pack.writeReverseIndex` by default
[git.git] / t / t5325-reverse-index.sh
blob149dcf5193bf35acf98b30198851db756fe7a44b
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 test_config pack.writeReverseIndex false &&
18 pack=$(git pack-objects --all $packdir/pack) &&
19 rev=$packdir/pack-$pack.rev &&
21 test_path_is_missing $rev
24 test_index_pack () {
25 rm -f $rev &&
26 conf=$1 &&
27 shift &&
28 # remove the index since Windows won't overwrite an existing file
29 rm $packdir/pack-$pack.idx &&
30 git -c pack.writeReverseIndex=$conf index-pack "$@" \
31 $packdir/pack-$pack.pack
34 test_expect_success 'index-pack with pack.writeReverseIndex' '
35 test_index_pack "" &&
36 test_path_is_missing $rev &&
38 test_index_pack false &&
39 test_path_is_missing $rev &&
41 test_index_pack true &&
42 test_path_is_file $rev
45 test_expect_success 'index-pack with --[no-]rev-index' '
46 for conf in "" true false
48 test_index_pack "$conf" --rev-index &&
49 test_path_exists $rev &&
51 test_index_pack "$conf" --no-rev-index &&
52 test_path_is_missing $rev || return 1
53 done
56 test_expect_success 'index-pack can verify reverse indexes' '
57 test_when_finished "rm -f $rev" &&
58 test_index_pack true &&
60 test_path_is_file $rev &&
61 git index-pack --rev-index --verify $packdir/pack-$pack.pack &&
63 # Intentionally corrupt the reverse index.
64 chmod u+w $rev &&
65 printf "xxxx" | dd of=$rev bs=1 count=4 conv=notrunc &&
67 test_must_fail git index-pack --rev-index --verify \
68 $packdir/pack-$pack.pack 2>err &&
69 grep "validation error" err
72 test_expect_success 'index-pack infers reverse index name with -o' '
73 git index-pack --rev-index -o other.idx $packdir/pack-$pack.pack &&
74 test_path_is_file other.idx &&
75 test_path_is_file other.rev
78 test_expect_success 'pack-objects respects pack.writeReverseIndex' '
79 test_when_finished "rm -fr pack-1-*" &&
81 git -c pack.writeReverseIndex= pack-objects --all pack-1 &&
82 test_path_is_missing pack-1-*.rev &&
84 git -c pack.writeReverseIndex=false pack-objects --all pack-1 &&
85 test_path_is_missing pack-1-*.rev &&
87 git -c pack.writeReverseIndex=true pack-objects --all pack-1 &&
88 test_path_is_file pack-1-*.rev
91 test_expect_success 'reverse index is not generated when available on disk' '
92 test_index_pack true &&
93 test_path_is_file $rev &&
95 git rev-parse HEAD >tip &&
96 GIT_TEST_REV_INDEX_DIE_IN_MEMORY=1 git cat-file \
97 --batch-check="%(objectsize:disk)" <tip
100 test_expect_success 'reverse index is ignored when pack.readReverseIndex is false' '
101 test_index_pack true &&
102 test_path_is_file $rev &&
104 test_config pack.readReverseIndex false &&
106 git rev-parse HEAD >tip &&
107 GIT_TEST_REV_INDEX_DIE_ON_DISK=1 git cat-file \
108 --batch-check="%(objectsize:disk)" <tip
111 test_expect_success 'revindex in-memory vs on-disk' '
112 git init repo &&
113 test_when_finished "rm -fr repo" &&
115 cd repo &&
117 test_commit commit &&
119 git rev-list --objects --no-object-names --all >objects &&
121 git -c pack.writeReverseIndex=false repack -ad &&
122 test_path_is_missing $packdir/pack-*.rev &&
123 git cat-file --batch-check="%(objectsize:disk) %(objectname)" \
124 <objects >in-core &&
126 git -c pack.writeReverseIndex=true repack -ad &&
127 test_path_is_file $packdir/pack-*.rev &&
128 git cat-file --batch-check="%(objectsize:disk) %(objectname)" \
129 <objects >on-disk &&
131 test_cmp on-disk in-core
134 test_done