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