]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1700-split-index.sh
read-cache: refactor read_index_from()
[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
9
10test_expect_success 'enable split index' '
e6a1dd77 11 git config splitIndex.maxPercentChange 100 &&
3e52f70b
NTND
12 git update-index --split-index &&
13 test-dump-split-index .git/index >actual &&
e869c5ea
TG
14 indexversion=$(test-index-version <.git/index) &&
15 if test "$indexversion" = "4"
16 then
17 own=432ef4b63f32193984f339431fd50ca796493569
18 base=508851a7f0dfa8691e9f69c7f055865389012491
19 else
20 own=8299b0bcd1ac364e5f1d7768efb62fa2da79a339
21 base=39d890139ee5356c7ef572216cebcd27aa41f9df
22 fi &&
56621763
CC
23 cat >expect <<-EOF &&
24 own $own
25 base $base
26 replacements:
27 deletions:
28 EOF
3e52f70b
NTND
29 test_cmp expect actual
30'
31
32test_expect_success 'add one file' '
33 : >one &&
34 git update-index --add one &&
35 git ls-files --stage >ls-files.actual &&
56621763
CC
36 cat >ls-files.expect <<-EOF &&
37 100644 $EMPTY_BLOB 0 one
38 EOF
3e52f70b
NTND
39 test_cmp ls-files.expect ls-files.actual &&
40
41 test-dump-split-index .git/index | sed "/^own/d" >actual &&
56621763
CC
42 cat >expect <<-EOF &&
43 base $base
44 100644 $EMPTY_BLOB 0 one
45 replacements:
46 deletions:
47 EOF
3e52f70b
NTND
48 test_cmp expect actual
49'
50
51test_expect_success 'disable split index' '
52 git update-index --no-split-index &&
53 git ls-files --stage >ls-files.actual &&
56621763
CC
54 cat >ls-files.expect <<-EOF &&
55 100644 $EMPTY_BLOB 0 one
56 EOF
3e52f70b
NTND
57 test_cmp ls-files.expect ls-files.actual &&
58
16149d75 59 BASE=$(test-dump-split-index .git/index | grep "^own" | sed "s/own/base/") &&
3e52f70b 60 test-dump-split-index .git/index | sed "/^own/d" >actual &&
56621763
CC
61 cat >expect <<-EOF &&
62 not a split index
63 EOF
3e52f70b
NTND
64 test_cmp expect actual
65'
66
67test_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 &&
56621763
CC
70 cat >ls-files.expect <<-EOF &&
71 100644 $EMPTY_BLOB 0 one
72 EOF
3e52f70b
NTND
73 test_cmp ls-files.expect ls-files.actual &&
74
75 test-dump-split-index .git/index | sed "/^own/d" >actual &&
56621763
CC
76 cat >expect <<-EOF &&
77 $BASE
78 replacements:
79 deletions:
80 EOF
3e52f70b
NTND
81 test_cmp expect actual
82'
83
84test_expect_success 'modify original file, base index untouched' '
85 echo modified >one &&
86 git update-index one &&
87 git ls-files --stage >ls-files.actual &&
56621763
CC
88 cat >ls-files.expect <<-EOF &&
89 100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0 one
90 EOF
3e52f70b
NTND
91 test_cmp ls-files.expect ls-files.actual &&
92
93 test-dump-split-index .git/index | sed "/^own/d" >actual &&
56621763
CC
94 q_to_tab >expect <<-EOF &&
95 $BASE
96 100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q
97 replacements: 0
98 deletions:
99 EOF
3e52f70b
NTND
100 test_cmp expect actual
101'
102
103test_expect_success 'add another file, which stays index' '
104 : >two &&
105 git update-index --add two &&
106 git ls-files --stage >ls-files.actual &&
56621763
CC
107 cat >ls-files.expect <<-EOF &&
108 100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0 one
109 100644 $EMPTY_BLOB 0 two
110 EOF
3e52f70b
NTND
111 test_cmp ls-files.expect ls-files.actual &&
112
113 test-dump-split-index .git/index | sed "/^own/d" >actual &&
56621763
CC
114 q_to_tab >expect <<-EOF &&
115 $BASE
116 100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q
117 100644 $EMPTY_BLOB 0 two
118 replacements: 0
119 deletions:
120 EOF
3e52f70b
NTND
121 test_cmp expect actual
122'
123
124test_expect_success 'remove file not in base index' '
125 git update-index --force-remove two &&
126 git ls-files --stage >ls-files.actual &&
56621763
CC
127 cat >ls-files.expect <<-EOF &&
128 100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0 one
129 EOF
3e52f70b
NTND
130 test_cmp ls-files.expect ls-files.actual &&
131
132 test-dump-split-index .git/index | sed "/^own/d" >actual &&
56621763
CC
133 q_to_tab >expect <<-EOF &&
134 $BASE
135 100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q
136 replacements: 0
137 deletions:
138 EOF
3e52f70b
NTND
139 test_cmp expect actual
140'
141
142test_expect_success 'remove file in base index' '
143 git update-index --force-remove one &&
144 git ls-files --stage >ls-files.actual &&
56621763
CC
145 cat >ls-files.expect <<-EOF &&
146 EOF
3e52f70b
NTND
147 test_cmp ls-files.expect ls-files.actual &&
148
149 test-dump-split-index .git/index | sed "/^own/d" >actual &&
56621763
CC
150 cat >expect <<-EOF &&
151 $BASE
152 replacements:
153 deletions: 0
154 EOF
3e52f70b
NTND
155 test_cmp expect actual
156'
157
158test_expect_success 'add original file back' '
159 : >one &&
160 git update-index --add one &&
161 git ls-files --stage >ls-files.actual &&
56621763
CC
162 cat >ls-files.expect <<-EOF &&
163 100644 $EMPTY_BLOB 0 one
164 EOF
3e52f70b
NTND
165 test_cmp ls-files.expect ls-files.actual &&
166
167 test-dump-split-index .git/index | sed "/^own/d" >actual &&
56621763
CC
168 cat >expect <<-EOF &&
169 $BASE
170 100644 $EMPTY_BLOB 0 one
171 replacements:
172 deletions: 0
173 EOF
3e52f70b
NTND
174 test_cmp expect actual
175'
176
177test_expect_success 'add new file' '
178 : >two &&
179 git update-index --add two &&
180 git ls-files --stage >actual &&
56621763
CC
181 cat >expect <<-EOF &&
182 100644 $EMPTY_BLOB 0 one
183 100644 $EMPTY_BLOB 0 two
184 EOF
3e52f70b
NTND
185 test_cmp expect actual
186'
187
188test_expect_success 'unify index, two files remain' '
189 git update-index --no-split-index &&
190 git ls-files --stage >ls-files.actual &&
56621763
CC
191 cat >ls-files.expect <<-EOF &&
192 100644 $EMPTY_BLOB 0 one
193 100644 $EMPTY_BLOB 0 two
194 EOF
8fb26872 195 test_cmp ls-files.expect ls-files.actual &&
3e52f70b
NTND
196
197 test-dump-split-index .git/index | sed "/^own/d" >actual &&
56621763
CC
198 cat >expect <<-EOF &&
199 not a split index
200 EOF
3e52f70b
NTND
201 test_cmp expect actual
202'
203
b8923bf6
CC
204test_expect_success 'set core.splitIndex config variable to true' '
205 git config core.splitIndex true &&
206 : >three &&
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
213 EOF
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 &&
218 $BASE
219 replacements:
220 deletions:
221 EOF
222 test_cmp expect actual
223'
224
225test_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
232 EOF
233 test_cmp ls-files.expect ls-files.actual &&
234 test-dump-split-index .git/index | sed "/^own/d" >actual &&
235 cat >expect <<-EOF &&
236 not a split index
237 EOF
238 test_cmp expect actual
239'
240
fcdbd954
CC
241test_expect_success 'set core.splitIndex config variable to true' '
242 git config core.splitIndex true &&
243 : >three &&
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 &&
248 $BASE
249 replacements:
250 deletions:
251 EOF
252 test_cmp expect actual &&
253 : >four &&
254 git update-index --add four &&
255 test-dump-split-index .git/index | sed "/^own/d" >actual &&
256 cat >expect <<-EOF &&
257 $BASE
258 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 four
259 replacements:
260 deletions:
261 EOF
262 test_cmp expect actual
263'
264
265test_expect_success 'check behavior with splitIndex.maxPercentChange unset' '
266 git config --unset splitIndex.maxPercentChange &&
267 : >five &&
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 &&
272 $BASE
273 replacements:
274 deletions:
275 EOF
276 test_cmp expect actual &&
277 : >six &&
278 git update-index --add six &&
279 test-dump-split-index .git/index | sed "/^own/d" >actual &&
280 cat >expect <<-EOF &&
281 $BASE
282 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 six
283 replacements:
284 deletions:
285 EOF
286 test_cmp expect actual
287'
288
289test_expect_success 'check splitIndex.maxPercentChange set to 0' '
290 git config splitIndex.maxPercentChange 0 &&
291 : >seven &&
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 &&
296 $BASE
297 replacements:
298 deletions:
299 EOF
300 test_cmp expect actual &&
301 : >eight &&
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 &&
306 $BASE
307 replacements:
308 deletions:
309 EOF
310 test_cmp expect actual
311'
312
c0441f7e
CC
313test_expect_success 'shared index files expire after 2 weeks by default' '
314 : >ten &&
315 git update-index --add ten &&
316 test $(ls .git/sharedindex.* | wc -l) -gt 1 &&
317 just_under_2_weeks_ago=$((5-14*86400)) &&
318 test-chmtime =$just_under_2_weeks_ago .git/sharedindex.* &&
319 : >eleven &&
320 git update-index --add eleven &&
321 test $(ls .git/sharedindex.* | wc -l) -gt 1 &&
322 just_over_2_weeks_ago=$((-1-14*86400)) &&
323 test-chmtime =$just_over_2_weeks_ago .git/sharedindex.* &&
324 : >twelve &&
325 git update-index --add twelve &&
326 test $(ls .git/sharedindex.* | wc -l) = 1
327'
328
329test_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.* &&
332 : >thirteen &&
333 git update-index --add thirteen &&
334 test $(ls .git/sharedindex.* | wc -l) -gt 1 &&
335 just_over_16_days_ago=$((-1-16*86400)) &&
336 test-chmtime =$just_over_16_days_ago .git/sharedindex.* &&
337 : >fourteen &&
338 git update-index --add fourteen &&
339 test $(ls .git/sharedindex.* | wc -l) = 1
340'
341
342test_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.* &&
346 : >fifteen &&
347 git update-index --add fifteen &&
348 test $(ls .git/sharedindex.* | wc -l) -gt 1 &&
349 git config splitIndex.sharedIndexExpire now &&
350 just_1_second_ago=-1 &&
351 test-chmtime =$just_1_second_ago .git/sharedindex.* &&
352 : >sixteen &&
353 git update-index --add sixteen &&
354 test $(ls .git/sharedindex.* | wc -l) = 1
355'
356
3e52f70b 357test_done