3 test_description
='test untracked cache'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 # On some filesystems (e.g. FreeBSD's ext2 and ufs) directory mtime
11 # is updated lazily after contents in the directory changes, which
12 # forces the untracked cache code to take the slow path. A test
13 # that wants to make sure that the fast path works correctly should
14 # call this helper to make mtime of the containing directory in sync
15 # with the reality before checking the fast path behaviour.
17 # See <20160803174522.5571-1-pclouds@gmail.com> if you want to know
20 GIT_FORCE_UNTRACKED_CACHE
=true
21 export GIT_FORCE_UNTRACKED_CACHE
24 find .
-type d
-exec ls -ld {} + >/dev
/null
32 git status
--porcelain >..
/status.actual
&&
33 test_must_be_empty ..
/status.actual
36 # Ignore_Untracked_Cache, abbreviated to 3 letters because then people can
37 # compare commands side-by-side, e.g.
38 # iuc status --porcelain >expect &&
39 # git status --porcelain >actual &&
40 # test_cmp expect actual
42 git ls-files
-s >..
/current-index-entries
43 git ls-files
-t |
sed -ne s
/^S.
//p
>..
/current-sparse-entries
45 GIT_INDEX_FILE
=.git
/tmp_index
47 git update-index
--index-info <..
/current-index-entries
48 git update-index
--skip-worktree $
(cat ..
/current-sparse-entries
)
50 git
-c core.untrackedCache
=false
"$@"
53 rm ..
/current-index-entries
60 get_relevant_traces
() {
61 # From the GIT_TRACE2_PERF data of the form
62 # $TIME $FILE:$LINE | d0 | main | data | r1 | ? | ? | read_directo | $RELEVANT_STAT
63 # extract the $RELEVANT_STAT fields. We don't care about region_enter
64 # or region_leave, or stats for things outside read_directory.
67 grep data.
*read_directo
$INPUT_FILE |
74 test_lazy_prereq UNTRACKED_CACHE
'
75 { git update-index --test-untracked-cache; ret=$?; } &&
79 if ! test_have_prereq UNTRACKED_CACHE
; then
80 skip_all
='This system does not support untracked cache'
84 test_expect_success
'core.untrackedCache is unset' '
85 test_must_fail git config --get core.untrackedCache
88 test_expect_success
'setup' '
91 mkdir done dtwo dthree &&
92 touch one two three done/one dtwo/two dthree/three &&
93 test-tool chmtime =-300 one two three done/one dtwo/two dthree/three &&
94 test-tool chmtime =-300 done dtwo dthree &&
95 test-tool chmtime =-300 . &&
96 git add one two done/one &&
97 : >.git/info/exclude &&
98 git update-index --untracked-cache &&
100 root sha1:e6fcc8f2ee31bae321d66afd183fcb7237afae6e
101 root sha256:b90c672088c015b9c83876e919da311bad4cd39639fb139f988af6a11493b974
103 exclude sha1:13263c0978fb9fad16b2d580fb800b6d811c3ff0
104 exclude sha256:fe4aaa1bbbbce4cb8f73426748a14c5ad6026b26f90505a0bf2494b165a5b76c
106 done sha1:1946f0437f90c5005533cbe1736a6451ca301714
107 done sha256:7f079501d79f665b3acc50f5e0e9e94509084d5032ac20113a37dd5029b757cc
111 test_expect_success
'untracked cache is empty' '
112 test-tool dump-untracked-cache >../actual &&
113 cat >../expect-empty <<EOF &&
114 info/exclude $ZERO_OID
115 core.excludesfile $ZERO_OID
116 exclude_per_dir .gitignore
119 test_cmp ../expect-empty ../actual
122 cat >..
/status.expect
<<EOF &&
131 cat >..
/dump.expect
<<EOF &&
132 info/exclude $EMPTY_BLOB
133 core.excludesfile $ZERO_OID
134 exclude_per_dir .gitignore
136 / $ZERO_OID recurse valid
140 /done/ $ZERO_OID recurse valid
141 /dthree/ $ZERO_OID recurse check_only valid
143 /dtwo/ $ZERO_OID recurse check_only valid
147 test_expect_success
'status first time (empty cache)' '
148 : >../trace.output &&
149 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
150 git status --porcelain >../actual &&
151 iuc status --porcelain >../status.iuc &&
152 test_cmp ../status.expect ../status.iuc &&
153 test_cmp ../status.expect ../actual &&
154 get_relevant_traces ../trace.output ../trace.relevant &&
155 cat >../trace.expect <<EOF &&
158 ....gitignore-invalidation:1
159 ....directory-invalidation:0
162 test_cmp ../trace.expect ../trace.relevant
165 test_expect_success
'untracked cache after first status' '
166 test-tool dump-untracked-cache >../actual &&
167 test_cmp ../dump.expect ../actual
170 test_expect_success
'status second time (fully populated cache)' '
171 : >../trace.output &&
172 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
173 git status --porcelain >../actual &&
174 iuc status --porcelain >../status.iuc &&
175 test_cmp ../status.expect ../status.iuc &&
176 test_cmp ../status.expect ../actual &&
177 get_relevant_traces ../trace.output ../trace.relevant &&
178 cat >../trace.expect <<EOF &&
181 ....gitignore-invalidation:0
182 ....directory-invalidation:0
185 test_cmp ../trace.expect ../trace.relevant
188 test_expect_success
'untracked cache after second status' '
189 test-tool dump-untracked-cache >../actual &&
190 test_cmp ../dump.expect ../actual
193 test_expect_success
'modify in root directory, one dir invalidation' '
195 test-tool chmtime =-240 four &&
196 : >../trace.output &&
197 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
198 git status --porcelain >../actual &&
199 iuc status --porcelain >../status.iuc &&
200 cat >../status.expect <<EOF &&
209 test_cmp ../status.expect ../status.iuc &&
210 test_cmp ../status.expect ../actual &&
211 get_relevant_traces ../trace.output ../trace.relevant &&
212 cat >../trace.expect <<EOF &&
215 ....gitignore-invalidation:0
216 ....directory-invalidation:1
219 test_cmp ../trace.expect ../trace.relevant
223 test_expect_success
'verify untracked cache dump' '
224 test-tool dump-untracked-cache >../actual &&
225 cat >../expect <<EOF &&
226 info/exclude $EMPTY_BLOB
227 core.excludesfile $ZERO_OID
228 exclude_per_dir .gitignore
230 / $ZERO_OID recurse valid
235 /done/ $ZERO_OID recurse valid
236 /dthree/ $ZERO_OID recurse check_only valid
238 /dtwo/ $ZERO_OID recurse check_only valid
241 test_cmp ../expect ../actual
244 test_expect_success
'new .gitignore invalidates recursively' '
245 echo four >.gitignore &&
246 : >../trace.output &&
247 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
248 git status --porcelain >../actual &&
249 iuc status --porcelain >../status.iuc &&
250 cat >../status.expect <<EOF &&
259 test_cmp ../status.expect ../status.iuc &&
260 test_cmp ../status.expect ../actual &&
261 get_relevant_traces ../trace.output ../trace.relevant &&
262 cat >../trace.expect <<EOF &&
265 ....gitignore-invalidation:1
266 ....directory-invalidation:1
269 test_cmp ../trace.expect ../trace.relevant
273 test_expect_success
'verify untracked cache dump' '
274 test-tool dump-untracked-cache >../actual &&
275 cat >../expect <<EOF &&
276 info/exclude $EMPTY_BLOB
277 core.excludesfile $ZERO_OID
278 exclude_per_dir .gitignore
280 / $(test_oid root) recurse valid
285 /done/ $ZERO_OID recurse valid
286 /dthree/ $ZERO_OID recurse check_only valid
288 /dtwo/ $ZERO_OID recurse check_only valid
291 test_cmp ../expect ../actual
294 test_expect_success
'new info/exclude invalidates everything' '
295 echo three >>.git/info/exclude &&
296 : >../trace.output &&
297 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
298 git status --porcelain >../actual &&
299 iuc status --porcelain >../status.iuc &&
300 cat >../status.expect <<EOF &&
307 test_cmp ../status.expect ../status.iuc &&
308 test_cmp ../status.expect ../actual &&
309 get_relevant_traces ../trace.output ../trace.relevant &&
310 cat >../trace.expect <<EOF &&
313 ....gitignore-invalidation:1
314 ....directory-invalidation:0
317 test_cmp ../trace.expect ../trace.relevant
320 test_expect_success
'verify untracked cache dump' '
321 test-tool dump-untracked-cache >../actual &&
322 cat >../expect <<EOF &&
323 info/exclude $(test_oid exclude)
324 core.excludesfile $ZERO_OID
325 exclude_per_dir .gitignore
327 / $(test_oid root) recurse valid
330 /done/ $ZERO_OID recurse valid
331 /dthree/ $ZERO_OID recurse check_only valid
332 /dtwo/ $ZERO_OID recurse check_only valid
335 test_cmp ../expect ../actual
338 test_expect_success
'move two from tracked to untracked' '
339 git rm --cached two &&
340 test-tool dump-untracked-cache >../actual &&
341 cat >../expect <<EOF &&
342 info/exclude $(test_oid exclude)
343 core.excludesfile $ZERO_OID
344 exclude_per_dir .gitignore
346 / $(test_oid root) recurse
347 /done/ $ZERO_OID recurse valid
348 /dthree/ $ZERO_OID recurse check_only valid
349 /dtwo/ $ZERO_OID recurse check_only valid
352 test_cmp ../expect ../actual
355 test_expect_success
'status after the move' '
356 : >../trace.output &&
357 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
358 git status --porcelain >../actual &&
359 iuc status --porcelain >../status.iuc &&
360 cat >../status.expect <<EOF &&
367 test_cmp ../status.expect ../status.iuc &&
368 test_cmp ../status.expect ../actual &&
369 get_relevant_traces ../trace.output ../trace.relevant &&
370 cat >../trace.expect <<EOF &&
373 ....gitignore-invalidation:0
374 ....directory-invalidation:0
377 test_cmp ../trace.expect ../trace.relevant
380 test_expect_success
'verify untracked cache dump' '
381 test-tool dump-untracked-cache >../actual &&
382 cat >../expect <<EOF &&
383 info/exclude $(test_oid exclude)
384 core.excludesfile $ZERO_OID
385 exclude_per_dir .gitignore
387 / $(test_oid root) recurse valid
391 /done/ $ZERO_OID recurse valid
392 /dthree/ $ZERO_OID recurse check_only valid
393 /dtwo/ $ZERO_OID recurse check_only valid
396 test_cmp ../expect ../actual
399 test_expect_success
'move two from untracked to tracked' '
401 test-tool dump-untracked-cache >../actual &&
402 cat >../expect <<EOF &&
403 info/exclude $(test_oid exclude)
404 core.excludesfile $ZERO_OID
405 exclude_per_dir .gitignore
407 / $(test_oid root) recurse
408 /done/ $ZERO_OID recurse valid
409 /dthree/ $ZERO_OID recurse check_only valid
410 /dtwo/ $ZERO_OID recurse check_only valid
413 test_cmp ../expect ../actual
416 test_expect_success
'status after the move' '
417 : >../trace.output &&
418 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
419 git status --porcelain >../actual &&
420 iuc status --porcelain >../status.iuc &&
421 cat >../status.expect <<EOF &&
428 test_cmp ../status.expect ../status.iuc &&
429 test_cmp ../status.expect ../actual &&
430 get_relevant_traces ../trace.output ../trace.relevant &&
431 cat >../trace.expect <<EOF &&
434 ....gitignore-invalidation:0
435 ....directory-invalidation:0
438 test_cmp ../trace.expect ../trace.relevant
441 test_expect_success
'verify untracked cache dump' '
442 test-tool dump-untracked-cache >../actual &&
443 cat >../expect <<EOF &&
444 info/exclude $(test_oid exclude)
445 core.excludesfile $ZERO_OID
446 exclude_per_dir .gitignore
448 / $(test_oid root) recurse valid
451 /done/ $ZERO_OID recurse valid
452 /dthree/ $ZERO_OID recurse check_only valid
453 /dtwo/ $ZERO_OID recurse check_only valid
456 test_cmp ../expect ../actual
459 test_expect_success
'set up for sparse checkout testing' '
460 echo two >done/.gitignore &&
461 echo three >>done/.gitignore &&
462 echo two >done/two &&
463 git add -f done/two done/.gitignore &&
464 git commit -m "first commit"
467 test_expect_success
'status after commit' '
468 : >../trace.output &&
469 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
470 git status --porcelain >../actual &&
471 iuc status --porcelain >../status.iuc &&
472 cat >../status.expect <<EOF &&
476 test_cmp ../status.expect ../status.iuc &&
477 test_cmp ../status.expect ../actual &&
478 get_relevant_traces ../trace.output ../trace.relevant &&
479 cat >../trace.expect <<EOF &&
482 ....gitignore-invalidation:0
483 ....directory-invalidation:0
486 test_cmp ../trace.expect ../trace.relevant
489 test_expect_success
'untracked cache correct after commit' '
490 test-tool dump-untracked-cache >../actual &&
491 cat >../expect <<EOF &&
492 info/exclude $(test_oid exclude)
493 core.excludesfile $ZERO_OID
494 exclude_per_dir .gitignore
496 / $(test_oid root) recurse valid
499 /done/ $ZERO_OID recurse valid
500 /dthree/ $ZERO_OID recurse check_only valid
501 /dtwo/ $ZERO_OID recurse check_only valid
504 test_cmp ../expect ../actual
507 test_expect_success
'set up sparse checkout' '
508 echo "done/[a-z]*" >.git/info/sparse-checkout &&
509 test_config core.sparsecheckout true &&
511 git update-index --force-untracked-cache &&
512 git status --porcelain >/dev/null && # prime the cache
513 test_path_is_missing done/.gitignore &&
514 test_path_is_file done/one
517 test_expect_success
'create/modify files, some of which are gitignored' '
518 echo two bis >done/two &&
519 echo three >done/three && # three is gitignored
520 echo four >done/four && # four is gitignored at a higher level
521 echo five >done/five && # five is not gitignored
522 test-tool chmtime =-180 done/two done/three done/four done/five done &&
523 # we need to ensure that the root dir is touched (in the past);
524 test-tool chmtime =-180 . &&
528 test_expect_success
'test sparse status with untracked cache' '
529 : >../trace.output &&
530 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
531 git status --porcelain >../status.actual &&
532 iuc status --porcelain >../status.iuc &&
533 cat >../status.expect <<EOF &&
539 test_cmp ../status.expect ../status.iuc &&
540 test_cmp ../status.expect ../status.actual &&
541 get_relevant_traces ../trace.output ../trace.relevant &&
542 cat >../trace.expect <<EOF &&
545 ....gitignore-invalidation:1
546 ....directory-invalidation:2
549 test_cmp ../trace.expect ../trace.relevant
552 test_expect_success
'untracked cache correct after status' '
553 test-tool dump-untracked-cache >../actual &&
554 cat >../expect <<EOF &&
555 info/exclude $(test_oid exclude)
556 core.excludesfile $ZERO_OID
557 exclude_per_dir .gitignore
559 / $(test_oid root) recurse valid
562 /done/ $(test_oid done) recurse valid
564 /dthree/ $ZERO_OID recurse check_only valid
565 /dtwo/ $ZERO_OID recurse check_only valid
568 test_cmp ../expect ../actual
571 test_expect_success
'test sparse status again with untracked cache' '
572 : >../trace.output &&
573 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
574 git status --porcelain >../status.actual &&
575 iuc status --porcelain >../status.iuc &&
576 cat >../status.expect <<EOF &&
582 test_cmp ../status.expect ../status.iuc &&
583 test_cmp ../status.expect ../status.actual &&
584 get_relevant_traces ../trace.output ../trace.relevant &&
585 cat >../trace.expect <<EOF &&
588 ....gitignore-invalidation:0
589 ....directory-invalidation:0
592 test_cmp ../trace.expect ../trace.relevant
595 test_expect_success
'set up for test of subdir and sparse checkouts' '
597 mkdir done/sub/sub &&
598 echo "sub" > done/sub/sub/file &&
599 test-tool chmtime =-120 done/sub/sub/file done/sub/sub done/sub done
602 test_expect_success
'test sparse status with untracked cache and subdir' '
603 : >../trace.output &&
604 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
605 git status --porcelain >../status.actual &&
606 iuc status --porcelain >../status.iuc &&
607 cat >../status.expect <<EOF &&
614 test_cmp ../status.expect ../status.iuc &&
615 test_cmp ../status.expect ../status.actual &&
616 get_relevant_traces ../trace.output ../trace.relevant &&
617 cat >../trace.expect <<EOF &&
620 ....gitignore-invalidation:0
621 ....directory-invalidation:1
624 test_cmp ../trace.expect ../trace.relevant
627 test_expect_success
'verify untracked cache dump (sparse/subdirs)' '
628 test-tool dump-untracked-cache >../actual &&
629 cat >../expect-from-test-dump <<EOF &&
630 info/exclude $(test_oid exclude)
631 core.excludesfile $ZERO_OID
632 exclude_per_dir .gitignore
634 / $(test_oid root) recurse valid
637 /done/ $(test_oid done) recurse valid
640 /done/sub/ $ZERO_OID recurse check_only valid
642 /done/sub/sub/ $ZERO_OID recurse check_only valid
644 /dthree/ $ZERO_OID recurse check_only valid
645 /dtwo/ $ZERO_OID recurse check_only valid
648 test_cmp ../expect-from-test-dump ../actual
651 test_expect_success
'test sparse status again with untracked cache and subdir' '
652 : >../trace.output &&
653 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
654 git status --porcelain >../status.actual &&
655 iuc status --porcelain >../status.iuc &&
656 test_cmp ../status.expect ../status.iuc &&
657 test_cmp ../status.expect ../status.actual &&
658 get_relevant_traces ../trace.output ../trace.relevant &&
659 cat >../trace.expect <<EOF &&
662 ....gitignore-invalidation:0
663 ....directory-invalidation:0
666 test_cmp ../trace.expect ../trace.relevant
669 test_expect_success
'move entry in subdir from untracked to cached' '
671 git status --porcelain >../status.actual &&
672 iuc status --porcelain >../status.iuc &&
673 cat >../status.expect <<EOF &&
680 test_cmp ../status.expect ../status.iuc &&
681 test_cmp ../status.expect ../status.actual
684 test_expect_success
'move entry in subdir from cached to untracked' '
685 git rm --cached dtwo/two &&
686 git status --porcelain >../status.actual &&
687 iuc status --porcelain >../status.iuc &&
688 cat >../status.expect <<EOF &&
695 test_cmp ../status.expect ../status.iuc &&
696 test_cmp ../status.expect ../status.actual
699 test_expect_success
'--no-untracked-cache removes the cache' '
700 git update-index --no-untracked-cache &&
701 test-tool dump-untracked-cache >../actual &&
702 echo "no untracked cache" >../expect-no-uc &&
703 test_cmp ../expect-no-uc ../actual
706 test_expect_success
'git status does not change anything' '
708 test-tool dump-untracked-cache >../actual &&
709 test_cmp ../expect-no-uc ../actual
712 test_expect_success
'setting core.untrackedCache to true and using git status creates the cache' '
713 git config core.untrackedCache true &&
714 test-tool dump-untracked-cache >../actual &&
715 test_cmp ../expect-no-uc ../actual &&
717 test-tool dump-untracked-cache >../actual &&
718 test_cmp ../expect-from-test-dump ../actual
721 test_expect_success
'using --no-untracked-cache does not fail when core.untrackedCache is true' '
722 git update-index --no-untracked-cache &&
723 test-tool dump-untracked-cache >../actual &&
724 test_cmp ../expect-no-uc ../actual &&
725 git update-index --untracked-cache &&
726 test-tool dump-untracked-cache >../actual &&
727 test_cmp ../expect-empty ../actual
730 test_expect_success
'setting core.untrackedCache to false and using git status removes the cache' '
731 git config core.untrackedCache false &&
732 test-tool dump-untracked-cache >../actual &&
733 test_cmp ../expect-empty ../actual &&
735 test-tool dump-untracked-cache >../actual &&
736 test_cmp ../expect-no-uc ../actual
739 test_expect_success
'using --untracked-cache does not fail when core.untrackedCache is false' '
740 git update-index --untracked-cache &&
741 test-tool dump-untracked-cache >../actual &&
742 test_cmp ../expect-empty ../actual
745 test_expect_success
'setting core.untrackedCache to keep' '
746 git config core.untrackedCache keep &&
747 git update-index --untracked-cache &&
748 test-tool dump-untracked-cache >../actual &&
749 test_cmp ../expect-empty ../actual &&
751 test-tool dump-untracked-cache >../actual &&
752 test_cmp ../expect-from-test-dump ../actual &&
753 git update-index --no-untracked-cache &&
754 test-tool dump-untracked-cache >../actual &&
755 test_cmp ../expect-no-uc ../actual &&
756 git update-index --force-untracked-cache &&
757 test-tool dump-untracked-cache >../actual &&
758 test_cmp ../expect-empty ../actual &&
760 test-tool dump-untracked-cache >../actual &&
761 test_cmp ../expect-from-test-dump ../actual
764 test_expect_success
'test ident field is working' '
765 mkdir ../other_worktree &&
766 cp -R done dthree dtwo four three ../other_worktree &&
767 GIT_WORK_TREE=../other_worktree git status 2>../err &&
768 echo "warning: untracked cache is disabled on this system or location" >../expect &&
769 test_cmp ../expect ../err
772 test_expect_success
'untracked cache survives a checkout' '
773 git commit --allow-empty -m empty &&
774 test-tool dump-untracked-cache >../before &&
775 test_when_finished "git checkout main" &&
776 git checkout -b other_branch &&
777 test-tool dump-untracked-cache >../after &&
778 test_cmp ../before ../after &&
780 test-tool dump-untracked-cache >../before &&
782 test-tool dump-untracked-cache >../after &&
783 test_cmp ../before ../after
786 test_expect_success
'untracked cache survives a commit' '
787 test-tool dump-untracked-cache >../before &&
789 git commit -m commit &&
790 test-tool dump-untracked-cache >../after &&
791 test_cmp ../before ../after
794 test_expect_success
'teardown worktree' '
798 test_expect_success SYMLINKS
'setup worktree for symlink test' '
799 git init worktree-symlink &&
800 cd worktree-symlink &&
801 git config core.untrackedCache true &&
803 touch one/file two/file &&
804 git add one/file two/file &&
805 git commit -m"first commit" &&
809 git commit -m"second commit"
812 test_expect_success SYMLINKS
'"status" after symlink replacement should be clean with UC=true' '
813 git checkout HEAD~ &&
822 test_expect_success SYMLINKS
'"status" after symlink replacement should be clean with UC=false' '
823 git config core.untrackedCache false &&
824 git checkout HEAD~ &&
833 test_expect_success
'setup worktree for non-symlink test' '
834 git init worktree-non-symlink &&
835 cd worktree-non-symlink &&
836 git config core.untrackedCache true &&
838 touch one/file two/file &&
839 git add one/file two/file &&
840 git commit -m"first commit" &&
844 git commit -m"second commit"
847 test_expect_success
'"status" after file replacement should be clean with UC=true' '
848 git checkout HEAD~ &&
854 test-tool dump-untracked-cache >../actual &&
855 grep -F "recurse valid" ../actual >../actual.grep &&
856 cat >../expect.grep <<EOF &&
857 / $ZERO_OID recurse valid
858 /two/ $ZERO_OID recurse valid
861 test_cmp ../expect.grep ../actual.grep
864 test_expect_success
'"status" after file replacement should be clean with UC=false' '
865 git config core.untrackedCache false &&
866 git checkout HEAD~ &&