blob: 12a556884427b87e8f3d6784ba638a446f6bf7c2 [file] [log] [blame]
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +07001#!/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
Ben Peartc780b9c2018-10-10 11:59:35 -04009
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.
Ben Peart4cb54d02018-09-18 23:29:35 +000013sane_unset GIT_TEST_FSMONITOR
Ben Peartc780b9c2018-10-10 11:59:35 -040014sane_unset GIT_TEST_INDEX_THREADS
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +070015
SZEDER Gáborc6e56072018-10-11 11:43:06 +020016# 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
brian m. carlsonbfefd522019-06-28 22:59:27 +000023test_expect_success 'setup' '
24 test_oid_cache <<-EOF
25 own_v3 sha1:8299b0bcd1ac364e5f1d7768efb62fa2da79a339
26 own_v3 sha256:38a6d2925e3eceec33ad7b34cbff4e0086caa0daf28f31e51f5bd94b4a7af86b
27
28 base_v3 sha1:39d890139ee5356c7ef572216cebcd27aa41f9df
29 base_v3 sha256:c9baeadf905112bf6c17aefbd7d02267afd70ded613c30cafed2d40cb506e1ed
30
31 own_v4 sha1:432ef4b63f32193984f339431fd50ca796493569
32 own_v4 sha256:6738ac6319c25b694afa7bcc313deb182d1a59b68bf7a47b4296de83478c0420
33
34 base_v4 sha1:508851a7f0dfa8691e9f69c7f055865389012491
35 base_v4 sha256:3177d4adfdd4b6904f7e921d91d715a471c0dde7cf6a4bba574927f02b699508
36 EOF
37'
38
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +070039test_expect_success 'enable split index' '
Christian Coudere6a1dd72017-02-27 19:00:08 +010040 git config splitIndex.maxPercentChange 100 &&
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +070041 git update-index --split-index &&
Nguyễn Thái Ngọc Duy81330612018-03-24 08:44:40 +010042 test-tool dump-split-index .git/index >actual &&
Nguyễn Thái Ngọc Duycc6f6632018-03-24 08:44:44 +010043 indexversion=$(test-tool index-version <.git/index) &&
Jonathan Niederd8465502018-11-19 22:11:47 -080044
45 # NEEDSWORK: Stop hard-coding checksums.
Thomas Gummerere869c5e2015-03-20 19:20:30 +010046 if test "$indexversion" = "4"
47 then
brian m. carlsonbfefd522019-06-28 22:59:27 +000048 own=$(test_oid own_v4)
49 base=$(test_oid base_v4)
Thomas Gummerere869c5e2015-03-20 19:20:30 +010050 else
brian m. carlsonbfefd522019-06-28 22:59:27 +000051 own=$(test_oid own_v3)
52 base=$(test_oid base_v3)
Thomas Gummerere869c5e2015-03-20 19:20:30 +010053 fi &&
Jonathan Niederd8465502018-11-19 22:11:47 -080054
Christian Couder56621762017-02-27 18:59:59 +010055 cat >expect <<-EOF &&
56 own $own
57 base $base
58 replacements:
59 deletions:
60 EOF
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +070061 test_cmp expect actual
62'
63
64test_expect_success 'add one file' '
SZEDER Gáborc6e56072018-10-11 11:43:06 +020065 create_non_racy_file one &&
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +070066 git update-index --add one &&
67 git ls-files --stage >ls-files.actual &&
Christian Couder56621762017-02-27 18:59:59 +010068 cat >ls-files.expect <<-EOF &&
69 100644 $EMPTY_BLOB 0 one
70 EOF
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +070071 test_cmp ls-files.expect ls-files.actual &&
72
Nguyễn Thái Ngọc Duy81330612018-03-24 08:44:40 +010073 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
Christian Couder56621762017-02-27 18:59:59 +010074 cat >expect <<-EOF &&
75 base $base
76 100644 $EMPTY_BLOB 0 one
77 replacements:
78 deletions:
79 EOF
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +070080 test_cmp expect actual
81'
82
83test_expect_success 'disable split index' '
84 git update-index --no-split-index &&
85 git ls-files --stage >ls-files.actual &&
Christian Couder56621762017-02-27 18:59:59 +010086 cat >ls-files.expect <<-EOF &&
87 100644 $EMPTY_BLOB 0 one
88 EOF
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +070089 test_cmp ls-files.expect ls-files.actual &&
90
SZEDER Gáboracdee9e2018-09-06 04:48:06 +020091 BASE=$(test-tool dump-split-index .git/index | sed -n "s/^own/base/p") &&
Nguyễn Thái Ngọc Duy81330612018-03-24 08:44:40 +010092 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
Christian Couder56621762017-02-27 18:59:59 +010093 cat >expect <<-EOF &&
94 not a split index
95 EOF
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +070096 test_cmp expect actual
97'
98
99test_expect_success 'enable split index again, "one" now belongs to base index"' '
100 git update-index --split-index &&
101 git ls-files --stage >ls-files.actual &&
Christian Couder56621762017-02-27 18:59:59 +0100102 cat >ls-files.expect <<-EOF &&
103 100644 $EMPTY_BLOB 0 one
104 EOF
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +0700105 test_cmp ls-files.expect ls-files.actual &&
106
Nguyễn Thái Ngọc Duy81330612018-03-24 08:44:40 +0100107 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
Christian Couder56621762017-02-27 18:59:59 +0100108 cat >expect <<-EOF &&
109 $BASE
110 replacements:
111 deletions:
112 EOF
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +0700113 test_cmp expect actual
114'
115
116test_expect_success 'modify original file, base index untouched' '
SZEDER Gáborc6e56072018-10-11 11:43:06 +0200117 echo modified | create_non_racy_file one &&
brian m. carlsonbfefd522019-06-28 22:59:27 +0000118 file1_blob=$(git hash-object one) &&
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +0700119 git update-index one &&
120 git ls-files --stage >ls-files.actual &&
Christian Couder56621762017-02-27 18:59:59 +0100121 cat >ls-files.expect <<-EOF &&
brian m. carlsonbfefd522019-06-28 22:59:27 +0000122 100644 $file1_blob 0 one
Christian Couder56621762017-02-27 18:59:59 +0100123 EOF
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +0700124 test_cmp ls-files.expect ls-files.actual &&
125
Nguyễn Thái Ngọc Duy81330612018-03-24 08:44:40 +0100126 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
Christian Couder56621762017-02-27 18:59:59 +0100127 q_to_tab >expect <<-EOF &&
128 $BASE
brian m. carlsonbfefd522019-06-28 22:59:27 +0000129 100644 $file1_blob 0Q
Christian Couder56621762017-02-27 18:59:59 +0100130 replacements: 0
131 deletions:
132 EOF
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +0700133 test_cmp expect actual
134'
135
136test_expect_success 'add another file, which stays index' '
SZEDER Gáborc6e56072018-10-11 11:43:06 +0200137 create_non_racy_file two &&
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +0700138 git update-index --add two &&
139 git ls-files --stage >ls-files.actual &&
Christian Couder56621762017-02-27 18:59:59 +0100140 cat >ls-files.expect <<-EOF &&
brian m. carlsonbfefd522019-06-28 22:59:27 +0000141 100644 $file1_blob 0 one
Christian Couder56621762017-02-27 18:59:59 +0100142 100644 $EMPTY_BLOB 0 two
143 EOF
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +0700144 test_cmp ls-files.expect ls-files.actual &&
145
Nguyễn Thái Ngọc Duy81330612018-03-24 08:44:40 +0100146 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
Christian Couder56621762017-02-27 18:59:59 +0100147 q_to_tab >expect <<-EOF &&
148 $BASE
brian m. carlsonbfefd522019-06-28 22:59:27 +0000149 100644 $file1_blob 0Q
Christian Couder56621762017-02-27 18:59:59 +0100150 100644 $EMPTY_BLOB 0 two
151 replacements: 0
152 deletions:
153 EOF
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +0700154 test_cmp expect actual
155'
156
157test_expect_success 'remove file not in base index' '
158 git update-index --force-remove two &&
159 git ls-files --stage >ls-files.actual &&
Christian Couder56621762017-02-27 18:59:59 +0100160 cat >ls-files.expect <<-EOF &&
brian m. carlsonbfefd522019-06-28 22:59:27 +0000161 100644 $file1_blob 0 one
Christian Couder56621762017-02-27 18:59:59 +0100162 EOF
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +0700163 test_cmp ls-files.expect ls-files.actual &&
164
Nguyễn Thái Ngọc Duy81330612018-03-24 08:44:40 +0100165 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
Christian Couder56621762017-02-27 18:59:59 +0100166 q_to_tab >expect <<-EOF &&
167 $BASE
brian m. carlsonbfefd522019-06-28 22:59:27 +0000168 100644 $file1_blob 0Q
Christian Couder56621762017-02-27 18:59:59 +0100169 replacements: 0
170 deletions:
171 EOF
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +0700172 test_cmp expect actual
173'
174
175test_expect_success 'remove file in base index' '
176 git update-index --force-remove one &&
177 git ls-files --stage >ls-files.actual &&
SZEDER Gábor1c5e94f2018-08-19 23:57:25 +0200178 test_must_be_empty ls-files.actual &&
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +0700179
Nguyễn Thái Ngọc Duy81330612018-03-24 08:44:40 +0100180 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
Christian Couder56621762017-02-27 18:59:59 +0100181 cat >expect <<-EOF &&
182 $BASE
183 replacements:
184 deletions: 0
185 EOF
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +0700186 test_cmp expect actual
187'
188
189test_expect_success 'add original file back' '
SZEDER Gáborc6e56072018-10-11 11:43:06 +0200190 create_non_racy_file one &&
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +0700191 git update-index --add one &&
192 git ls-files --stage >ls-files.actual &&
Christian Couder56621762017-02-27 18:59:59 +0100193 cat >ls-files.expect <<-EOF &&
194 100644 $EMPTY_BLOB 0 one
195 EOF
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +0700196 test_cmp ls-files.expect ls-files.actual &&
197
Nguyễn Thái Ngọc Duy81330612018-03-24 08:44:40 +0100198 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
Christian Couder56621762017-02-27 18:59:59 +0100199 cat >expect <<-EOF &&
200 $BASE
201 100644 $EMPTY_BLOB 0 one
202 replacements:
203 deletions: 0
204 EOF
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +0700205 test_cmp expect actual
206'
207
208test_expect_success 'add new file' '
SZEDER Gáborc6e56072018-10-11 11:43:06 +0200209 create_non_racy_file two &&
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +0700210 git update-index --add two &&
211 git ls-files --stage >actual &&
Christian Couder56621762017-02-27 18:59:59 +0100212 cat >expect <<-EOF &&
213 100644 $EMPTY_BLOB 0 one
214 100644 $EMPTY_BLOB 0 two
215 EOF
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +0700216 test_cmp expect actual
217'
218
219test_expect_success 'unify index, two files remain' '
220 git update-index --no-split-index &&
221 git ls-files --stage >ls-files.actual &&
Christian Couder56621762017-02-27 18:59:59 +0100222 cat >ls-files.expect <<-EOF &&
223 100644 $EMPTY_BLOB 0 one
224 100644 $EMPTY_BLOB 0 two
225 EOF
Jeff King8fb26872015-03-20 06:06:15 -0400226 test_cmp ls-files.expect ls-files.actual &&
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +0700227
Nguyễn Thái Ngọc Duy81330612018-03-24 08:44:40 +0100228 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
Christian Couder56621762017-02-27 18:59:59 +0100229 cat >expect <<-EOF &&
230 not a split index
231 EOF
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +0700232 test_cmp expect actual
233'
234
Johannes Schindelin098aa862017-02-17 17:59:06 +0100235test_expect_success 'rev-parse --shared-index-path' '
Michael Rappazzo5de8a542017-02-17 17:59:02 +0100236 test_create_repo split-index &&
237 (
238 cd split-index &&
239 git update-index --split-index &&
240 echo .git/sharedindex* >expect &&
241 git rev-parse --shared-index-path >actual &&
242 test_cmp expect actual &&
243 mkdir subdirectory &&
244 cd subdirectory &&
245 echo ../.git/sharedindex* >expect &&
246 git rev-parse --shared-index-path >actual &&
247 test_cmp expect actual
248 )
249'
250
Christian Couderb8923bf2017-02-27 19:00:04 +0100251test_expect_success 'set core.splitIndex config variable to true' '
252 git config core.splitIndex true &&
SZEDER Gáborc6e56072018-10-11 11:43:06 +0200253 create_non_racy_file three &&
Christian Couderb8923bf2017-02-27 19:00:04 +0100254 git update-index --add three &&
255 git ls-files --stage >ls-files.actual &&
256 cat >ls-files.expect <<-EOF &&
brian m. carlsonbfefd522019-06-28 22:59:27 +0000257 100644 $EMPTY_BLOB 0 one
258 100644 $EMPTY_BLOB 0 three
259 100644 $EMPTY_BLOB 0 two
Christian Couderb8923bf2017-02-27 19:00:04 +0100260 EOF
261 test_cmp ls-files.expect ls-files.actual &&
Nguyễn Thái Ngọc Duy81330612018-03-24 08:44:40 +0100262 BASE=$(test-tool dump-split-index .git/index | grep "^base") &&
263 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
Christian Couderb8923bf2017-02-27 19:00:04 +0100264 cat >expect <<-EOF &&
265 $BASE
266 replacements:
267 deletions:
268 EOF
269 test_cmp expect actual
270'
271
272test_expect_success 'set core.splitIndex config variable to false' '
273 git config core.splitIndex false &&
274 git update-index --force-remove three &&
275 git ls-files --stage >ls-files.actual &&
276 cat >ls-files.expect <<-EOF &&
brian m. carlsonbfefd522019-06-28 22:59:27 +0000277 100644 $EMPTY_BLOB 0 one
278 100644 $EMPTY_BLOB 0 two
Christian Couderb8923bf2017-02-27 19:00:04 +0100279 EOF
280 test_cmp ls-files.expect ls-files.actual &&
Nguyễn Thái Ngọc Duy81330612018-03-24 08:44:40 +0100281 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
Christian Couderb8923bf2017-02-27 19:00:04 +0100282 cat >expect <<-EOF &&
283 not a split index
284 EOF
285 test_cmp expect actual
286'
287
SZEDER Gáborc6e56072018-10-11 11:43:06 +0200288test_expect_success 'set core.splitIndex config variable back to true' '
Christian Couderfcdbd952017-02-27 19:00:09 +0100289 git config core.splitIndex true &&
SZEDER Gáborc6e56072018-10-11 11:43:06 +0200290 create_non_racy_file three &&
Christian Couderfcdbd952017-02-27 19:00:09 +0100291 git update-index --add three &&
Nguyễn Thái Ngọc Duy81330612018-03-24 08:44:40 +0100292 BASE=$(test-tool dump-split-index .git/index | grep "^base") &&
293 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
Christian Couderfcdbd952017-02-27 19:00:09 +0100294 cat >expect <<-EOF &&
295 $BASE
296 replacements:
297 deletions:
298 EOF
299 test_cmp expect actual &&
SZEDER Gáborc6e56072018-10-11 11:43:06 +0200300 create_non_racy_file four &&
Christian Couderfcdbd952017-02-27 19:00:09 +0100301 git update-index --add four &&
Nguyễn Thái Ngọc Duy81330612018-03-24 08:44:40 +0100302 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
Christian Couderfcdbd952017-02-27 19:00:09 +0100303 cat >expect <<-EOF &&
304 $BASE
brian m. carlsonbfefd522019-06-28 22:59:27 +0000305 100644 $EMPTY_BLOB 0 four
Christian Couderfcdbd952017-02-27 19:00:09 +0100306 replacements:
307 deletions:
308 EOF
309 test_cmp expect actual
310'
311
312test_expect_success 'check behavior with splitIndex.maxPercentChange unset' '
313 git config --unset splitIndex.maxPercentChange &&
SZEDER Gáborc6e56072018-10-11 11:43:06 +0200314 create_non_racy_file five &&
Christian Couderfcdbd952017-02-27 19:00:09 +0100315 git update-index --add five &&
Nguyễn Thái Ngọc Duy81330612018-03-24 08:44:40 +0100316 BASE=$(test-tool dump-split-index .git/index | grep "^base") &&
317 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
Christian Couderfcdbd952017-02-27 19:00:09 +0100318 cat >expect <<-EOF &&
319 $BASE
320 replacements:
321 deletions:
322 EOF
323 test_cmp expect actual &&
SZEDER Gáborc6e56072018-10-11 11:43:06 +0200324 create_non_racy_file six &&
Christian Couderfcdbd952017-02-27 19:00:09 +0100325 git update-index --add six &&
Nguyễn Thái Ngọc Duy81330612018-03-24 08:44:40 +0100326 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
Christian Couderfcdbd952017-02-27 19:00:09 +0100327 cat >expect <<-EOF &&
328 $BASE
brian m. carlsonbfefd522019-06-28 22:59:27 +0000329 100644 $EMPTY_BLOB 0 six
Christian Couderfcdbd952017-02-27 19:00:09 +0100330 replacements:
331 deletions:
332 EOF
333 test_cmp expect actual
334'
335
336test_expect_success 'check splitIndex.maxPercentChange set to 0' '
337 git config splitIndex.maxPercentChange 0 &&
SZEDER Gáborc6e56072018-10-11 11:43:06 +0200338 create_non_racy_file seven &&
Christian Couderfcdbd952017-02-27 19:00:09 +0100339 git update-index --add seven &&
Nguyễn Thái Ngọc Duy81330612018-03-24 08:44:40 +0100340 BASE=$(test-tool dump-split-index .git/index | grep "^base") &&
341 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
Christian Couderfcdbd952017-02-27 19:00:09 +0100342 cat >expect <<-EOF &&
343 $BASE
344 replacements:
345 deletions:
346 EOF
347 test_cmp expect actual &&
SZEDER Gáborc6e56072018-10-11 11:43:06 +0200348 create_non_racy_file eight &&
Christian Couderfcdbd952017-02-27 19:00:09 +0100349 git update-index --add eight &&
Nguyễn Thái Ngọc Duy81330612018-03-24 08:44:40 +0100350 BASE=$(test-tool dump-split-index .git/index | grep "^base") &&
351 test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
Christian Couderfcdbd952017-02-27 19:00:09 +0100352 cat >expect <<-EOF &&
353 $BASE
354 replacements:
355 deletions:
356 EOF
357 test_cmp expect actual
358'
359
Christian Couderc0441f72017-03-06 10:41:59 +0100360test_expect_success 'shared index files expire after 2 weeks by default' '
SZEDER Gáborc6e56072018-10-11 11:43:06 +0200361 create_non_racy_file ten &&
Christian Couderc0441f72017-03-06 10:41:59 +0100362 git update-index --add ten &&
Christian Couderc3a00822017-03-06 10:42:01 +0100363 test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
Christian Couderc0441f72017-03-06 10:41:59 +0100364 just_under_2_weeks_ago=$((5-14*86400)) &&
Nguyễn Thái Ngọc Duy0e496492018-03-24 08:44:31 +0100365 test-tool chmtime =$just_under_2_weeks_ago .git/sharedindex.* &&
SZEDER Gáborc6e56072018-10-11 11:43:06 +0200366 create_non_racy_file eleven &&
Christian Couderc0441f72017-03-06 10:41:59 +0100367 git update-index --add eleven &&
Christian Couderc3a00822017-03-06 10:42:01 +0100368 test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
Christian Couderc0441f72017-03-06 10:41:59 +0100369 just_over_2_weeks_ago=$((-1-14*86400)) &&
Nguyễn Thái Ngọc Duy0e496492018-03-24 08:44:31 +0100370 test-tool chmtime =$just_over_2_weeks_ago .git/sharedindex.* &&
SZEDER Gáborc6e56072018-10-11 11:43:06 +0200371 create_non_racy_file twelve &&
Christian Couderc0441f72017-03-06 10:41:59 +0100372 git update-index --add twelve &&
Christian Couderc3a00822017-03-06 10:42:01 +0100373 test $(ls .git/sharedindex.* | wc -l) -le 2
Christian Couderc0441f72017-03-06 10:41:59 +0100374'
375
376test_expect_success 'check splitIndex.sharedIndexExpire set to 16 days' '
377 git config splitIndex.sharedIndexExpire "16.days.ago" &&
Nguyễn Thái Ngọc Duy0e496492018-03-24 08:44:31 +0100378 test-tool chmtime =$just_over_2_weeks_ago .git/sharedindex.* &&
SZEDER Gáborc6e56072018-10-11 11:43:06 +0200379 create_non_racy_file thirteen &&
Christian Couderc0441f72017-03-06 10:41:59 +0100380 git update-index --add thirteen &&
Christian Couderc3a00822017-03-06 10:42:01 +0100381 test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
Christian Couderc0441f72017-03-06 10:41:59 +0100382 just_over_16_days_ago=$((-1-16*86400)) &&
Nguyễn Thái Ngọc Duy0e496492018-03-24 08:44:31 +0100383 test-tool chmtime =$just_over_16_days_ago .git/sharedindex.* &&
SZEDER Gáborc6e56072018-10-11 11:43:06 +0200384 create_non_racy_file fourteen &&
Christian Couderc0441f72017-03-06 10:41:59 +0100385 git update-index --add fourteen &&
Christian Couderc3a00822017-03-06 10:42:01 +0100386 test $(ls .git/sharedindex.* | wc -l) -le 2
Christian Couderc0441f72017-03-06 10:41:59 +0100387'
388
389test_expect_success 'check splitIndex.sharedIndexExpire set to "never" and "now"' '
390 git config splitIndex.sharedIndexExpire never &&
391 just_10_years_ago=$((-365*10*86400)) &&
Nguyễn Thái Ngọc Duy0e496492018-03-24 08:44:31 +0100392 test-tool chmtime =$just_10_years_ago .git/sharedindex.* &&
SZEDER Gáborc6e56072018-10-11 11:43:06 +0200393 create_non_racy_file fifteen &&
Christian Couderc0441f72017-03-06 10:41:59 +0100394 git update-index --add fifteen &&
Christian Couderc3a00822017-03-06 10:42:01 +0100395 test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
Christian Couderc0441f72017-03-06 10:41:59 +0100396 git config splitIndex.sharedIndexExpire now &&
397 just_1_second_ago=-1 &&
Nguyễn Thái Ngọc Duy0e496492018-03-24 08:44:31 +0100398 test-tool chmtime =$just_1_second_ago .git/sharedindex.* &&
SZEDER Gáborc6e56072018-10-11 11:43:06 +0200399 create_non_racy_file sixteen &&
Christian Couderc0441f72017-03-06 10:41:59 +0100400 git update-index --add sixteen &&
Christian Couderc3a00822017-03-06 10:42:01 +0100401 test $(ls .git/sharedindex.* | wc -l) -le 2
Christian Couderc0441f72017-03-06 10:41:59 +0100402'
403
Ævar Arnfjörð Bjarmasonc9d6c782018-11-18 19:04:29 +0000404test_expect_success POSIXPERM 'same mode for index & split index' '
405 git init same-mode &&
406 (
407 cd same-mode &&
408 test_commit A &&
409 test_modebits .git/index >index_mode &&
410 test_must_fail git config core.sharedRepository &&
411 git -c core.splitIndex=true status &&
412 shared=$(ls .git/sharedindex.*) &&
413 case "$shared" in
414 *" "*)
415 # we have more than one???
416 false ;;
417 *)
418 test_modebits "$shared" >split_index_mode &&
419 test_cmp index_mode split_index_mode ;;
420 esac
421 )
422'
423
Christian Couder3ee83f42017-06-25 06:34:29 +0200424while read -r mode modebits
425do
426 test_expect_success POSIXPERM "split index respects core.sharedrepository $mode" '
427 # Remove existing shared index files
428 git config core.splitIndex false &&
429 git update-index --force-remove one &&
430 rm -f .git/sharedindex.* &&
431 # Create one new shared index file
432 git config core.sharedrepository "$mode" &&
433 git config core.splitIndex true &&
SZEDER Gáborc6e56072018-10-11 11:43:06 +0200434 create_non_racy_file one &&
Christian Couder3ee83f42017-06-25 06:34:29 +0200435 git update-index --add one &&
436 echo "$modebits" >expect &&
437 test_modebits .git/index >actual &&
438 test_cmp expect actual &&
439 shared=$(ls .git/sharedindex.*) &&
440 case "$shared" in
441 *" "*)
442 # we have more than one???
443 false ;;
444 *)
445 test_modebits "$shared" >actual &&
446 test_cmp expect actual ;;
447 esac
448 '
449done <<\EOF
4500666 -rw-rw-rw-
4510642 -rw-r---w-
452EOF
453
Nguyễn Thái Ngọc Duyef5b3a62018-01-24 16:38:29 +0700454test_expect_success POSIXPERM,SANITY 'graceful handling when splitting index is not allowed' '
455 test_create_repo ro &&
456 (
457 cd ro &&
458 test_commit initial &&
459 git update-index --split-index &&
460 test -f .git/sharedindex.*
461 ) &&
462 cp ro/.git/index new-index &&
463 test_when_finished "chmod u+w ro/.git" &&
464 chmod u-w ro/.git &&
465 GIT_INDEX_FILE="$(pwd)/new-index" git -C ro update-index --split-index &&
466 chmod u+w ro/.git &&
467 rm ro/.git/sharedindex.* &&
468 GIT_INDEX_FILE=new-index git ls-files >actual &&
469 echo initial.t >expected &&
470 test_cmp expected actual
471'
472
Thomas Gummerer4bddd982018-01-07 22:30:14 +0000473test_expect_success 'writing split index with null sha1 does not write cache tree' '
474 git config core.splitIndex true &&
475 git config splitIndex.maxPercentChange 0 &&
476 git commit -m "commit" &&
477 {
478 git ls-tree HEAD &&
brian m. carlson8125a582018-05-13 02:24:13 +0000479 printf "160000 commit $ZERO_OID\\tbroken\\n"
Thomas Gummerer4bddd982018-01-07 22:30:14 +0000480 } >broken-tree &&
481 echo "add broken entry" >msg &&
482
483 tree=$(git mktree <broken-tree) &&
484 test_tick &&
485 commit=$(git commit-tree $tree -p HEAD <msg) &&
486 git update-ref HEAD "$commit" &&
487 GIT_ALLOW_NULL_SHA1=1 git reset --hard &&
Eric Sunshine83279742018-07-01 20:23:41 -0400488 test_might_fail test-tool dump-cache-tree >cache-tree.out &&
Thomas Gummerer4bddd982018-01-07 22:30:14 +0000489 test_line_count = 0 cache-tree.out
490'
491
Nguyễn Thái Ngọc Duy6e37c8e2019-02-13 16:51:29 +0700492test_expect_success 'do not refresh null base index' '
493 test_create_repo merge &&
494 (
495 cd merge &&
496 test_commit initial &&
497 git checkout -b side-branch &&
498 test_commit extra &&
499 git checkout master &&
500 git update-index --split-index &&
501 test_commit more &&
502 # must not write a new shareindex, or we wont catch the problem
503 git -c splitIndex.maxPercentChange=100 merge --no-edit side-branch 2>err &&
504 # i.e. do not expect warnings like
505 # could not freshen shared index .../shareindex.00000...
506 test_must_be_empty err
507 )
508'
509
Nguyễn Thái Ngọc Duy3e52f702014-06-13 19:19:51 +0700510test_done