@@ -13,6 +13,13 @@ sane_unset GIT_TEST_SPLIT_INDEX
13
13
sane_unset GIT_TEST_FSMONITOR
14
14
sane_unset GIT_TEST_INDEX_THREADS
15
15
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.
18
+ create_non_racy_file () {
19
+ cat > " $1 " &&
20
+ test-tool chmtime =-5 " $1 "
21
+ }
22
+
16
23
test_expect_success ' enable split index' '
17
24
git config splitIndex.maxPercentChange 100 &&
18
25
git update-index --split-index &&
@@ -36,7 +43,7 @@ test_expect_success 'enable split index' '
36
43
'
37
44
38
45
test_expect_success ' add one file' '
39
- : > one &&
46
+ create_non_racy_file one &&
40
47
git update-index --add one &&
41
48
git ls-files --stage >ls-files.actual &&
42
49
cat >ls-files.expect <<-EOF &&
@@ -88,7 +95,7 @@ test_expect_success 'enable split index again, "one" now belongs to base index"'
88
95
'
89
96
90
97
test_expect_success ' modify original file, base index untouched' '
91
- echo modified > one &&
98
+ echo modified | create_non_racy_file one &&
92
99
git update-index one &&
93
100
git ls-files --stage >ls-files.actual &&
94
101
cat >ls-files.expect <<-EOF &&
@@ -107,7 +114,7 @@ test_expect_success 'modify original file, base index untouched' '
107
114
'
108
115
109
116
test_expect_success ' add another file, which stays index' '
110
- : > two &&
117
+ create_non_racy_file two &&
111
118
git update-index --add two &&
112
119
git ls-files --stage >ls-files.actual &&
113
120
cat >ls-files.expect <<-EOF &&
@@ -160,7 +167,7 @@ test_expect_success 'remove file in base index' '
160
167
'
161
168
162
169
test_expect_success ' add original file back' '
163
- : > one &&
170
+ create_non_racy_file one &&
164
171
git update-index --add one &&
165
172
git ls-files --stage >ls-files.actual &&
166
173
cat >ls-files.expect <<-EOF &&
@@ -179,7 +186,7 @@ test_expect_success 'add original file back' '
179
186
'
180
187
181
188
test_expect_success ' add new file' '
182
- : > two &&
189
+ create_non_racy_file two &&
183
190
git update-index --add two &&
184
191
git ls-files --stage >actual &&
185
192
cat >expect <<-EOF &&
@@ -223,7 +230,7 @@ test_expect_success 'rev-parse --shared-index-path' '
223
230
224
231
test_expect_success ' set core.splitIndex config variable to true' '
225
232
git config core.splitIndex true &&
226
- : > three &&
233
+ create_non_racy_file three &&
227
234
git update-index --add three &&
228
235
git ls-files --stage >ls-files.actual &&
229
236
cat >ls-files.expect <<-EOF &&
@@ -258,9 +265,9 @@ test_expect_success 'set core.splitIndex config variable to false' '
258
265
test_cmp expect actual
259
266
'
260
267
261
- test_expect_success ' set core.splitIndex config variable to true' '
268
+ test_expect_success ' set core.splitIndex config variable back to true' '
262
269
git config core.splitIndex true &&
263
- : > three &&
270
+ create_non_racy_file three &&
264
271
git update-index --add three &&
265
272
BASE=$(test-tool dump-split-index .git/index | grep "^base") &&
266
273
test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
@@ -270,7 +277,7 @@ test_expect_success 'set core.splitIndex config variable to true' '
270
277
deletions:
271
278
EOF
272
279
test_cmp expect actual &&
273
- : > four &&
280
+ create_non_racy_file four &&
274
281
git update-index --add four &&
275
282
test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
276
283
cat >expect <<-EOF &&
@@ -284,7 +291,7 @@ test_expect_success 'set core.splitIndex config variable to true' '
284
291
285
292
test_expect_success ' check behavior with splitIndex.maxPercentChange unset' '
286
293
git config --unset splitIndex.maxPercentChange &&
287
- : > five &&
294
+ create_non_racy_file five &&
288
295
git update-index --add five &&
289
296
BASE=$(test-tool dump-split-index .git/index | grep "^base") &&
290
297
test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
@@ -294,7 +301,7 @@ test_expect_success 'check behavior with splitIndex.maxPercentChange unset' '
294
301
deletions:
295
302
EOF
296
303
test_cmp expect actual &&
297
- : > six &&
304
+ create_non_racy_file six &&
298
305
git update-index --add six &&
299
306
test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
300
307
cat >expect <<-EOF &&
@@ -308,7 +315,7 @@ test_expect_success 'check behavior with splitIndex.maxPercentChange unset' '
308
315
309
316
test_expect_success ' check splitIndex.maxPercentChange set to 0' '
310
317
git config splitIndex.maxPercentChange 0 &&
311
- : > seven &&
318
+ create_non_racy_file seven &&
312
319
git update-index --add seven &&
313
320
BASE=$(test-tool dump-split-index .git/index | grep "^base") &&
314
321
test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
@@ -318,7 +325,7 @@ test_expect_success 'check splitIndex.maxPercentChange set to 0' '
318
325
deletions:
319
326
EOF
320
327
test_cmp expect actual &&
321
- : > eight &&
328
+ create_non_racy_file eight &&
322
329
git update-index --add eight &&
323
330
BASE=$(test-tool dump-split-index .git/index | grep "^base") &&
324
331
test-tool dump-split-index .git/index | sed "/^own/d" >actual &&
@@ -331,30 +338,30 @@ test_expect_success 'check splitIndex.maxPercentChange set to 0' '
331
338
'
332
339
333
340
test_expect_success ' shared index files expire after 2 weeks by default' '
334
- : > ten &&
341
+ create_non_racy_file ten &&
335
342
git update-index --add ten &&
336
343
test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
337
344
just_under_2_weeks_ago=$((5-14*86400)) &&
338
345
test-tool chmtime =$just_under_2_weeks_ago .git/sharedindex.* &&
339
- : > eleven &&
346
+ create_non_racy_file eleven &&
340
347
git update-index --add eleven &&
341
348
test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
342
349
just_over_2_weeks_ago=$((-1-14*86400)) &&
343
350
test-tool chmtime =$just_over_2_weeks_ago .git/sharedindex.* &&
344
- : > twelve &&
351
+ create_non_racy_file twelve &&
345
352
git update-index --add twelve &&
346
353
test $(ls .git/sharedindex.* | wc -l) -le 2
347
354
'
348
355
349
356
test_expect_success ' check splitIndex.sharedIndexExpire set to 16 days' '
350
357
git config splitIndex.sharedIndexExpire "16.days.ago" &&
351
358
test-tool chmtime =$just_over_2_weeks_ago .git/sharedindex.* &&
352
- : > thirteen &&
359
+ create_non_racy_file thirteen &&
353
360
git update-index --add thirteen &&
354
361
test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
355
362
just_over_16_days_ago=$((-1-16*86400)) &&
356
363
test-tool chmtime =$just_over_16_days_ago .git/sharedindex.* &&
357
- : > fourteen &&
364
+ create_non_racy_file fourteen &&
358
365
git update-index --add fourteen &&
359
366
test $(ls .git/sharedindex.* | wc -l) -le 2
360
367
'
@@ -363,13 +370,13 @@ test_expect_success 'check splitIndex.sharedIndexExpire set to "never" and "now"
363
370
git config splitIndex.sharedIndexExpire never &&
364
371
just_10_years_ago=$((-365*10*86400)) &&
365
372
test-tool chmtime =$just_10_years_ago .git/sharedindex.* &&
366
- : > fifteen &&
373
+ create_non_racy_file fifteen &&
367
374
git update-index --add fifteen &&
368
375
test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
369
376
git config splitIndex.sharedIndexExpire now &&
370
377
just_1_second_ago=-1 &&
371
378
test-tool chmtime =$just_1_second_ago .git/sharedindex.* &&
372
- : > sixteen &&
379
+ create_non_racy_file sixteen &&
373
380
git update-index --add sixteen &&
374
381
test $(ls .git/sharedindex.* | wc -l) -le 2
375
382
'
384
391
# Create one new shared index file
385
392
git config core.sharedrepository "$mode" &&
386
393
git config core.splitIndex true &&
387
- : > one &&
394
+ create_non_racy_file one &&
388
395
git update-index --add one &&
389
396
echo "$modebits" >expect &&
390
397
test_modebits .git/index >actual &&
0 commit comments