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