3 test_description='split index mode tests'
7 # We need total control of index splitting here
8 sane_unset GIT_TEST_SPLIT_INDEX
9 sane_unset GIT_FSMONITOR_TEST
11 test_expect_success 'enable split index' '
12 git config splitIndex.maxPercentChange 100 &&
13 git update-index --split-index &&
14 test-dump-split-index .git/index >actual &&
15 indexversion=$(test-index-version <.git/index) &&
16 if test "$indexversion" = "4"
18 own=432ef4b63f32193984f339431fd50ca796493569
19 base=508851a7f0dfa8691e9f69c7f055865389012491
21 own=8299b0bcd1ac364e5f1d7768efb62fa2da79a339
22 base=39d890139ee5356c7ef572216cebcd27aa41f9df
30 test_cmp expect actual
33 test_expect_success 'add one file' '
35 git update-index --add one &&
36 git ls-files --stage >ls-files.actual &&
37 cat >ls-files.expect <<-EOF &&
38 100644 $EMPTY_BLOB 0 one
40 test_cmp ls-files.expect ls-files.actual &&
42 test-dump-split-index .git/index | sed "/^own/d" >actual &&
45 100644 $EMPTY_BLOB 0 one
49 test_cmp expect actual
52 test_expect_success 'disable split index' '
53 git update-index --no-split-index &&
54 git ls-files --stage >ls-files.actual &&
55 cat >ls-files.expect <<-EOF &&
56 100644 $EMPTY_BLOB 0 one
58 test_cmp ls-files.expect ls-files.actual &&
60 BASE=$(test-dump-split-index .git/index | grep "^own" | sed "s/own/base/") &&
61 test-dump-split-index .git/index | sed "/^own/d" >actual &&
65 test_cmp expect actual
68 test_expect_success 'enable split index again, "one" now belongs to base index"' '
69 git update-index --split-index &&
70 git ls-files --stage >ls-files.actual &&
71 cat >ls-files.expect <<-EOF &&
72 100644 $EMPTY_BLOB 0 one
74 test_cmp ls-files.expect ls-files.actual &&
76 test-dump-split-index .git/index | sed "/^own/d" >actual &&
82 test_cmp expect actual
85 test_expect_success 'modify original file, base index untouched' '
87 git update-index one &&
88 git ls-files --stage >ls-files.actual &&
89 cat >ls-files.expect <<-EOF &&
90 100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0 one
92 test_cmp ls-files.expect ls-files.actual &&
94 test-dump-split-index .git/index | sed "/^own/d" >actual &&
95 q_to_tab >expect <<-EOF &&
97 100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q
101 test_cmp expect actual
104 test_expect_success 'add another file, which stays index' '
106 git update-index --add two &&
107 git ls-files --stage >ls-files.actual &&
108 cat >ls-files.expect <<-EOF &&
109 100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0 one
110 100644 $EMPTY_BLOB 0 two
112 test_cmp ls-files.expect ls-files.actual &&
114 test-dump-split-index .git/index | sed "/^own/d" >actual &&
115 q_to_tab >expect <<-EOF &&
117 100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q
118 100644 $EMPTY_BLOB 0 two
122 test_cmp expect actual
125 test_expect_success 'remove file not in base index' '
126 git update-index --force-remove two &&
127 git ls-files --stage >ls-files.actual &&
128 cat >ls-files.expect <<-EOF &&
129 100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0 one
131 test_cmp ls-files.expect ls-files.actual &&
133 test-dump-split-index .git/index | sed "/^own/d" >actual &&
134 q_to_tab >expect <<-EOF &&
136 100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q
140 test_cmp expect actual
143 test_expect_success 'remove file in base index' '
144 git update-index --force-remove one &&
145 git ls-files --stage >ls-files.actual &&
146 cat >ls-files.expect <<-EOF &&
148 test_cmp ls-files.expect ls-files.actual &&
150 test-dump-split-index .git/index | sed "/^own/d" >actual &&
151 cat >expect <<-EOF &&
156 test_cmp expect actual
159 test_expect_success 'add original file back' '
161 git update-index --add one &&
162 git ls-files --stage >ls-files.actual &&
163 cat >ls-files.expect <<-EOF &&
164 100644 $EMPTY_BLOB 0 one
166 test_cmp ls-files.expect ls-files.actual &&
168 test-dump-split-index .git/index | sed "/^own/d" >actual &&
169 cat >expect <<-EOF &&
171 100644 $EMPTY_BLOB 0 one
175 test_cmp expect actual
178 test_expect_success 'add new file' '
180 git update-index --add two &&
181 git ls-files --stage >actual &&
182 cat >expect <<-EOF &&
183 100644 $EMPTY_BLOB 0 one
184 100644 $EMPTY_BLOB 0 two
186 test_cmp expect actual
189 test_expect_success 'unify index, two files remain' '
190 git update-index --no-split-index &&
191 git ls-files --stage >ls-files.actual &&
192 cat >ls-files.expect <<-EOF &&
193 100644 $EMPTY_BLOB 0 one
194 100644 $EMPTY_BLOB 0 two
196 test_cmp ls-files.expect ls-files.actual &&
198 test-dump-split-index .git/index | sed "/^own/d" >actual &&
199 cat >expect <<-EOF &&
202 test_cmp expect actual
205 test_expect_success 'rev-parse --shared-index-path' '
206 test_create_repo split-index &&
209 git update-index --split-index &&
210 echo .git/sharedindex* >expect &&
211 git rev-parse --shared-index-path >actual &&
212 test_cmp expect actual &&
213 mkdir subdirectory &&
215 echo ../.git/sharedindex* >expect &&
216 git rev-parse --shared-index-path >actual &&
217 test_cmp expect actual
221 test_expect_success 'set core.splitIndex config variable to true' '
222 git config core.splitIndex true &&
224 git update-index --add three &&
225 git ls-files --stage >ls-files.actual &&
226 cat >ls-files.expect <<-EOF &&
227 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one
228 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 three
229 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 two
231 test_cmp ls-files.expect ls-files.actual &&
232 BASE=$(test-dump-split-index .git/index | grep "^base") &&
233 test-dump-split-index .git/index | sed "/^own/d" >actual &&
234 cat >expect <<-EOF &&
239 test_cmp expect actual
242 test_expect_success 'set core.splitIndex config variable to false' '
243 git config core.splitIndex false &&
244 git update-index --force-remove three &&
245 git ls-files --stage >ls-files.actual &&
246 cat >ls-files.expect <<-EOF &&
247 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one
248 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 two
250 test_cmp ls-files.expect ls-files.actual &&
251 test-dump-split-index .git/index | sed "/^own/d" >actual &&
252 cat >expect <<-EOF &&
255 test_cmp expect actual
258 test_expect_success 'set core.splitIndex config variable to true' '
259 git config core.splitIndex true &&
261 git update-index --add three &&
262 BASE=$(test-dump-split-index .git/index | grep "^base") &&
263 test-dump-split-index .git/index | sed "/^own/d" >actual &&
264 cat >expect <<-EOF &&
269 test_cmp expect actual &&
271 git update-index --add four &&
272 test-dump-split-index .git/index | sed "/^own/d" >actual &&
273 cat >expect <<-EOF &&
275 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 four
279 test_cmp expect actual
282 test_expect_success 'check behavior with splitIndex.maxPercentChange unset' '
283 git config --unset splitIndex.maxPercentChange &&
285 git update-index --add five &&
286 BASE=$(test-dump-split-index .git/index | grep "^base") &&
287 test-dump-split-index .git/index | sed "/^own/d" >actual &&
288 cat >expect <<-EOF &&
293 test_cmp expect actual &&
295 git update-index --add six &&
296 test-dump-split-index .git/index | sed "/^own/d" >actual &&
297 cat >expect <<-EOF &&
299 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 six
303 test_cmp expect actual
306 test_expect_success 'check splitIndex.maxPercentChange set to 0' '
307 git config splitIndex.maxPercentChange 0 &&
309 git update-index --add seven &&
310 BASE=$(test-dump-split-index .git/index | grep "^base") &&
311 test-dump-split-index .git/index | sed "/^own/d" >actual &&
312 cat >expect <<-EOF &&
317 test_cmp expect actual &&
319 git update-index --add eight &&
320 BASE=$(test-dump-split-index .git/index | grep "^base") &&
321 test-dump-split-index .git/index | sed "/^own/d" >actual &&
322 cat >expect <<-EOF &&
327 test_cmp expect actual
330 test_expect_success 'shared index files expire after 2 weeks by default' '
332 git update-index --add ten &&
333 test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
334 just_under_2_weeks_ago=$((5-14*86400)) &&
335 test-chmtime =$just_under_2_weeks_ago .git/sharedindex.* &&
337 git update-index --add eleven &&
338 test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
339 just_over_2_weeks_ago=$((-1-14*86400)) &&
340 test-chmtime =$just_over_2_weeks_ago .git/sharedindex.* &&
342 git update-index --add twelve &&
343 test $(ls .git/sharedindex.* | wc -l) -le 2
346 test_expect_success 'check splitIndex.sharedIndexExpire set to 16 days' '
347 git config splitIndex.sharedIndexExpire "16.days.ago" &&
348 test-chmtime =$just_over_2_weeks_ago .git/sharedindex.* &&
350 git update-index --add thirteen &&
351 test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
352 just_over_16_days_ago=$((-1-16*86400)) &&
353 test-chmtime =$just_over_16_days_ago .git/sharedindex.* &&
355 git update-index --add fourteen &&
356 test $(ls .git/sharedindex.* | wc -l) -le 2
359 test_expect_success 'check splitIndex.sharedIndexExpire set to "never" and "now"' '
360 git config splitIndex.sharedIndexExpire never &&
361 just_10_years_ago=$((-365*10*86400)) &&
362 test-chmtime =$just_10_years_ago .git/sharedindex.* &&
364 git update-index --add fifteen &&
365 test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
366 git config splitIndex.sharedIndexExpire now &&
367 just_1_second_ago=-1 &&
368 test-chmtime =$just_1_second_ago .git/sharedindex.* &&
370 git update-index --add sixteen &&
371 test $(ls .git/sharedindex.* | wc -l) -le 2
374 while read -r mode modebits
376 test_expect_success POSIXPERM "split index respects core.sharedrepository $mode" '
377 # Remove existing shared index files
378 git config core.splitIndex false &&
379 git update-index --force-remove one &&
380 rm -f .git/sharedindex.* &&
381 # Create one new shared index file
382 git config core.sharedrepository "$mode" &&
383 git config core.splitIndex true &&
385 git update-index --add one &&
386 echo "$modebits" >expect &&
387 test_modebits .git/index >actual &&
388 test_cmp expect actual &&
389 shared=$(ls .git/sharedindex.*) &&
392 # we have more than one???
395 test_modebits "$shared" >actual &&
396 test_cmp expect actual ;;