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 git add one two done/one &&
94 : >.git/info/exclude &&
95 git update-index --untracked-cache &&
97 root sha1:e6fcc8f2ee31bae321d66afd183fcb7237afae6e
98 root sha256:b90c672088c015b9c83876e919da311bad4cd39639fb139f988af6a11493b974
100 exclude sha1:13263c0978fb9fad16b2d580fb800b6d811c3ff0
101 exclude sha256:fe4aaa1bbbbce4cb8f73426748a14c5ad6026b26f90505a0bf2494b165a5b76c
103 done sha1:1946f0437f90c5005533cbe1736a6451ca301714
104 done sha256:7f079501d79f665b3acc50f5e0e9e94509084d5032ac20113a37dd5029b757cc
108 test_expect_success
'untracked cache is empty' '
109 test-tool dump-untracked-cache >../actual &&
110 cat >../expect-empty <<EOF &&
111 info/exclude $ZERO_OID
112 core.excludesfile $ZERO_OID
113 exclude_per_dir .gitignore
116 test_cmp ../expect-empty ../actual
119 cat >..
/status.expect
<<EOF &&
128 cat >..
/dump.expect
<<EOF &&
129 info/exclude $EMPTY_BLOB
130 core.excludesfile $ZERO_OID
131 exclude_per_dir .gitignore
133 / $ZERO_OID recurse valid
137 /done/ $ZERO_OID recurse valid
138 /dthree/ $ZERO_OID recurse check_only valid
140 /dtwo/ $ZERO_OID recurse check_only valid
144 test_expect_success
'status first time (empty cache)' '
146 : >../trace.output &&
147 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
148 git status --porcelain >../actual &&
149 iuc status --porcelain >../status.iuc &&
150 test_cmp ../status.expect ../status.iuc &&
151 test_cmp ../status.expect ../actual &&
152 get_relevant_traces ../trace.output ../trace.relevant &&
153 cat >../trace.expect <<EOF &&
156 ....gitignore-invalidation:1
157 ....directory-invalidation:0
160 test_cmp ../trace.expect ../trace.relevant
163 test_expect_success
'untracked cache after first status' '
164 test-tool dump-untracked-cache >../actual &&
165 test_cmp ../dump.expect ../actual
168 test_expect_success
'status second time (fully populated cache)' '
170 : >../trace.output &&
171 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
172 git status --porcelain >../actual &&
173 iuc status --porcelain >../status.iuc &&
174 test_cmp ../status.expect ../status.iuc &&
175 test_cmp ../status.expect ../actual &&
176 get_relevant_traces ../trace.output ../trace.relevant &&
177 cat >../trace.expect <<EOF &&
180 ....gitignore-invalidation:0
181 ....directory-invalidation:0
184 test_cmp ../trace.expect ../trace.relevant
187 test_expect_success
'untracked cache after second status' '
188 test-tool dump-untracked-cache >../actual &&
189 test_cmp ../dump.expect ../actual
192 test_expect_success
'modify in root directory, one dir invalidation' '
195 : >../trace.output &&
196 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
197 git status --porcelain >../actual &&
198 iuc status --porcelain >../status.iuc &&
199 cat >../status.expect <<EOF &&
208 test_cmp ../status.expect ../status.iuc &&
209 test_cmp ../status.expect ../actual &&
210 get_relevant_traces ../trace.output ../trace.relevant &&
211 cat >../trace.expect <<EOF &&
214 ....gitignore-invalidation:0
215 ....directory-invalidation:1
218 test_cmp ../trace.expect ../trace.relevant
222 test_expect_success
'verify untracked cache dump' '
223 test-tool dump-untracked-cache >../actual &&
224 cat >../expect <<EOF &&
225 info/exclude $EMPTY_BLOB
226 core.excludesfile $ZERO_OID
227 exclude_per_dir .gitignore
229 / $ZERO_OID recurse valid
234 /done/ $ZERO_OID recurse valid
235 /dthree/ $ZERO_OID recurse check_only valid
237 /dtwo/ $ZERO_OID recurse check_only valid
240 test_cmp ../expect ../actual
243 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' '
296 echo three >>.git/info/exclude &&
297 : >../trace.output &&
298 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
299 git status --porcelain >../actual &&
300 iuc status --porcelain >../status.iuc &&
301 cat >../status.expect <<EOF &&
308 test_cmp ../status.expect ../status.iuc &&
309 test_cmp ../status.expect ../actual &&
310 get_relevant_traces ../trace.output ../trace.relevant &&
311 cat >../trace.expect <<EOF &&
314 ....gitignore-invalidation:1
315 ....directory-invalidation:0
318 test_cmp ../trace.expect ../trace.relevant
321 test_expect_success
'verify untracked cache dump' '
322 test-tool dump-untracked-cache >../actual &&
323 cat >../expect <<EOF &&
324 info/exclude $(test_oid exclude)
325 core.excludesfile $ZERO_OID
326 exclude_per_dir .gitignore
328 / $(test_oid root) recurse valid
331 /done/ $ZERO_OID recurse valid
332 /dthree/ $ZERO_OID recurse check_only valid
333 /dtwo/ $ZERO_OID recurse check_only valid
336 test_cmp ../expect ../actual
339 test_expect_success
'move two from tracked to untracked' '
340 git rm --cached two &&
341 test-tool dump-untracked-cache >../actual &&
342 cat >../expect <<EOF &&
343 info/exclude $(test_oid exclude)
344 core.excludesfile $ZERO_OID
345 exclude_per_dir .gitignore
347 / $(test_oid root) recurse
348 /done/ $ZERO_OID recurse valid
349 /dthree/ $ZERO_OID recurse check_only valid
350 /dtwo/ $ZERO_OID recurse check_only valid
353 test_cmp ../expect ../actual
356 test_expect_success
'status after the move' '
357 : >../trace.output &&
358 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
359 git status --porcelain >../actual &&
360 iuc status --porcelain >../status.iuc &&
361 cat >../status.expect <<EOF &&
368 test_cmp ../status.expect ../status.iuc &&
369 test_cmp ../status.expect ../actual &&
370 get_relevant_traces ../trace.output ../trace.relevant &&
371 cat >../trace.expect <<EOF &&
374 ....gitignore-invalidation:0
375 ....directory-invalidation:0
378 test_cmp ../trace.expect ../trace.relevant
381 test_expect_success
'verify untracked cache dump' '
382 test-tool dump-untracked-cache >../actual &&
383 cat >../expect <<EOF &&
384 info/exclude $(test_oid exclude)
385 core.excludesfile $ZERO_OID
386 exclude_per_dir .gitignore
388 / $(test_oid root) recurse valid
392 /done/ $ZERO_OID recurse valid
393 /dthree/ $ZERO_OID recurse check_only valid
394 /dtwo/ $ZERO_OID recurse check_only valid
397 test_cmp ../expect ../actual
400 test_expect_success
'move two from untracked to tracked' '
402 test-tool dump-untracked-cache >../actual &&
403 cat >../expect <<EOF &&
404 info/exclude $(test_oid exclude)
405 core.excludesfile $ZERO_OID
406 exclude_per_dir .gitignore
408 / $(test_oid root) recurse
409 /done/ $ZERO_OID recurse valid
410 /dthree/ $ZERO_OID recurse check_only valid
411 /dtwo/ $ZERO_OID recurse check_only valid
414 test_cmp ../expect ../actual
417 test_expect_success
'status after the move' '
418 : >../trace.output &&
419 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
420 git status --porcelain >../actual &&
421 iuc status --porcelain >../status.iuc &&
422 cat >../status.expect <<EOF &&
429 test_cmp ../status.expect ../status.iuc &&
430 test_cmp ../status.expect ../actual &&
431 get_relevant_traces ../trace.output ../trace.relevant &&
432 cat >../trace.expect <<EOF &&
435 ....gitignore-invalidation:0
436 ....directory-invalidation:0
439 test_cmp ../trace.expect ../trace.relevant
442 test_expect_success
'verify untracked cache dump' '
443 test-tool dump-untracked-cache >../actual &&
444 cat >../expect <<EOF &&
445 info/exclude $(test_oid exclude)
446 core.excludesfile $ZERO_OID
447 exclude_per_dir .gitignore
449 / $(test_oid root) recurse valid
452 /done/ $ZERO_OID recurse valid
453 /dthree/ $ZERO_OID recurse check_only valid
454 /dtwo/ $ZERO_OID recurse check_only valid
457 test_cmp ../expect ../actual
460 test_expect_success
'set up for sparse checkout testing' '
461 echo two >done/.gitignore &&
462 echo three >>done/.gitignore &&
463 echo two >done/two &&
464 git add -f done/two done/.gitignore &&
465 git commit -m "first commit"
468 test_expect_success
'status after commit' '
469 : >../trace.output &&
470 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
471 git status --porcelain >../actual &&
472 iuc status --porcelain >../status.iuc &&
473 cat >../status.expect <<EOF &&
477 test_cmp ../status.expect ../status.iuc &&
478 test_cmp ../status.expect ../actual &&
479 get_relevant_traces ../trace.output ../trace.relevant &&
480 cat >../trace.expect <<EOF &&
483 ....gitignore-invalidation:0
484 ....directory-invalidation:0
487 test_cmp ../trace.expect ../trace.relevant
490 test_expect_success
'untracked cache correct after commit' '
491 test-tool dump-untracked-cache >../actual &&
492 cat >../expect <<EOF &&
493 info/exclude $(test_oid exclude)
494 core.excludesfile $ZERO_OID
495 exclude_per_dir .gitignore
497 / $(test_oid root) recurse valid
500 /done/ $ZERO_OID recurse valid
501 /dthree/ $ZERO_OID recurse check_only valid
502 /dtwo/ $ZERO_OID recurse check_only valid
505 test_cmp ../expect ../actual
508 test_expect_success
'set up sparse checkout' '
509 echo "done/[a-z]*" >.git/info/sparse-checkout &&
510 test_config core.sparsecheckout true &&
512 git update-index --force-untracked-cache &&
513 git status --porcelain >/dev/null && # prime the cache
514 test_path_is_missing done/.gitignore &&
515 test_path_is_file done/one
518 test_expect_success
'create/modify files, some of which are gitignored' '
519 echo two bis >done/two &&
520 echo three >done/three && # three is gitignored
521 echo four >done/four && # four is gitignored at a higher level
522 echo five >done/five && # five is not gitignored
523 echo test >base && #we need to ensure that the root dir is touched
528 test_expect_success
'test sparse status with untracked cache' '
529 : >../trace.output &&
531 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
532 git status --porcelain >../status.actual &&
533 iuc status --porcelain >../status.iuc &&
534 cat >../status.expect <<EOF &&
540 test_cmp ../status.expect ../status.iuc &&
541 test_cmp ../status.expect ../status.actual &&
542 get_relevant_traces ../trace.output ../trace.relevant &&
543 cat >../trace.expect <<EOF &&
546 ....gitignore-invalidation:1
547 ....directory-invalidation:2
550 test_cmp ../trace.expect ../trace.relevant
553 test_expect_success
'untracked cache correct after status' '
554 test-tool dump-untracked-cache >../actual &&
555 cat >../expect <<EOF &&
556 info/exclude $(test_oid exclude)
557 core.excludesfile $ZERO_OID
558 exclude_per_dir .gitignore
560 / $(test_oid root) recurse valid
563 /done/ $(test_oid done) recurse valid
565 /dthree/ $ZERO_OID recurse check_only valid
566 /dtwo/ $ZERO_OID recurse check_only valid
569 test_cmp ../expect ../actual
572 test_expect_success
'test sparse status again with untracked cache' '
574 : >../trace.output &&
575 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
576 git status --porcelain >../status.actual &&
577 iuc status --porcelain >../status.iuc &&
578 cat >../status.expect <<EOF &&
584 test_cmp ../status.expect ../status.iuc &&
585 test_cmp ../status.expect ../status.actual &&
586 get_relevant_traces ../trace.output ../trace.relevant &&
587 cat >../trace.expect <<EOF &&
590 ....gitignore-invalidation:0
591 ....directory-invalidation:0
594 test_cmp ../trace.expect ../trace.relevant
597 test_expect_success
'set up for test of subdir and sparse checkouts' '
599 mkdir done/sub/sub &&
600 echo "sub" > done/sub/sub/file
603 test_expect_success
'test sparse status with untracked cache and subdir' '
605 : >../trace.output &&
606 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
607 git status --porcelain >../status.actual &&
608 iuc status --porcelain >../status.iuc &&
609 cat >../status.expect <<EOF &&
616 test_cmp ../status.expect ../status.iuc &&
617 test_cmp ../status.expect ../status.actual &&
618 get_relevant_traces ../trace.output ../trace.relevant &&
619 cat >../trace.expect <<EOF &&
622 ....gitignore-invalidation:0
623 ....directory-invalidation:1
626 test_cmp ../trace.expect ../trace.relevant
629 test_expect_success
'verify untracked cache dump (sparse/subdirs)' '
630 test-tool dump-untracked-cache >../actual &&
631 cat >../expect-from-test-dump <<EOF &&
632 info/exclude $(test_oid exclude)
633 core.excludesfile $ZERO_OID
634 exclude_per_dir .gitignore
636 / $(test_oid root) recurse valid
639 /done/ $(test_oid done) recurse valid
642 /done/sub/ $ZERO_OID recurse check_only valid
644 /done/sub/sub/ $ZERO_OID recurse check_only valid
646 /dthree/ $ZERO_OID recurse check_only valid
647 /dtwo/ $ZERO_OID recurse check_only valid
650 test_cmp ../expect-from-test-dump ../actual
653 test_expect_success
'test sparse status again with untracked cache and subdir' '
655 : >../trace.output &&
656 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
657 git status --porcelain >../status.actual &&
658 iuc status --porcelain >../status.iuc &&
659 test_cmp ../status.expect ../status.iuc &&
660 test_cmp ../status.expect ../status.actual &&
661 get_relevant_traces ../trace.output ../trace.relevant &&
662 cat >../trace.expect <<EOF &&
665 ....gitignore-invalidation:0
666 ....directory-invalidation:0
669 test_cmp ../trace.expect ../trace.relevant
672 test_expect_success
'move entry in subdir from untracked to cached' '
674 git status --porcelain >../status.actual &&
675 iuc status --porcelain >../status.iuc &&
676 cat >../status.expect <<EOF &&
683 test_cmp ../status.expect ../status.iuc &&
684 test_cmp ../status.expect ../status.actual
687 test_expect_success
'move entry in subdir from cached to untracked' '
688 git rm --cached dtwo/two &&
689 git status --porcelain >../status.actual &&
690 iuc status --porcelain >../status.iuc &&
691 cat >../status.expect <<EOF &&
698 test_cmp ../status.expect ../status.iuc &&
699 test_cmp ../status.expect ../status.actual
702 test_expect_success
'--no-untracked-cache removes the cache' '
703 git update-index --no-untracked-cache &&
704 test-tool dump-untracked-cache >../actual &&
705 echo "no untracked cache" >../expect-no-uc &&
706 test_cmp ../expect-no-uc ../actual
709 test_expect_success
'git status does not change anything' '
711 test-tool dump-untracked-cache >../actual &&
712 test_cmp ../expect-no-uc ../actual
715 test_expect_success
'setting core.untrackedCache to true and using git status creates the cache' '
716 git config core.untrackedCache true &&
717 test-tool dump-untracked-cache >../actual &&
718 test_cmp ../expect-no-uc ../actual &&
720 test-tool dump-untracked-cache >../actual &&
721 test_cmp ../expect-from-test-dump ../actual
724 test_expect_success
'using --no-untracked-cache does not fail when core.untrackedCache is true' '
725 git update-index --no-untracked-cache &&
726 test-tool dump-untracked-cache >../actual &&
727 test_cmp ../expect-no-uc ../actual &&
728 git update-index --untracked-cache &&
729 test-tool dump-untracked-cache >../actual &&
730 test_cmp ../expect-empty ../actual
733 test_expect_success
'setting core.untrackedCache to false and using git status removes the cache' '
734 git config core.untrackedCache false &&
735 test-tool dump-untracked-cache >../actual &&
736 test_cmp ../expect-empty ../actual &&
738 test-tool dump-untracked-cache >../actual &&
739 test_cmp ../expect-no-uc ../actual
742 test_expect_success
'using --untracked-cache does not fail when core.untrackedCache is false' '
743 git update-index --untracked-cache &&
744 test-tool dump-untracked-cache >../actual &&
745 test_cmp ../expect-empty ../actual
748 test_expect_success
'setting core.untrackedCache to keep' '
749 git config core.untrackedCache keep &&
750 git update-index --untracked-cache &&
751 test-tool dump-untracked-cache >../actual &&
752 test_cmp ../expect-empty ../actual &&
754 test-tool dump-untracked-cache >../actual &&
755 test_cmp ../expect-from-test-dump ../actual &&
756 git update-index --no-untracked-cache &&
757 test-tool dump-untracked-cache >../actual &&
758 test_cmp ../expect-no-uc ../actual &&
759 git update-index --force-untracked-cache &&
760 test-tool dump-untracked-cache >../actual &&
761 test_cmp ../expect-empty ../actual &&
763 test-tool dump-untracked-cache >../actual &&
764 test_cmp ../expect-from-test-dump ../actual
767 test_expect_success
'test ident field is working' '
768 mkdir ../other_worktree &&
769 cp -R done dthree dtwo four three ../other_worktree &&
770 GIT_WORK_TREE=../other_worktree git status 2>../err &&
771 echo "warning: untracked cache is disabled on this system or location" >../expect &&
772 test_cmp ../expect ../err
775 test_expect_success
'untracked cache survives a checkout' '
776 git commit --allow-empty -m empty &&
777 test-tool dump-untracked-cache >../before &&
778 test_when_finished "git checkout main" &&
779 git checkout -b other_branch &&
780 test-tool dump-untracked-cache >../after &&
781 test_cmp ../before ../after &&
783 test-tool dump-untracked-cache >../before &&
785 test-tool dump-untracked-cache >../after &&
786 test_cmp ../before ../after
789 test_expect_success
'untracked cache survives a commit' '
790 test-tool dump-untracked-cache >../before &&
792 git commit -m commit &&
793 test-tool dump-untracked-cache >../after &&
794 test_cmp ../before ../after
797 test_expect_success
'teardown worktree' '
801 test_expect_success SYMLINKS
'setup worktree for symlink test' '
802 git init worktree-symlink &&
803 cd worktree-symlink &&
804 git config core.untrackedCache true &&
806 touch one/file two/file &&
807 git add one/file two/file &&
808 git commit -m"first commit" &&
812 git commit -m"second commit"
815 test_expect_success SYMLINKS
'"status" after symlink replacement should be clean with UC=true' '
816 git checkout HEAD~ &&
825 test_expect_success SYMLINKS
'"status" after symlink replacement should be clean with UC=false' '
826 git config core.untrackedCache false &&
827 git checkout HEAD~ &&
836 test_expect_success
'setup worktree for non-symlink test' '
837 git init worktree-non-symlink &&
838 cd worktree-non-symlink &&
839 git config core.untrackedCache true &&
841 touch one/file two/file &&
842 git add one/file two/file &&
843 git commit -m"first commit" &&
847 git commit -m"second commit"
850 test_expect_success
'"status" after file replacement should be clean with UC=true' '
851 git checkout HEAD~ &&
857 test-tool dump-untracked-cache >../actual &&
858 grep -F "recurse valid" ../actual >../actual.grep &&
859 cat >../expect.grep <<EOF &&
860 / $ZERO_OID recurse valid
861 /two/ $ZERO_OID recurse valid
864 test_cmp ../expect.grep ../actual.grep
867 test_expect_success
'"status" after file replacement should be clean with UC=false' '
868 git config core.untrackedCache false &&
869 git checkout HEAD~ &&