3 test_description='test untracked cache'
11 # It's fine if git update-index returns an error code other than one,
12 # it'll be caught in the first test.
13 test_lazy_prereq UNTRACKED_CACHE '
14 { git update-index --untracked-cache; ret=$?; } &&
18 if ! test_have_prereq UNTRACKED_CACHE; then
19 skip_all='This system does not support untracked cache'
23 test_expect_success 'setup' '
26 mkdir done dtwo dthree &&
27 touch one two three done/one dtwo/two dthree/three &&
28 git add one two done/one &&
29 : >.git/info/exclude &&
30 git update-index --untracked-cache
33 test_expect_success 'untracked cache is empty' '
34 test-dump-untracked-cache >../actual &&
35 cat >../expect <<EOF &&
36 info/exclude 0000000000000000000000000000000000000000
37 core.excludesfile 0000000000000000000000000000000000000000
38 exclude_per_dir .gitignore
41 test_cmp ../expect ../actual
44 cat >../status.expect <<EOF &&
53 cat >../dump.expect <<EOF &&
54 info/exclude e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
55 core.excludesfile 0000000000000000000000000000000000000000
56 exclude_per_dir .gitignore
58 / 0000000000000000000000000000000000000000 recurse valid
62 /done/ 0000000000000000000000000000000000000000 recurse valid
63 /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
65 /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
69 test_expect_success 'status first time (empty cache)' '
72 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
73 git status --porcelain >../actual &&
74 test_cmp ../status.expect ../actual &&
75 cat >../trace.expect <<EOF &&
77 gitignore invalidation: 1
78 directory invalidation: 0
81 test_cmp ../trace.expect ../trace
84 test_expect_success 'untracked cache after first status' '
85 test-dump-untracked-cache >../actual &&
86 test_cmp ../dump.expect ../actual
89 test_expect_success 'status second time (fully populated cache)' '
92 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
93 git status --porcelain >../actual &&
94 test_cmp ../status.expect ../actual &&
95 cat >../trace.expect <<EOF &&
97 gitignore invalidation: 0
98 directory invalidation: 0
101 test_cmp ../trace.expect ../trace
104 test_expect_success 'untracked cache after second status' '
105 test-dump-untracked-cache >../actual &&
106 test_cmp ../dump.expect ../actual
109 test_expect_success 'modify in root directory, one dir invalidation' '
113 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
114 git status --porcelain >../actual &&
115 cat >../status.expect <<EOF &&
124 test_cmp ../status.expect ../actual &&
125 cat >../trace.expect <<EOF &&
127 gitignore invalidation: 0
128 directory invalidation: 1
131 test_cmp ../trace.expect ../trace
135 test_expect_success 'verify untracked cache dump' '
136 test-dump-untracked-cache >../actual &&
137 cat >../expect <<EOF &&
138 info/exclude e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
139 core.excludesfile 0000000000000000000000000000000000000000
140 exclude_per_dir .gitignore
142 / 0000000000000000000000000000000000000000 recurse valid
147 /done/ 0000000000000000000000000000000000000000 recurse valid
148 /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
150 /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
153 test_cmp ../expect ../actual
156 test_expect_success 'new .gitignore invalidates recursively' '
158 echo four >.gitignore &&
160 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
161 git status --porcelain >../actual &&
162 cat >../status.expect <<EOF &&
171 test_cmp ../status.expect ../actual &&
172 cat >../trace.expect <<EOF &&
174 gitignore invalidation: 1
175 directory invalidation: 1
178 test_cmp ../trace.expect ../trace
182 test_expect_success 'verify untracked cache dump' '
183 test-dump-untracked-cache >../actual &&
184 cat >../expect <<EOF &&
185 info/exclude e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
186 core.excludesfile 0000000000000000000000000000000000000000
187 exclude_per_dir .gitignore
189 / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
194 /done/ 0000000000000000000000000000000000000000 recurse valid
195 /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
197 /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
200 test_cmp ../expect ../actual
203 test_expect_success 'new info/exclude invalidates everything' '
205 echo three >>.git/info/exclude &&
207 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
208 git status --porcelain >../actual &&
209 cat >../status.expect <<EOF &&
216 test_cmp ../status.expect ../actual &&
217 cat >../trace.expect <<EOF &&
219 gitignore invalidation: 1
220 directory invalidation: 0
223 test_cmp ../trace.expect ../trace
226 test_expect_success 'verify untracked cache dump' '
227 test-dump-untracked-cache >../actual &&
228 cat >../expect <<EOF &&
229 info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
230 core.excludesfile 0000000000000000000000000000000000000000
231 exclude_per_dir .gitignore
233 / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
236 /done/ 0000000000000000000000000000000000000000 recurse valid
237 /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
238 /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
241 test_cmp ../expect ../actual
244 test_expect_success 'move two from tracked to untracked' '
245 git rm --cached two &&
246 test-dump-untracked-cache >../actual &&
247 cat >../expect <<EOF &&
248 info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
249 core.excludesfile 0000000000000000000000000000000000000000
250 exclude_per_dir .gitignore
252 / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse
253 /done/ 0000000000000000000000000000000000000000 recurse valid
254 /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
255 /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
258 test_cmp ../expect ../actual
261 test_expect_success 'status after the move' '
263 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
264 git status --porcelain >../actual &&
265 cat >../status.expect <<EOF &&
272 test_cmp ../status.expect ../actual &&
273 cat >../trace.expect <<EOF &&
275 gitignore invalidation: 0
276 directory invalidation: 0
279 test_cmp ../trace.expect ../trace
282 test_expect_success 'verify untracked cache dump' '
283 test-dump-untracked-cache >../actual &&
284 cat >../expect <<EOF &&
285 info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
286 core.excludesfile 0000000000000000000000000000000000000000
287 exclude_per_dir .gitignore
289 / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
293 /done/ 0000000000000000000000000000000000000000 recurse valid
294 /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
295 /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
298 test_cmp ../expect ../actual
301 test_expect_success 'move two from untracked to tracked' '
303 test-dump-untracked-cache >../actual &&
304 cat >../expect <<EOF &&
305 info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
306 core.excludesfile 0000000000000000000000000000000000000000
307 exclude_per_dir .gitignore
309 / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse
310 /done/ 0000000000000000000000000000000000000000 recurse valid
311 /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
312 /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
315 test_cmp ../expect ../actual
318 test_expect_success 'status after the move' '
320 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
321 git status --porcelain >../actual &&
322 cat >../status.expect <<EOF &&
329 test_cmp ../status.expect ../actual &&
330 cat >../trace.expect <<EOF &&
332 gitignore invalidation: 0
333 directory invalidation: 0
336 test_cmp ../trace.expect ../trace
339 test_expect_success 'verify untracked cache dump' '
340 test-dump-untracked-cache >../actual &&
341 cat >../expect <<EOF &&
342 info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
343 core.excludesfile 0000000000000000000000000000000000000000
344 exclude_per_dir .gitignore
346 / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
349 /done/ 0000000000000000000000000000000000000000 recurse valid
350 /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
351 /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
354 test_cmp ../expect ../actual
357 test_expect_success 'set up for sparse checkout testing' '
358 echo two >done/.gitignore &&
359 echo three >>done/.gitignore &&
360 echo two >done/two &&
361 git add -f done/two done/.gitignore &&
362 git commit -m "first commit"
365 test_expect_success 'status after commit' '
367 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
368 git status --porcelain >../actual &&
369 cat >../status.expect <<EOF &&
373 test_cmp ../status.expect ../actual &&
374 cat >../trace.expect <<EOF &&
376 gitignore invalidation: 0
377 directory invalidation: 0
380 test_cmp ../trace.expect ../trace
383 test_expect_success 'untracked cache correct after commit' '
384 test-dump-untracked-cache >../actual &&
385 cat >../expect <<EOF &&
386 info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
387 core.excludesfile 0000000000000000000000000000000000000000
388 exclude_per_dir .gitignore
390 / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
393 /done/ 0000000000000000000000000000000000000000 recurse valid
394 /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
395 /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
398 test_cmp ../expect ../actual
401 test_expect_success 'set up sparse checkout' '
402 echo "done/[a-z]*" >.git/info/sparse-checkout &&
403 test_config core.sparsecheckout true &&
404 git checkout master &&
405 git update-index --force-untracked-cache &&
406 git status --porcelain >/dev/null && # prime the cache
407 test_path_is_missing done/.gitignore &&
408 test_path_is_file done/one
411 test_expect_success 'create/modify files, some of which are gitignored' '
412 echo two bis >done/two &&
413 echo three >done/three && # three is gitignored
414 echo four >done/four && # four is gitignored at a higher level
415 echo five >done/five # five is not gitignored
418 test_expect_success 'test sparse status with untracked cache' '
421 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
422 git status --porcelain >../status.actual &&
423 cat >../status.expect <<EOF &&
429 test_cmp ../status.expect ../status.actual &&
430 cat >../trace.expect <<EOF &&
432 gitignore invalidation: 1
433 directory invalidation: 2
436 test_cmp ../trace.expect ../trace
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
446 / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
449 /done/ 1946f0437f90c5005533cbe1736a6451ca301714 recurse valid
451 /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
452 /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
455 test_cmp ../expect ../actual
458 test_expect_success 'test sparse status again with untracked cache' '
461 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
462 git status --porcelain >../status.actual &&
463 cat >../status.expect <<EOF &&
469 test_cmp ../status.expect ../status.actual &&
470 cat >../trace.expect <<EOF &&
472 gitignore invalidation: 0
473 directory invalidation: 0
476 test_cmp ../trace.expect ../trace
479 test_expect_success 'set up for test of subdir and sparse checkouts' '
481 mkdir done/sub/sub &&
482 echo "sub" > done/sub/sub/file
485 test_expect_success 'test sparse status with untracked cache and subdir' '
488 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
489 git status --porcelain >../status.actual &&
490 cat >../status.expect <<EOF &&
497 test_cmp ../status.expect ../status.actual &&
498 cat >../trace.expect <<EOF &&
500 gitignore invalidation: 0
501 directory invalidation: 1
504 test_cmp ../trace.expect ../trace
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
514 / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
517 /done/ 1946f0437f90c5005533cbe1736a6451ca301714 recurse valid
520 /done/sub/ 0000000000000000000000000000000000000000 recurse check_only valid
522 /done/sub/sub/ 0000000000000000000000000000000000000000 recurse check_only valid
524 /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
525 /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
528 test_cmp ../expect ../actual
531 test_expect_success 'test sparse status again with untracked cache and subdir' '
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 &&
539 gitignore invalidation: 0
540 directory invalidation: 0
543 test_cmp ../trace.expect ../trace
546 test_expect_success 'move entry in subdir from untracked to cached' '
548 git status --porcelain >../status.actual &&
549 cat >../status.expect <<EOF &&
556 test_cmp ../status.expect ../status.actual
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 &&
569 test_cmp ../status.expect ../status.actual