interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t1600-index.sh

237 lines · 6453 bytes Raw Blame History
1#!/bin/sh
2
3test_description='index file specific tests'
4
5. ./test-lib.sh
6
7sane_unset GIT_TEST_SPLIT_INDEX
8
9test_expect_success 'setup' '
10 echo 1 >a
11'
12
13test_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
28test_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
43test_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
52test_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
67test_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
98test_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
125test_expect_success 'cache entry with a representable name length is accepted' '
126 test-tool cache-entry 100 >actual &&
127 test_grep "^ok: allocated cache entry for namelen 100" actual
128'
129
130test_expect_success SIZE_T_IS_64BIT \
131 'over-long cache entry name length is rejected rather than truncated' '
132 # 4294967296 == 2^32
133 test_must_fail test-tool cache-entry 4294967296 2>err &&
134 test_grep "index entry path is too long" err
135'
136
137test_expect_success 'path length enforced from filesystem to index' '
138 name=a-somewhat-long-path-name &&
139 echo foo >"$name" &&
140 test_must_fail git -c index.maxPathLen=10 add "$name" 2>err &&
141 test_grep "invalid path" err
142'
143
144test_expect_success 'path length enforced from tree to index' '
145 name=a-somewhat-long-path-name &&
146 echo foo >"$name" &&
147 git add "$name" &&
148 git commit -m long-path &&
149 test_when_finished "rm -rf long-clone.git" &&
150 test_must_fail git -c index.maxPathLen=10 clone . long-clone.git 2>err &&
151 test_grep "invalid path" err
152'
153
154test_expect_success 'index.maxPathLen rejects out-of-range values' '
155 test_must_fail git -c index.maxPathLen=-1 status 2>err &&
156 test_grep "bad numeric config value" err &&
157 test_must_fail git -c index.maxPathLen=2147483648 status 2>err &&
158 test_grep "exceeds maximum" err
159'
160
161make_large_tree () {
162 {
163 printf "100644 " &&
164 test-tool genzeros "$1" | tr "\000" a &&
165 printf "\0" &&
166 test-tool genzeros "$(test_oid rawsz)"
167 } >"tree-$1" &&
168 git hash-object --literally -w -t tree "tree-$1"
169}
170
171check_overlong_tree () {
172 test_must_fail git -C overlong "$@" >actual 2>err &&
173 test_cmp expect-overlong err &&
174 test_must_be_empty actual
175}
176
177test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,LONG_IS_64BIT \
178 "set up a tree path whose length wraps to a small int" '
179 test_create_repo overlong &&
180 (
181 cd overlong &&
182 subtree=$(make_large_tree 4294967294) &&
183 printf "040000 tree %s\tabc\n" "$subtree" |
184 git mktree >tree
185 ) &&
186 overlong_tree=$(cat overlong/tree) &&
187 echo "fatal: index entry path is too long" \
188 "(4294967298 bytes)" >expect-overlong
189'
190
191test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,LONG_IS_64BIT \
192 "checkout rejects a path before its length is truncated" '
193 check_overlong_tree checkout "$overlong_tree" -- :/
194'
195
196test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,LONG_IS_64BIT \
197 "restore rejects a path before its length is truncated" '
198 check_overlong_tree restore --source="$overlong_tree" --staged -- :/
199'
200
201test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,LONG_IS_64BIT \
202 "ls-files rejects a path before its length is truncated" '
203 check_overlong_tree ls-files --with-tree="$overlong_tree"
204'
205
206test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,LONG_IS_64BIT \
207 "clean up the large tree" '
208 rm -rf overlong
209'
210
211test_expect_success EXPENSIVE,SIZE_T_IS_64BIT \
212 "ls-files includes the terminator without signed overflow" '
213 test_create_repo boundary &&
214 test_when_finished "rm -rf boundary" &&
215 (
216 cd boundary &&
217 make_large_tree 2147483647 >tree
218 ) &&
219 echo 100644 >expect &&
220 git -C boundary ls-files --with-tree="$(cat boundary/tree)" \
221 --format="%(objectmode)" >actual &&
222 test_cmp expect actual
223'
224
225# This must be the last test case because it deletes .git/config
226test_expect_success 'index version config precedence' '
227 test_index_version 0 false 0 2 &&
228 test_index_version 2 false 0 2 &&
229 test_index_version 3 false 0 2 &&
230 test_index_version 4 false 0 4 &&
231 test_index_version 2 false 4 4 &&
232 test_index_version 2 true 0 2 &&
233 test_index_version 0 true 0 4 &&
234 test_index_version 0 true 2 2
235'
236
237test_done