t: support GIT_TEST_WRITE_REV_INDEX
[alt-git.git] / t / t5325-reverse-index.sh
blobbe452bb3434a0edb259dbc9db795ef094d7f8d23
1 #!/bin/sh
3 test_description='on-disk reverse index'
4 . ./test-lib.sh
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
10 packdir=.git/objects/pack
12 test_expect_success 'setup' '
13 test_commit base &&
15 pack=$(git pack-objects --all $packdir/pack) &&
16 rev=$packdir/pack-$pack.rev &&
18 test_path_is_missing $rev
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
31 test_expect_success 'index-pack with pack.writeReverseIndex' '
32 test_index_pack "" &&
33 test_path_is_missing $rev &&
35 test_index_pack false &&
36 test_path_is_missing $rev &&
38 test_index_pack true &&
39 test_path_is_file $rev
42 test_expect_success 'index-pack with --[no-]rev-index' '
43 for conf in "" true false
45 test_index_pack "$conf" --rev-index &&
46 test_path_exists $rev &&
48 test_index_pack "$conf" --no-rev-index &&
49 test_path_is_missing $rev
50 done
53 test_expect_success 'index-pack can verify reverse indexes' '
54 test_when_finished "rm -f $rev" &&
55 test_index_pack true &&
57 test_path_is_file $rev &&
58 git index-pack --rev-index --verify $packdir/pack-$pack.pack &&
60 # Intentionally corrupt the reverse index.
61 chmod u+w $rev &&
62 printf "xxxx" | dd of=$rev bs=1 count=4 conv=notrunc &&
64 test_must_fail git index-pack --rev-index --verify \
65 $packdir/pack-$pack.pack 2>err &&
66 grep "validation error" err
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
75 test_expect_success 'pack-objects respects pack.writeReverseIndex' '
76 test_when_finished "rm -fr pack-1-*" &&
78 git -c pack.writeReverseIndex= pack-objects --all pack-1 &&
79 test_path_is_missing pack-1-*.rev &&
81 git -c pack.writeReverseIndex=false pack-objects --all pack-1 &&
82 test_path_is_missing pack-1-*.rev &&
84 git -c pack.writeReverseIndex=true pack-objects --all pack-1 &&
85 test_path_is_file pack-1-*.rev
88 test_done