]> git.ipfire.org Git - thirdparty/git.git/blob - t/t7063-status-untracked-cache.sh
config: add core.untrackedCache
[thirdparty/git.git] / t / t7063-status-untracked-cache.sh
1 #!/bin/sh
2
3 test_description='test untracked cache'
4
5 . ./test-lib.sh
6
7 avoid_racy() {
8 sleep 1
9 }
10
11 test_lazy_prereq UNTRACKED_CACHE '
12 { git update-index --test-untracked-cache; ret=$?; } &&
13 test $ret -ne 1
14 '
15
16 if ! test_have_prereq UNTRACKED_CACHE; then
17 skip_all='This system does not support untracked cache'
18 test_done
19 fi
20
21 test_expect_success 'setup' '
22 git init worktree &&
23 cd worktree &&
24 mkdir done dtwo dthree &&
25 touch one two three done/one dtwo/two dthree/three &&
26 git add one two done/one &&
27 : >.git/info/exclude &&
28 git update-index --untracked-cache
29 '
30
31 test_expect_success 'untracked cache is empty' '
32 test-dump-untracked-cache >../actual &&
33 cat >../expect <<EOF &&
34 info/exclude 0000000000000000000000000000000000000000
35 core.excludesfile 0000000000000000000000000000000000000000
36 exclude_per_dir .gitignore
37 flags 00000006
38 EOF
39 test_cmp ../expect ../actual
40 '
41
42 cat >../status.expect <<EOF &&
43 A done/one
44 A one
45 A two
46 ?? dthree/
47 ?? dtwo/
48 ?? three
49 EOF
50
51 cat >../dump.expect <<EOF &&
52 info/exclude e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
53 core.excludesfile 0000000000000000000000000000000000000000
54 exclude_per_dir .gitignore
55 flags 00000006
56 / 0000000000000000000000000000000000000000 recurse valid
57 dthree/
58 dtwo/
59 three
60 /done/ 0000000000000000000000000000000000000000 recurse valid
61 /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
62 three
63 /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
64 two
65 EOF
66
67 test_expect_success 'status first time (empty cache)' '
68 avoid_racy &&
69 : >../trace &&
70 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
71 git status --porcelain >../actual &&
72 test_cmp ../status.expect ../actual &&
73 cat >../trace.expect <<EOF &&
74 node creation: 3
75 gitignore invalidation: 1
76 directory invalidation: 0
77 opendir: 4
78 EOF
79 test_cmp ../trace.expect ../trace
80 '
81
82 test_expect_success 'untracked cache after first status' '
83 test-dump-untracked-cache >../actual &&
84 test_cmp ../dump.expect ../actual
85 '
86
87 test_expect_success 'status second time (fully populated cache)' '
88 avoid_racy &&
89 : >../trace &&
90 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
91 git status --porcelain >../actual &&
92 test_cmp ../status.expect ../actual &&
93 cat >../trace.expect <<EOF &&
94 node creation: 0
95 gitignore invalidation: 0
96 directory invalidation: 0
97 opendir: 0
98 EOF
99 test_cmp ../trace.expect ../trace
100 '
101
102 test_expect_success 'untracked cache after second status' '
103 test-dump-untracked-cache >../actual &&
104 test_cmp ../dump.expect ../actual
105 '
106
107 test_expect_success 'modify in root directory, one dir invalidation' '
108 avoid_racy &&
109 : >four &&
110 : >../trace &&
111 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
112 git status --porcelain >../actual &&
113 cat >../status.expect <<EOF &&
114 A done/one
115 A one
116 A two
117 ?? dthree/
118 ?? dtwo/
119 ?? four
120 ?? three
121 EOF
122 test_cmp ../status.expect ../actual &&
123 cat >../trace.expect <<EOF &&
124 node creation: 0
125 gitignore invalidation: 0
126 directory invalidation: 1
127 opendir: 1
128 EOF
129 test_cmp ../trace.expect ../trace
130
131 '
132
133 test_expect_success 'verify untracked cache dump' '
134 test-dump-untracked-cache >../actual &&
135 cat >../expect <<EOF &&
136 info/exclude e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
137 core.excludesfile 0000000000000000000000000000000000000000
138 exclude_per_dir .gitignore
139 flags 00000006
140 / 0000000000000000000000000000000000000000 recurse valid
141 dthree/
142 dtwo/
143 four
144 three
145 /done/ 0000000000000000000000000000000000000000 recurse valid
146 /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
147 three
148 /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
149 two
150 EOF
151 test_cmp ../expect ../actual
152 '
153
154 test_expect_success 'new .gitignore invalidates recursively' '
155 avoid_racy &&
156 echo four >.gitignore &&
157 : >../trace &&
158 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
159 git status --porcelain >../actual &&
160 cat >../status.expect <<EOF &&
161 A done/one
162 A one
163 A two
164 ?? .gitignore
165 ?? dthree/
166 ?? dtwo/
167 ?? three
168 EOF
169 test_cmp ../status.expect ../actual &&
170 cat >../trace.expect <<EOF &&
171 node creation: 0
172 gitignore invalidation: 1
173 directory invalidation: 1
174 opendir: 4
175 EOF
176 test_cmp ../trace.expect ../trace
177
178 '
179
180 test_expect_success 'verify untracked cache dump' '
181 test-dump-untracked-cache >../actual &&
182 cat >../expect <<EOF &&
183 info/exclude e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
184 core.excludesfile 0000000000000000000000000000000000000000
185 exclude_per_dir .gitignore
186 flags 00000006
187 / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
188 .gitignore
189 dthree/
190 dtwo/
191 three
192 /done/ 0000000000000000000000000000000000000000 recurse valid
193 /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
194 three
195 /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
196 two
197 EOF
198 test_cmp ../expect ../actual
199 '
200
201 test_expect_success 'new info/exclude invalidates everything' '
202 avoid_racy &&
203 echo three >>.git/info/exclude &&
204 : >../trace &&
205 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
206 git status --porcelain >../actual &&
207 cat >../status.expect <<EOF &&
208 A done/one
209 A one
210 A two
211 ?? .gitignore
212 ?? dtwo/
213 EOF
214 test_cmp ../status.expect ../actual &&
215 cat >../trace.expect <<EOF &&
216 node creation: 0
217 gitignore invalidation: 1
218 directory invalidation: 0
219 opendir: 4
220 EOF
221 test_cmp ../trace.expect ../trace
222 '
223
224 test_expect_success 'verify untracked cache dump' '
225 test-dump-untracked-cache >../actual &&
226 cat >../expect <<EOF &&
227 info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
228 core.excludesfile 0000000000000000000000000000000000000000
229 exclude_per_dir .gitignore
230 flags 00000006
231 / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
232 .gitignore
233 dtwo/
234 /done/ 0000000000000000000000000000000000000000 recurse valid
235 /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
236 /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
237 two
238 EOF
239 test_cmp ../expect ../actual
240 '
241
242 test_expect_success 'move two from tracked to untracked' '
243 git rm --cached two &&
244 test-dump-untracked-cache >../actual &&
245 cat >../expect <<EOF &&
246 info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
247 core.excludesfile 0000000000000000000000000000000000000000
248 exclude_per_dir .gitignore
249 flags 00000006
250 / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse
251 /done/ 0000000000000000000000000000000000000000 recurse valid
252 /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
253 /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
254 two
255 EOF
256 test_cmp ../expect ../actual
257 '
258
259 test_expect_success 'status after the move' '
260 : >../trace &&
261 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
262 git status --porcelain >../actual &&
263 cat >../status.expect <<EOF &&
264 A done/one
265 A one
266 ?? .gitignore
267 ?? dtwo/
268 ?? two
269 EOF
270 test_cmp ../status.expect ../actual &&
271 cat >../trace.expect <<EOF &&
272 node creation: 0
273 gitignore invalidation: 0
274 directory invalidation: 0
275 opendir: 1
276 EOF
277 test_cmp ../trace.expect ../trace
278 '
279
280 test_expect_success 'verify untracked cache dump' '
281 test-dump-untracked-cache >../actual &&
282 cat >../expect <<EOF &&
283 info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
284 core.excludesfile 0000000000000000000000000000000000000000
285 exclude_per_dir .gitignore
286 flags 00000006
287 / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
288 .gitignore
289 dtwo/
290 two
291 /done/ 0000000000000000000000000000000000000000 recurse valid
292 /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
293 /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
294 two
295 EOF
296 test_cmp ../expect ../actual
297 '
298
299 test_expect_success 'move two from untracked to tracked' '
300 git add two &&
301 test-dump-untracked-cache >../actual &&
302 cat >../expect <<EOF &&
303 info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
304 core.excludesfile 0000000000000000000000000000000000000000
305 exclude_per_dir .gitignore
306 flags 00000006
307 / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse
308 /done/ 0000000000000000000000000000000000000000 recurse valid
309 /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
310 /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
311 two
312 EOF
313 test_cmp ../expect ../actual
314 '
315
316 test_expect_success 'status after the move' '
317 : >../trace &&
318 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
319 git status --porcelain >../actual &&
320 cat >../status.expect <<EOF &&
321 A done/one
322 A one
323 A two
324 ?? .gitignore
325 ?? dtwo/
326 EOF
327 test_cmp ../status.expect ../actual &&
328 cat >../trace.expect <<EOF &&
329 node creation: 0
330 gitignore invalidation: 0
331 directory invalidation: 0
332 opendir: 1
333 EOF
334 test_cmp ../trace.expect ../trace
335 '
336
337 test_expect_success 'verify untracked cache dump' '
338 test-dump-untracked-cache >../actual &&
339 cat >../expect <<EOF &&
340 info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
341 core.excludesfile 0000000000000000000000000000000000000000
342 exclude_per_dir .gitignore
343 flags 00000006
344 / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
345 .gitignore
346 dtwo/
347 /done/ 0000000000000000000000000000000000000000 recurse valid
348 /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
349 /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
350 two
351 EOF
352 test_cmp ../expect ../actual
353 '
354
355 test_expect_success 'set up for sparse checkout testing' '
356 echo two >done/.gitignore &&
357 echo three >>done/.gitignore &&
358 echo two >done/two &&
359 git add -f done/two done/.gitignore &&
360 git commit -m "first commit"
361 '
362
363 test_expect_success 'status after commit' '
364 : >../trace &&
365 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
366 git status --porcelain >../actual &&
367 cat >../status.expect <<EOF &&
368 ?? .gitignore
369 ?? dtwo/
370 EOF
371 test_cmp ../status.expect ../actual &&
372 cat >../trace.expect <<EOF &&
373 node creation: 0
374 gitignore invalidation: 0
375 directory invalidation: 0
376 opendir: 2
377 EOF
378 test_cmp ../trace.expect ../trace
379 '
380
381 test_expect_success 'untracked cache correct after commit' '
382 test-dump-untracked-cache >../actual &&
383 cat >../expect <<EOF &&
384 info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
385 core.excludesfile 0000000000000000000000000000000000000000
386 exclude_per_dir .gitignore
387 flags 00000006
388 / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
389 .gitignore
390 dtwo/
391 /done/ 0000000000000000000000000000000000000000 recurse valid
392 /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
393 /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
394 two
395 EOF
396 test_cmp ../expect ../actual
397 '
398
399 test_expect_success 'set up sparse checkout' '
400 echo "done/[a-z]*" >.git/info/sparse-checkout &&
401 test_config core.sparsecheckout true &&
402 git checkout master &&
403 git update-index --force-untracked-cache &&
404 git status --porcelain >/dev/null && # prime the cache
405 test_path_is_missing done/.gitignore &&
406 test_path_is_file done/one
407 '
408
409 test_expect_success 'create/modify files, some of which are gitignored' '
410 echo two bis >done/two &&
411 echo three >done/three && # three is gitignored
412 echo four >done/four && # four is gitignored at a higher level
413 echo five >done/five && # five is not gitignored
414 echo test >base && #we need to ensure that the root dir is touched
415 rm base
416 '
417
418 test_expect_success 'test sparse status with untracked cache' '
419 : >../trace &&
420 avoid_racy &&
421 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
422 git status --porcelain >../status.actual &&
423 cat >../status.expect <<EOF &&
424 M done/two
425 ?? .gitignore
426 ?? done/five
427 ?? dtwo/
428 EOF
429 test_cmp ../status.expect ../status.actual &&
430 cat >../trace.expect <<EOF &&
431 node creation: 0
432 gitignore invalidation: 1
433 directory invalidation: 2
434 opendir: 2
435 EOF
436 test_cmp ../trace.expect ../trace
437 '
438
439 test_expect_success 'untracked cache correct after status' '
440 test-dump-untracked-cache >../actual &&
441 cat >../expect <<EOF &&
442 info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
443 core.excludesfile 0000000000000000000000000000000000000000
444 exclude_per_dir .gitignore
445 flags 00000006
446 / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
447 .gitignore
448 dtwo/
449 /done/ 1946f0437f90c5005533cbe1736a6451ca301714 recurse valid
450 five
451 /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
452 /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
453 two
454 EOF
455 test_cmp ../expect ../actual
456 '
457
458 test_expect_success 'test sparse status again with untracked cache' '
459 avoid_racy &&
460 : >../trace &&
461 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
462 git status --porcelain >../status.actual &&
463 cat >../status.expect <<EOF &&
464 M done/two
465 ?? .gitignore
466 ?? done/five
467 ?? dtwo/
468 EOF
469 test_cmp ../status.expect ../status.actual &&
470 cat >../trace.expect <<EOF &&
471 node creation: 0
472 gitignore invalidation: 0
473 directory invalidation: 0
474 opendir: 0
475 EOF
476 test_cmp ../trace.expect ../trace
477 '
478
479 test_expect_success 'set up for test of subdir and sparse checkouts' '
480 mkdir done/sub &&
481 mkdir done/sub/sub &&
482 echo "sub" > done/sub/sub/file
483 '
484
485 test_expect_success 'test sparse status with untracked cache and subdir' '
486 avoid_racy &&
487 : >../trace &&
488 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
489 git status --porcelain >../status.actual &&
490 cat >../status.expect <<EOF &&
491 M done/two
492 ?? .gitignore
493 ?? done/five
494 ?? done/sub/
495 ?? dtwo/
496 EOF
497 test_cmp ../status.expect ../status.actual &&
498 cat >../trace.expect <<EOF &&
499 node creation: 2
500 gitignore invalidation: 0
501 directory invalidation: 1
502 opendir: 3
503 EOF
504 test_cmp ../trace.expect ../trace
505 '
506
507 test_expect_success 'verify untracked cache dump (sparse/subdirs)' '
508 test-dump-untracked-cache >../actual &&
509 cat >../expect <<EOF &&
510 info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
511 core.excludesfile 0000000000000000000000000000000000000000
512 exclude_per_dir .gitignore
513 flags 00000006
514 / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
515 .gitignore
516 dtwo/
517 /done/ 1946f0437f90c5005533cbe1736a6451ca301714 recurse valid
518 five
519 sub/
520 /done/sub/ 0000000000000000000000000000000000000000 recurse check_only valid
521 sub/
522 /done/sub/sub/ 0000000000000000000000000000000000000000 recurse check_only valid
523 file
524 /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
525 /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
526 two
527 EOF
528 test_cmp ../expect ../actual
529 '
530
531 test_expect_success 'test sparse status again with untracked cache and subdir' '
532 avoid_racy &&
533 : >../trace &&
534 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
535 git status --porcelain >../status.actual &&
536 test_cmp ../status.expect ../status.actual &&
537 cat >../trace.expect <<EOF &&
538 node creation: 0
539 gitignore invalidation: 0
540 directory invalidation: 0
541 opendir: 0
542 EOF
543 test_cmp ../trace.expect ../trace
544 '
545
546 test_expect_success 'move entry in subdir from untracked to cached' '
547 git add dtwo/two &&
548 git status --porcelain >../status.actual &&
549 cat >../status.expect <<EOF &&
550 M done/two
551 A dtwo/two
552 ?? .gitignore
553 ?? done/five
554 ?? done/sub/
555 EOF
556 test_cmp ../status.expect ../status.actual
557 '
558
559 test_expect_success 'move entry in subdir from cached to untracked' '
560 git rm --cached dtwo/two &&
561 git status --porcelain >../status.actual &&
562 cat >../status.expect <<EOF &&
563 M done/two
564 ?? .gitignore
565 ?? done/five
566 ?? done/sub/
567 ?? dtwo/
568 EOF
569 test_cmp ../status.expect ../status.actual
570 '
571
572 test_done