3 test_description='split index mode tests'
7 # We need total control of index splitting here
8 sane_unset GIT_TEST_SPLIT_INDEX
10 test_expect_success 'enable split index' '
11 git config splitIndex.maxPercentChange 100 &&
12 git update-index --split-index &&
13 test-dump-split-index .git/index >actual &&
14 indexversion=$(test-index-version <.git/index) &&
15 if test "$indexversion" = "4"
17 own=432ef4b63f32193984f339431fd50ca796493569
18 base=508851a7f0dfa8691e9f69c7f055865389012491
20 own=8299b0bcd1ac364e5f1d7768efb62fa2da79a339
21 base=39d890139ee5356c7ef572216cebcd27aa41f9df
29 test_cmp expect actual
32 test_expect_success 'add one file' '
34 git update-index --add one &&
35 git ls-files --stage >ls-files.actual &&
36 cat >ls-files.expect <<-EOF &&
37 100644 $EMPTY_BLOB 0 one
39 test_cmp ls-files.expect ls-files.actual &&
41 test-dump-split-index .git/index | sed "/^own/d" >actual &&
44 100644 $EMPTY_BLOB 0 one
48 test_cmp expect actual
51 test_expect_success 'disable split index' '
52 git update-index --no-split-index &&
53 git ls-files --stage >ls-files.actual &&
54 cat >ls-files.expect <<-EOF &&
55 100644 $EMPTY_BLOB 0 one
57 test_cmp ls-files.expect ls-files.actual &&
59 BASE=$(test-dump-split-index .git/index | grep "^own" | sed "s/own/base/") &&
60 test-dump-split-index .git/index | sed "/^own/d" >actual &&
64 test_cmp expect actual
67 test_expect_success 'enable split index again, "one" now belongs to base index"' '
68 git update-index --split-index &&
69 git ls-files --stage >ls-files.actual &&
70 cat >ls-files.expect <<-EOF &&
71 100644 $EMPTY_BLOB 0 one
73 test_cmp ls-files.expect ls-files.actual &&
75 test-dump-split-index .git/index | sed "/^own/d" >actual &&
81 test_cmp expect actual
84 test_expect_success 'modify original file, base index untouched' '
86 git update-index one &&
87 git ls-files --stage >ls-files.actual &&
88 cat >ls-files.expect <<-EOF &&
89 100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0 one
91 test_cmp ls-files.expect ls-files.actual &&
93 test-dump-split-index .git/index | sed "/^own/d" >actual &&
94 q_to_tab >expect <<-EOF &&
96 100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q
100 test_cmp expect actual
103 test_expect_success 'add another file, which stays index' '
105 git update-index --add two &&
106 git ls-files --stage >ls-files.actual &&
107 cat >ls-files.expect <<-EOF &&
108 100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0 one
109 100644 $EMPTY_BLOB 0 two
111 test_cmp ls-files.expect ls-files.actual &&
113 test-dump-split-index .git/index | sed "/^own/d" >actual &&
114 q_to_tab >expect <<-EOF &&
116 100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q
117 100644 $EMPTY_BLOB 0 two
121 test_cmp expect actual
124 test_expect_success 'remove file not in base index' '
125 git update-index --force-remove two &&
126 git ls-files --stage >ls-files.actual &&
127 cat >ls-files.expect <<-EOF &&
128 100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0 one
130 test_cmp ls-files.expect ls-files.actual &&
132 test-dump-split-index .git/index | sed "/^own/d" >actual &&
133 q_to_tab >expect <<-EOF &&
135 100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q
139 test_cmp expect actual
142 test_expect_success 'remove file in base index' '
143 git update-index --force-remove one &&
144 git ls-files --stage >ls-files.actual &&
145 cat >ls-files.expect <<-EOF &&
147 test_cmp ls-files.expect ls-files.actual &&
149 test-dump-split-index .git/index | sed "/^own/d" >actual &&
150 cat >expect <<-EOF &&
155 test_cmp expect actual
158 test_expect_success 'add original file back' '
160 git update-index --add one &&
161 git ls-files --stage >ls-files.actual &&
162 cat >ls-files.expect <<-EOF &&
163 100644 $EMPTY_BLOB 0 one
165 test_cmp ls-files.expect ls-files.actual &&
167 test-dump-split-index .git/index | sed "/^own/d" >actual &&
168 cat >expect <<-EOF &&
170 100644 $EMPTY_BLOB 0 one
174 test_cmp expect actual
177 test_expect_success 'add new file' '
179 git update-index --add two &&
180 git ls-files --stage >actual &&
181 cat >expect <<-EOF &&
182 100644 $EMPTY_BLOB 0 one
183 100644 $EMPTY_BLOB 0 two
185 test_cmp expect actual
188 test_expect_success 'unify index, two files remain' '
189 git update-index --no-split-index &&
190 git ls-files --stage >ls-files.actual &&
191 cat >ls-files.expect <<-EOF &&
192 100644 $EMPTY_BLOB 0 one
193 100644 $EMPTY_BLOB 0 two
195 test_cmp ls-files.expect ls-files.actual &&
197 test-dump-split-index .git/index | sed "/^own/d" >actual &&
198 cat >expect <<-EOF &&
201 test_cmp expect actual
204 test_expect_success 'set core.splitIndex config variable to true' '
205 git config core.splitIndex true &&
207 git update-index --add three &&
208 git ls-files --stage >ls-files.actual &&
209 cat >ls-files.expect <<-EOF &&
210 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one
211 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 three
212 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 two
214 test_cmp ls-files.expect ls-files.actual &&
215 BASE=$(test-dump-split-index .git/index | grep "^base") &&
216 test-dump-split-index .git/index | sed "/^own/d" >actual &&
217 cat >expect <<-EOF &&
222 test_cmp expect actual
225 test_expect_success 'set core.splitIndex config variable to false' '
226 git config core.splitIndex false &&
227 git update-index --force-remove three &&
228 git ls-files --stage >ls-files.actual &&
229 cat >ls-files.expect <<-EOF &&
230 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one
231 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 two
233 test_cmp ls-files.expect ls-files.actual &&
234 test-dump-split-index .git/index | sed "/^own/d" >actual &&
235 cat >expect <<-EOF &&
238 test_cmp expect actual
241 test_expect_success 'set core.splitIndex config variable to true' '
242 git config core.splitIndex true &&
244 git update-index --add three &&
245 BASE=$(test-dump-split-index .git/index | grep "^base") &&
246 test-dump-split-index .git/index | sed "/^own/d" >actual &&
247 cat >expect <<-EOF &&
252 test_cmp expect actual &&
254 git update-index --add four &&
255 test-dump-split-index .git/index | sed "/^own/d" >actual &&
256 cat >expect <<-EOF &&
258 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 four
262 test_cmp expect actual
265 test_expect_success 'check behavior with splitIndex.maxPercentChange unset' '
266 git config --unset splitIndex.maxPercentChange &&
268 git update-index --add five &&
269 BASE=$(test-dump-split-index .git/index | grep "^base") &&
270 test-dump-split-index .git/index | sed "/^own/d" >actual &&
271 cat >expect <<-EOF &&
276 test_cmp expect actual &&
278 git update-index --add six &&
279 test-dump-split-index .git/index | sed "/^own/d" >actual &&
280 cat >expect <<-EOF &&
282 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 six
286 test_cmp expect actual
289 test_expect_success 'check splitIndex.maxPercentChange set to 0' '
290 git config splitIndex.maxPercentChange 0 &&
292 git update-index --add seven &&
293 BASE=$(test-dump-split-index .git/index | grep "^base") &&
294 test-dump-split-index .git/index | sed "/^own/d" >actual &&
295 cat >expect <<-EOF &&
300 test_cmp expect actual &&
302 git update-index --add eight &&
303 BASE=$(test-dump-split-index .git/index | grep "^base") &&
304 test-dump-split-index .git/index | sed "/^own/d" >actual &&
305 cat >expect <<-EOF &&
310 test_cmp expect actual
313 test_expect_success 'shared index files expire after 2 weeks by default' '
315 git update-index --add ten &&
316 test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
317 just_under_2_weeks_ago=$((5-14*86400)) &&
318 test-chmtime =$just_under_2_weeks_ago .git/sharedindex.* &&
320 git update-index --add eleven &&
321 test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
322 just_over_2_weeks_ago=$((-1-14*86400)) &&
323 test-chmtime =$just_over_2_weeks_ago .git/sharedindex.* &&
325 git update-index --add twelve &&
326 test $(ls .git/sharedindex.* | wc -l) -le 2
329 test_expect_success 'check splitIndex.sharedIndexExpire set to 16 days' '
330 git config splitIndex.sharedIndexExpire "16.days.ago" &&
331 test-chmtime =$just_over_2_weeks_ago .git/sharedindex.* &&
333 git update-index --add thirteen &&
334 test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
335 just_over_16_days_ago=$((-1-16*86400)) &&
336 test-chmtime =$just_over_16_days_ago .git/sharedindex.* &&
338 git update-index --add fourteen &&
339 test $(ls .git/sharedindex.* | wc -l) -le 2
342 test_expect_success 'check splitIndex.sharedIndexExpire set to "never" and "now"' '
343 git config splitIndex.sharedIndexExpire never &&
344 just_10_years_ago=$((-365*10*86400)) &&
345 test-chmtime =$just_10_years_ago .git/sharedindex.* &&
347 git update-index --add fifteen &&
348 test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
349 git config splitIndex.sharedIndexExpire now &&
350 just_1_second_ago=-1 &&
351 test-chmtime =$just_1_second_ago .git/sharedindex.* &&
353 git update-index --add sixteen &&
354 test $(ls .git/sharedindex.* | wc -l) -le 2