]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1700-split-index.sh
Merge branch 'tb/char-may-be-unsigned'
[thirdparty/git.git] / t / t1700-split-index.sh
CommitLineData
3e52f70b
NTND
1#!/bin/sh
2
3test_description='split index mode tests'
4
5. ./test-lib.sh
6
7# We need total control of index splitting here
8sane_unset GIT_TEST_SPLIT_INDEX
c780b9cf
BP
9
10# Testing a hard coded SHA against an index with an extension
11# that can vary from run to run is problematic so we disable
12# those extensions.
4cb54d0a 13sane_unset GIT_TEST_FSMONITOR
c780b9cf 14sane_unset GIT_TEST_INDEX_THREADS
3e52f70b 15
c6e5607c
SG
16# Create a file named as $1 with content read from stdin.
17# Set the file's mtime to a few seconds in the past to avoid racy situations.
18create_non_racy_file () {
19 cat >"$1" &&
20 test-tool chmtime =-5 "$1"
21}
22
3e52f70b 23test_expect_success 'enable split index' '
e6a1dd77 24 git config splitIndex.maxPercentChange 100 &&
3e52f70b 25 git update-index --split-index &&
8133061e 26 test-tool dump-split-index .git/index >actual &&
cc6f663d 27 indexversion=$(test-tool index-version <.git/index) &&
e869c5ea
TG
28 if test "$indexversion" = "4"
29 then
3b1d9e04
BP
30 own=3527df833c6c100d3d1d921a9a782d62a8be4b58
31 base=746f7ab2ed44fb839efdfbffcf399d0b113fb4cb
e869c5ea 32 else
3b1d9e04
BP
33 own=5e9b60117ece18da410ddecc8b8d43766a0e4204
34 base=4370042739b31cd17a5c5cd6043a77c9a00df113
e869c5ea 35 fi &&
56621763
CC
36 cat >expect <<-EOF &&
37 own $own
38 base $base
39 replacements:
40 deletions:
41 EOF
3e52f70b
NTND
42 test_cmp expect actual
43'
44
45test_expect_success 'add one file' '
c6e5607c 46 create_non_racy_file one &&
3e52f70b
NTND
47 git update-index --add one &&
48 git ls-files --stage >ls-files.actual &&
56621763
CC
49 cat >ls-files.expect <<-EOF &&
50 100644 $EMPTY_BLOB 0 one
51 EOF
3e52f70b
NTND
52 test_cmp ls-files.expect ls-files.actual &&
53
8133061e 54 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
56621763
CC
55 cat >expect <<-EOF &&
56 base $base
57 100644 $EMPTY_BLOB 0 one
58 replacements:
59 deletions:
60 EOF
3e52f70b
NTND
61 test_cmp expect actual
62'
63
64test_expect_success 'disable split index' '
65 git update-index --no-split-index &&
66 git ls-files --stage >ls-files.actual &&
56621763
CC
67 cat >ls-files.expect <<-EOF &&
68 100644 $EMPTY_BLOB 0 one
69 EOF
3e52f70b
NTND
70 test_cmp ls-files.expect ls-files.actual &&
71
acdee9e9 72 BASE=$(test-tool dump-split-index .git/index | sed -n "s/^own/base/p") &&
8133061e 73 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
56621763
CC
74 cat >expect <<-EOF &&
75 not a split index
76 EOF
3e52f70b
NTND
77 test_cmp expect actual
78'
79
80test_expect_success 'enable split index again, "one" now belongs to base index"' '
81 git update-index --split-index &&
82 git ls-files --stage >ls-files.actual &&
56621763
CC
83 cat >ls-files.expect <<-EOF &&
84 100644 $EMPTY_BLOB 0 one
85 EOF
3e52f70b
NTND
86 test_cmp ls-files.expect ls-files.actual &&
87
8133061e 88 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
56621763
CC
89 cat >expect <<-EOF &&
90 $BASE
91 replacements:
92 deletions:
93 EOF
3e52f70b
NTND
94 test_cmp expect actual
95'
96
97test_expect_success 'modify original file, base index untouched' '
c6e5607c 98 echo modified | create_non_racy_file one &&
3e52f70b
NTND
99 git update-index one &&
100 git ls-files --stage >ls-files.actual &&
56621763
CC
101 cat >ls-files.expect <<-EOF &&
102 100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0 one
103 EOF
3e52f70b
NTND
104 test_cmp ls-files.expect ls-files.actual &&
105
8133061e 106 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
56621763
CC
107 q_to_tab >expect <<-EOF &&
108 $BASE
109 100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q
110 replacements: 0
111 deletions:
112 EOF
3e52f70b
NTND
113 test_cmp expect actual
114'
115
116test_expect_success 'add another file, which stays index' '
c6e5607c 117 create_non_racy_file two &&
3e52f70b
NTND
118 git update-index --add two &&
119 git ls-files --stage >ls-files.actual &&
56621763
CC
120 cat >ls-files.expect <<-EOF &&
121 100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0 one
122 100644 $EMPTY_BLOB 0 two
123 EOF
3e52f70b
NTND
124 test_cmp ls-files.expect ls-files.actual &&
125
8133061e 126 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
56621763
CC
127 q_to_tab >expect <<-EOF &&
128 $BASE
129 100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q
130 100644 $EMPTY_BLOB 0 two
131 replacements: 0
132 deletions:
133 EOF
3e52f70b
NTND
134 test_cmp expect actual
135'
136
137test_expect_success 'remove file not in base index' '
138 git update-index --force-remove two &&
139 git ls-files --stage >ls-files.actual &&
56621763
CC
140 cat >ls-files.expect <<-EOF &&
141 100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0 one
142 EOF
3e52f70b
NTND
143 test_cmp ls-files.expect ls-files.actual &&
144
8133061e 145 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
56621763
CC
146 q_to_tab >expect <<-EOF &&
147 $BASE
148 100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q
149 replacements: 0
150 deletions:
151 EOF
3e52f70b
NTND
152 test_cmp expect actual
153'
154
155test_expect_success 'remove file in base index' '
156 git update-index --force-remove one &&
157 git ls-files --stage >ls-files.actual &&
1c5e94f4 158 test_must_be_empty ls-files.actual &&
3e52f70b 159
8133061e 160 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
56621763
CC
161 cat >expect <<-EOF &&
162 $BASE
163 replacements:
164 deletions: 0
165 EOF
3e52f70b
NTND
166 test_cmp expect actual
167'
168
169test_expect_success 'add original file back' '
c6e5607c 170 create_non_racy_file one &&
3e52f70b
NTND
171 git update-index --add one &&
172 git ls-files --stage >ls-files.actual &&
56621763
CC
173 cat >ls-files.expect <<-EOF &&
174 100644 $EMPTY_BLOB 0 one
175 EOF
3e52f70b
NTND
176 test_cmp ls-files.expect ls-files.actual &&
177
8133061e 178 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
56621763
CC
179 cat >expect <<-EOF &&
180 $BASE
181 100644 $EMPTY_BLOB 0 one
182 replacements:
183 deletions: 0
184 EOF
3e52f70b
NTND
185 test_cmp expect actual
186'
187
188test_expect_success 'add new file' '
c6e5607c 189 create_non_racy_file two &&
3e52f70b
NTND
190 git update-index --add two &&
191 git ls-files --stage >actual &&
56621763
CC
192 cat >expect <<-EOF &&
193 100644 $EMPTY_BLOB 0 one
194 100644 $EMPTY_BLOB 0 two
195 EOF
3e52f70b
NTND
196 test_cmp expect actual
197'
198
199test_expect_success 'unify index, two files remain' '
200 git update-index --no-split-index &&
201 git ls-files --stage >ls-files.actual &&
56621763
CC
202 cat >ls-files.expect <<-EOF &&
203 100644 $EMPTY_BLOB 0 one
204 100644 $EMPTY_BLOB 0 two
205 EOF
8fb26872 206 test_cmp ls-files.expect ls-files.actual &&
3e52f70b 207
8133061e 208 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
56621763
CC
209 cat >expect <<-EOF &&
210 not a split index
211 EOF
3e52f70b
NTND
212 test_cmp expect actual
213'
214
098aa867 215test_expect_success 'rev-parse --shared-index-path' '
5de8a549
MR
216 test_create_repo split-index &&
217 (
218 cd split-index &&
219 git update-index --split-index &&
220 echo .git/sharedindex* >expect &&
221 git rev-parse --shared-index-path >actual &&
222 test_cmp expect actual &&
223 mkdir subdirectory &&
224 cd subdirectory &&
225 echo ../.git/sharedindex* >expect &&
226 git rev-parse --shared-index-path >actual &&
227 test_cmp expect actual
228 )
229'
230
b8923bf6
CC
231test_expect_success 'set core.splitIndex config variable to true' '
232 git config core.splitIndex true &&
c6e5607c 233 create_non_racy_file three &&
b8923bf6
CC
234 git update-index --add three &&
235 git ls-files --stage >ls-files.actual &&
236 cat >ls-files.expect <<-EOF &&
237 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one
238 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 three
239 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 two
240 EOF
241 test_cmp ls-files.expect ls-files.actual &&
8133061e
NTND
242 BASE=$(test-tool dump-split-index .git/index | grep "^base") &&
243 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
b8923bf6
CC
244 cat >expect <<-EOF &&
245 $BASE
246 replacements:
247 deletions:
248 EOF
249 test_cmp expect actual
250'
251
252test_expect_success 'set core.splitIndex config variable to false' '
253 git config core.splitIndex false &&
254 git update-index --force-remove three &&
255 git ls-files --stage >ls-files.actual &&
256 cat >ls-files.expect <<-EOF &&
257 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one
258 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 two
259 EOF
260 test_cmp ls-files.expect ls-files.actual &&
8133061e 261 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
b8923bf6
CC
262 cat >expect <<-EOF &&
263 not a split index
264 EOF
265 test_cmp expect actual
266'
267
c6e5607c 268test_expect_success 'set core.splitIndex config variable back to true' '
fcdbd954 269 git config core.splitIndex true &&
c6e5607c 270 create_non_racy_file three &&
fcdbd954 271 git update-index --add three &&
8133061e
NTND
272 BASE=$(test-tool dump-split-index .git/index | grep "^base") &&
273 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
fcdbd954
CC
274 cat >expect <<-EOF &&
275 $BASE
276 replacements:
277 deletions:
278 EOF
279 test_cmp expect actual &&
c6e5607c 280 create_non_racy_file four &&
fcdbd954 281 git update-index --add four &&
8133061e 282 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
fcdbd954
CC
283 cat >expect <<-EOF &&
284 $BASE
285 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 four
286 replacements:
287 deletions:
288 EOF
289 test_cmp expect actual
290'
291
292test_expect_success 'check behavior with splitIndex.maxPercentChange unset' '
293 git config --unset splitIndex.maxPercentChange &&
c6e5607c 294 create_non_racy_file five &&
fcdbd954 295 git update-index --add five &&
8133061e
NTND
296 BASE=$(test-tool dump-split-index .git/index | grep "^base") &&
297 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
fcdbd954
CC
298 cat >expect <<-EOF &&
299 $BASE
300 replacements:
301 deletions:
302 EOF
303 test_cmp expect actual &&
c6e5607c 304 create_non_racy_file six &&
fcdbd954 305 git update-index --add six &&
8133061e 306 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
fcdbd954
CC
307 cat >expect <<-EOF &&
308 $BASE
309 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 six
310 replacements:
311 deletions:
312 EOF
313 test_cmp expect actual
314'
315
316test_expect_success 'check splitIndex.maxPercentChange set to 0' '
317 git config splitIndex.maxPercentChange 0 &&
c6e5607c 318 create_non_racy_file seven &&
fcdbd954 319 git update-index --add seven &&
8133061e
NTND
320 BASE=$(test-tool dump-split-index .git/index | grep "^base") &&
321 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
fcdbd954
CC
322 cat >expect <<-EOF &&
323 $BASE
324 replacements:
325 deletions:
326 EOF
327 test_cmp expect actual &&
c6e5607c 328 create_non_racy_file eight &&
fcdbd954 329 git update-index --add eight &&
8133061e
NTND
330 BASE=$(test-tool dump-split-index .git/index | grep "^base") &&
331 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
fcdbd954
CC
332 cat >expect <<-EOF &&
333 $BASE
334 replacements:
335 deletions:
336 EOF
337 test_cmp expect actual
338'
339
c0441f7e 340test_expect_success 'shared index files expire after 2 weeks by default' '
c6e5607c 341 create_non_racy_file ten &&
c0441f7e 342 git update-index --add ten &&
c3a00825 343 test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
c0441f7e 344 just_under_2_weeks_ago=$((5-14*86400)) &&
0e496492 345 test-tool chmtime =$just_under_2_weeks_ago .git/sharedindex.* &&
c6e5607c 346 create_non_racy_file eleven &&
c0441f7e 347 git update-index --add eleven &&
c3a00825 348 test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
c0441f7e 349 just_over_2_weeks_ago=$((-1-14*86400)) &&
0e496492 350 test-tool chmtime =$just_over_2_weeks_ago .git/sharedindex.* &&
c6e5607c 351 create_non_racy_file twelve &&
c0441f7e 352 git update-index --add twelve &&
c3a00825 353 test $(ls .git/sharedindex.* | wc -l) -le 2
c0441f7e
CC
354'
355
356test_expect_success 'check splitIndex.sharedIndexExpire set to 16 days' '
357 git config splitIndex.sharedIndexExpire "16.days.ago" &&
0e496492 358 test-tool chmtime =$just_over_2_weeks_ago .git/sharedindex.* &&
c6e5607c 359 create_non_racy_file thirteen &&
c0441f7e 360 git update-index --add thirteen &&
c3a00825 361 test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
c0441f7e 362 just_over_16_days_ago=$((-1-16*86400)) &&
0e496492 363 test-tool chmtime =$just_over_16_days_ago .git/sharedindex.* &&
c6e5607c 364 create_non_racy_file fourteen &&
c0441f7e 365 git update-index --add fourteen &&
c3a00825 366 test $(ls .git/sharedindex.* | wc -l) -le 2
c0441f7e
CC
367'
368
369test_expect_success 'check splitIndex.sharedIndexExpire set to "never" and "now"' '
370 git config splitIndex.sharedIndexExpire never &&
371 just_10_years_ago=$((-365*10*86400)) &&
0e496492 372 test-tool chmtime =$just_10_years_ago .git/sharedindex.* &&
c6e5607c 373 create_non_racy_file fifteen &&
c0441f7e 374 git update-index --add fifteen &&
c3a00825 375 test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
c0441f7e
CC
376 git config splitIndex.sharedIndexExpire now &&
377 just_1_second_ago=-1 &&
0e496492 378 test-tool chmtime =$just_1_second_ago .git/sharedindex.* &&
c6e5607c 379 create_non_racy_file sixteen &&
c0441f7e 380 git update-index --add sixteen &&
c3a00825 381 test $(ls .git/sharedindex.* | wc -l) -le 2
c0441f7e
CC
382'
383
3ee83f48
CC
384while read -r mode modebits
385do
386 test_expect_success POSIXPERM "split index respects core.sharedrepository $mode" '
387 # Remove existing shared index files
388 git config core.splitIndex false &&
389 git update-index --force-remove one &&
390 rm -f .git/sharedindex.* &&
391 # Create one new shared index file
392 git config core.sharedrepository "$mode" &&
393 git config core.splitIndex true &&
c6e5607c 394 create_non_racy_file one &&
3ee83f48
CC
395 git update-index --add one &&
396 echo "$modebits" >expect &&
397 test_modebits .git/index >actual &&
398 test_cmp expect actual &&
399 shared=$(ls .git/sharedindex.*) &&
400 case "$shared" in
401 *" "*)
402 # we have more than one???
403 false ;;
404 *)
405 test_modebits "$shared" >actual &&
406 test_cmp expect actual ;;
407 esac
408 '
409done <<\EOF
4100666 -rw-rw-rw-
4110642 -rw-r---w-
412EOF
413
ef5b3a6c
NTND
414test_expect_success POSIXPERM,SANITY 'graceful handling when splitting index is not allowed' '
415 test_create_repo ro &&
416 (
417 cd ro &&
418 test_commit initial &&
419 git update-index --split-index &&
420 test -f .git/sharedindex.*
421 ) &&
422 cp ro/.git/index new-index &&
423 test_when_finished "chmod u+w ro/.git" &&
424 chmod u-w ro/.git &&
425 GIT_INDEX_FILE="$(pwd)/new-index" git -C ro update-index --split-index &&
426 chmod u+w ro/.git &&
427 rm ro/.git/sharedindex.* &&
428 GIT_INDEX_FILE=new-index git ls-files >actual &&
429 echo initial.t >expected &&
430 test_cmp expected actual
431'
432
4bddd983
TG
433test_expect_success 'writing split index with null sha1 does not write cache tree' '
434 git config core.splitIndex true &&
435 git config splitIndex.maxPercentChange 0 &&
436 git commit -m "commit" &&
437 {
438 git ls-tree HEAD &&
8125a58b 439 printf "160000 commit $ZERO_OID\\tbroken\\n"
4bddd983
TG
440 } >broken-tree &&
441 echo "add broken entry" >msg &&
442
443 tree=$(git mktree <broken-tree) &&
444 test_tick &&
445 commit=$(git commit-tree $tree -p HEAD <msg) &&
446 git update-ref HEAD "$commit" &&
447 GIT_ALLOW_NULL_SHA1=1 git reset --hard &&
83279748 448 test_might_fail test-tool dump-cache-tree >cache-tree.out &&
4bddd983
TG
449 test_line_count = 0 cache-tree.out
450'
451
3e52f70b 452test_done