]>
Commit | Line | Data |
---|---|---|
136347d7 TG |
1 | #!/bin/sh |
2 | ||
3 | test_description='index file specific tests' | |
4 | ||
d96fb140 | 5 | TEST_PASSES_SANITIZE_LEAK=true |
136347d7 TG |
6 | . ./test-lib.sh |
7 | ||
daad41c9 SG |
8 | sane_unset GIT_TEST_SPLIT_INDEX |
9 | ||
136347d7 TG |
10 | test_expect_success 'setup' ' |
11 | echo 1 >a | |
12 | ' | |
13 | ||
14 | test_expect_success 'bogus GIT_INDEX_VERSION issues warning' ' | |
15 | ( | |
16 | rm -f .git/index && | |
17 | GIT_INDEX_VERSION=2bogus && | |
18 | export GIT_INDEX_VERSION && | |
bdfe1f0d SG |
19 | git add a 2>err && |
20 | sed "s/[0-9]//" err >actual.err && | |
136347d7 TG |
21 | sed -e "s/ Z$/ /" <<-\EOF >expect.err && |
22 | warning: GIT_INDEX_VERSION set, but the value is invalid. | |
23 | Using version Z | |
24 | EOF | |
1108cea7 | 25 | test_cmp expect.err actual.err |
136347d7 TG |
26 | ) |
27 | ' | |
28 | ||
29 | test_expect_success 'out of bounds GIT_INDEX_VERSION issues warning' ' | |
30 | ( | |
31 | rm -f .git/index && | |
32 | GIT_INDEX_VERSION=1 && | |
33 | export GIT_INDEX_VERSION && | |
bdfe1f0d SG |
34 | git add a 2>err && |
35 | sed "s/[0-9]//" err >actual.err && | |
136347d7 TG |
36 | sed -e "s/ Z$/ /" <<-\EOF >expect.err && |
37 | warning: GIT_INDEX_VERSION set, but the value is invalid. | |
38 | Using version Z | |
39 | EOF | |
1108cea7 | 40 | test_cmp expect.err actual.err |
136347d7 TG |
41 | ) |
42 | ' | |
43 | ||
44 | test_expect_success 'no warning with bogus GIT_INDEX_VERSION and existing index' ' | |
45 | ( | |
46 | GIT_INDEX_VERSION=1 && | |
47 | export GIT_INDEX_VERSION && | |
48 | git add a 2>actual.err && | |
1c5e94f4 | 49 | test_must_be_empty actual.err |
136347d7 TG |
50 | ) |
51 | ' | |
52 | ||
3c09d684 TG |
53 | test_expect_success 'out of bounds index.version issues warning' ' |
54 | ( | |
55 | sane_unset GIT_INDEX_VERSION && | |
56 | rm -f .git/index && | |
57 | git config --add index.version 1 && | |
bdfe1f0d SG |
58 | git add a 2>err && |
59 | sed "s/[0-9]//" err >actual.err && | |
3c09d684 TG |
60 | sed -e "s/ Z$/ /" <<-\EOF >expect.err && |
61 | warning: index.version set, but the value is invalid. | |
62 | Using version Z | |
63 | EOF | |
1108cea7 | 64 | test_cmp expect.err actual.err |
3c09d684 TG |
65 | ) |
66 | ' | |
67 | ||
ee1f0c24 DS |
68 | test_expect_success 'index.skipHash config option' ' |
69 | rm -f .git/index && | |
70 | git -c index.skipHash=true add a && | |
da9acde1 DS |
71 | test_trailing_hash .git/index >hash && |
72 | echo $(test_oid zero) >expect && | |
73 | test_cmp expect hash && | |
ee1f0c24 DS |
74 | git fsck && |
75 | ||
17194b19 DS |
76 | rm -f .git/index && |
77 | git -c feature.manyFiles=true add a && | |
78 | test_trailing_hash .git/index >hash && | |
79 | cmp expect hash && | |
80 | ||
81 | rm -f .git/index && | |
82 | git -c feature.manyFiles=true \ | |
83 | -c index.skipHash=false add a && | |
84 | test_trailing_hash .git/index >hash && | |
85 | ! cmp expect hash && | |
86 | ||
ee1f0c24 DS |
87 | test_commit start && |
88 | git -c protocol.file.allow=always submodule add ./ sub && | |
89 | git config index.skipHash false && | |
90 | git -C sub config index.skipHash true && | |
42ea7a41 | 91 | rm -f .git/modules/sub/index && |
ee1f0c24 DS |
92 | >sub/file && |
93 | git -C sub add a && | |
da9acde1 DS |
94 | test_trailing_hash .git/modules/sub/index >hash && |
95 | test_cmp expect hash && | |
ee1f0c24 DS |
96 | git -C sub fsck |
97 | ' | |
98 | ||
c6cc4c5a DS |
99 | test_index_version () { |
100 | INDEX_VERSION_CONFIG=$1 && | |
101 | FEATURE_MANY_FILES=$2 && | |
102 | ENV_VAR_VERSION=$3 | |
103 | EXPECTED_OUTPUT_VERSION=$4 && | |
3c09d684 TG |
104 | ( |
105 | rm -f .git/index && | |
c6cc4c5a DS |
106 | rm -f .git/config && |
107 | if test "$INDEX_VERSION_CONFIG" -ne 0 | |
108 | then | |
109 | git config --add index.version $INDEX_VERSION_CONFIG | |
110 | fi && | |
111 | git config --add feature.manyFiles $FEATURE_MANY_FILES | |
112 | if test "$ENV_VAR_VERSION" -ne 0 | |
113 | then | |
114 | GIT_INDEX_VERSION=$ENV_VAR_VERSION && | |
115 | export GIT_INDEX_VERSION | |
116 | else | |
117 | unset GIT_INDEX_VERSION | |
118 | fi && | |
c3442568 | 119 | git add a && |
c6cc4c5a | 120 | echo $EXPECTED_OUTPUT_VERSION >expect && |
cc6f663d | 121 | test-tool index-version <.git/index >actual && |
3c09d684 TG |
122 | test_cmp expect actual |
123 | ) | |
c6cc4c5a DS |
124 | } |
125 | ||
126 | test_expect_success 'index version config precedence' ' | |
c11e9966 DS |
127 | test_index_version 0 false 0 2 && |
128 | test_index_version 2 false 0 2 && | |
129 | test_index_version 3 false 0 2 && | |
130 | test_index_version 4 false 0 4 && | |
c6cc4c5a DS |
131 | test_index_version 2 false 4 4 && |
132 | test_index_version 2 true 0 2 && | |
133 | test_index_version 0 true 0 4 && | |
134 | test_index_version 0 true 2 2 | |
3c09d684 TG |
135 | ' |
136 | ||
136347d7 | 137 | test_done |