The eighth batch
[alt-git.git] / t / t7063-status-untracked-cache.sh
blob8929ef481f926ce8eee1414b852c3e14538afa9c
1 #!/bin/sh
3 test_description='test untracked cache'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 . ./test-lib.sh
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
18 # more.
20 GIT_FORCE_UNTRACKED_CACHE=true
21 export GIT_FORCE_UNTRACKED_CACHE
23 sync_mtime () {
24 find . -type d -exec ls -ld {} + >/dev/null
27 avoid_racy() {
28 sleep 1
31 status_is_clean() {
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
41 iuc () {
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
46 export GIT_INDEX_FILE
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 "$@"
51 ret=$?
53 rm ../current-index-entries
54 rm $GIT_INDEX_FILE
55 unset GIT_INDEX_FILE
57 return $ret
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.
65 INPUT_FILE=$1
66 OUTPUT_FILE=$2
67 grep data.*read_directo $INPUT_FILE |
68 cut -d "|" -f 9 |
69 grep -v visited \
70 >"$OUTPUT_FILE"
74 test_lazy_prereq UNTRACKED_CACHE '
75 { git update-index --test-untracked-cache; ret=$?; } &&
76 test $ret -ne 1
79 if ! test_have_prereq UNTRACKED_CACHE; then
80 skip_all='This system does not support untracked cache'
81 test_done
84 test_expect_success 'core.untrackedCache is unset' '
85 test_must_fail git config --get core.untrackedCache
88 test_expect_success 'setup' '
89 git init --template= worktree &&
90 cd worktree &&
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 mkdir .git/info &&
98 : >.git/info/exclude &&
99 git update-index --untracked-cache &&
100 test_oid_cache <<-EOF
101 root sha1:e6fcc8f2ee31bae321d66afd183fcb7237afae6e
102 root sha256:b90c672088c015b9c83876e919da311bad4cd39639fb139f988af6a11493b974
104 exclude sha1:13263c0978fb9fad16b2d580fb800b6d811c3ff0
105 exclude sha256:fe4aaa1bbbbce4cb8f73426748a14c5ad6026b26f90505a0bf2494b165a5b76c
107 done sha1:1946f0437f90c5005533cbe1736a6451ca301714
108 done sha256:7f079501d79f665b3acc50f5e0e9e94509084d5032ac20113a37dd5029b757cc
112 test_expect_success 'untracked cache is empty' '
113 test-tool dump-untracked-cache >../actual &&
114 cat >../expect-empty <<EOF &&
115 info/exclude $ZERO_OID
116 core.excludesfile $ZERO_OID
117 exclude_per_dir .gitignore
118 flags 00000006
120 test_cmp ../expect-empty ../actual
123 cat >../status.expect <<EOF &&
124 A done/one
125 A one
126 A two
127 ?? dthree/
128 ?? dtwo/
129 ?? three
132 cat >../dump.expect <<EOF &&
133 info/exclude $EMPTY_BLOB
134 core.excludesfile $ZERO_OID
135 exclude_per_dir .gitignore
136 flags 00000006
137 / $ZERO_OID recurse valid
138 dthree/
139 dtwo/
140 three
141 /done/ $ZERO_OID recurse valid
142 /dthree/ $ZERO_OID recurse check_only valid
143 three
144 /dtwo/ $ZERO_OID recurse check_only valid
148 test_expect_success 'status first time (empty cache)' '
149 : >../trace.output &&
150 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
151 git status --porcelain >../actual &&
152 iuc status --porcelain >../status.iuc &&
153 test_cmp ../status.expect ../status.iuc &&
154 test_cmp ../status.expect ../actual &&
155 get_relevant_traces ../trace.output ../trace.relevant &&
156 cat >../trace.expect <<EOF &&
157 ....path:
158 ....node-creation:3
159 ....gitignore-invalidation:1
160 ....directory-invalidation:0
161 ....opendir:4
163 test_cmp ../trace.expect ../trace.relevant
166 test_expect_success 'untracked cache after first status' '
167 test-tool dump-untracked-cache >../actual &&
168 test_cmp ../dump.expect ../actual
171 test_expect_success 'status second time (fully populated cache)' '
172 : >../trace.output &&
173 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
174 git status --porcelain >../actual &&
175 iuc status --porcelain >../status.iuc &&
176 test_cmp ../status.expect ../status.iuc &&
177 test_cmp ../status.expect ../actual &&
178 get_relevant_traces ../trace.output ../trace.relevant &&
179 cat >../trace.expect <<EOF &&
180 ....path:
181 ....node-creation:0
182 ....gitignore-invalidation:0
183 ....directory-invalidation:0
184 ....opendir:0
186 test_cmp ../trace.expect ../trace.relevant
189 test_expect_success 'untracked cache after second status' '
190 test-tool dump-untracked-cache >../actual &&
191 test_cmp ../dump.expect ../actual
194 cat >../status_uall.expect <<EOF &&
195 A done/one
196 A one
197 A two
198 ?? dthree/three
199 ?? dtwo/two
200 ?? three
203 # Bypassing the untracked cache here is not desirable from an
204 # end-user perspective, but is expected in the current design.
205 # The untracked cache data stored for a -unormal run cannot be
206 # correctly used in a -uall run - it would yield incorrect output.
207 test_expect_success 'untracked cache is bypassed with -uall' '
208 : >../trace.output &&
209 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
210 git status -uall --porcelain >../actual &&
211 iuc status -uall --porcelain >../status.iuc &&
212 test_cmp ../status_uall.expect ../status.iuc &&
213 test_cmp ../status_uall.expect ../actual &&
214 get_relevant_traces ../trace.output ../trace.relevant &&
215 cat >../trace.expect <<EOF &&
216 ....path:
218 test_cmp ../trace.expect ../trace.relevant
221 test_expect_success 'untracked cache remains after bypass' '
222 test-tool dump-untracked-cache >../actual &&
223 test_cmp ../dump.expect ../actual
226 test_expect_success 'if -uall is configured, untracked cache gets populated by default' '
227 test_config status.showuntrackedfiles all &&
228 : >../trace.output &&
229 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
230 git status --porcelain >../actual &&
231 iuc status --porcelain >../status.iuc &&
232 test_cmp ../status_uall.expect ../status.iuc &&
233 test_cmp ../status_uall.expect ../actual &&
234 get_relevant_traces ../trace.output ../trace.relevant &&
235 cat >../trace.expect <<EOF &&
236 ....path:
237 ....node-creation:3
238 ....gitignore-invalidation:1
239 ....directory-invalidation:0
240 ....opendir:4
242 test_cmp ../trace.expect ../trace.relevant
245 cat >../dump_uall.expect <<EOF &&
246 info/exclude $EMPTY_BLOB
247 core.excludesfile $ZERO_OID
248 exclude_per_dir .gitignore
249 flags 00000000
250 / $ZERO_OID recurse valid
251 three
252 /done/ $ZERO_OID recurse valid
253 /dthree/ $ZERO_OID recurse valid
254 three
255 /dtwo/ $ZERO_OID recurse valid
259 test_expect_success 'if -uall was configured, untracked cache is populated' '
260 test-tool dump-untracked-cache >../actual &&
261 test_cmp ../dump_uall.expect ../actual
264 test_expect_success 'if -uall is configured, untracked cache is used by default' '
265 test_config status.showuntrackedfiles all &&
266 : >../trace.output &&
267 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
268 git status --porcelain >../actual &&
269 iuc status --porcelain >../status.iuc &&
270 test_cmp ../status_uall.expect ../status.iuc &&
271 test_cmp ../status_uall.expect ../actual &&
272 get_relevant_traces ../trace.output ../trace.relevant &&
273 cat >../trace.expect <<EOF &&
274 ....path:
275 ....node-creation:0
276 ....gitignore-invalidation:0
277 ....directory-invalidation:0
278 ....opendir:0
280 test_cmp ../trace.expect ../trace.relevant
283 # Bypassing the untracked cache here is not desirable from an
284 # end-user perspective, but is expected in the current design.
285 # The untracked cache data stored for a -all run cannot be
286 # correctly used in a -unormal run - it would yield incorrect
287 # output.
288 test_expect_success 'if -uall is configured, untracked cache is bypassed with -unormal' '
289 test_config status.showuntrackedfiles all &&
290 : >../trace.output &&
291 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
292 git status -unormal --porcelain >../actual &&
293 iuc status -unormal --porcelain >../status.iuc &&
294 test_cmp ../status.expect ../status.iuc &&
295 test_cmp ../status.expect ../actual &&
296 get_relevant_traces ../trace.output ../trace.relevant &&
297 cat >../trace.expect <<EOF &&
298 ....path:
300 test_cmp ../trace.expect ../trace.relevant
303 test_expect_success 'repopulate untracked cache for -unormal' '
304 git status --porcelain
307 test_expect_success 'modify in root directory, one dir invalidation' '
308 : >four &&
309 test-tool chmtime =-240 four &&
310 : >../trace.output &&
311 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
312 git status --porcelain >../actual &&
313 iuc status --porcelain >../status.iuc &&
314 cat >../status.expect <<EOF &&
315 A done/one
316 A one
317 A two
318 ?? dthree/
319 ?? dtwo/
320 ?? four
321 ?? three
323 test_cmp ../status.expect ../status.iuc &&
324 test_cmp ../status.expect ../actual &&
325 get_relevant_traces ../trace.output ../trace.relevant &&
326 cat >../trace.expect <<EOF &&
327 ....path:
328 ....node-creation:0
329 ....gitignore-invalidation:0
330 ....directory-invalidation:1
331 ....opendir:1
333 test_cmp ../trace.expect ../trace.relevant
337 test_expect_success 'verify untracked cache dump' '
338 test-tool dump-untracked-cache >../actual &&
339 cat >../expect <<EOF &&
340 info/exclude $EMPTY_BLOB
341 core.excludesfile $ZERO_OID
342 exclude_per_dir .gitignore
343 flags 00000006
344 / $ZERO_OID recurse valid
345 dthree/
346 dtwo/
347 four
348 three
349 /done/ $ZERO_OID recurse valid
350 /dthree/ $ZERO_OID recurse check_only valid
351 three
352 /dtwo/ $ZERO_OID recurse check_only valid
355 test_cmp ../expect ../actual
358 test_expect_success 'new .gitignore invalidates recursively' '
359 echo four >.gitignore &&
360 : >../trace.output &&
361 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
362 git status --porcelain >../actual &&
363 iuc status --porcelain >../status.iuc &&
364 cat >../status.expect <<EOF &&
365 A done/one
366 A one
367 A two
368 ?? .gitignore
369 ?? dthree/
370 ?? dtwo/
371 ?? three
373 test_cmp ../status.expect ../status.iuc &&
374 test_cmp ../status.expect ../actual &&
375 get_relevant_traces ../trace.output ../trace.relevant &&
376 cat >../trace.expect <<EOF &&
377 ....path:
378 ....node-creation:0
379 ....gitignore-invalidation:1
380 ....directory-invalidation:1
381 ....opendir:4
383 test_cmp ../trace.expect ../trace.relevant
387 test_expect_success 'verify untracked cache dump' '
388 test-tool dump-untracked-cache >../actual &&
389 cat >../expect <<EOF &&
390 info/exclude $EMPTY_BLOB
391 core.excludesfile $ZERO_OID
392 exclude_per_dir .gitignore
393 flags 00000006
394 / $(test_oid root) recurse valid
395 .gitignore
396 dthree/
397 dtwo/
398 three
399 /done/ $ZERO_OID recurse valid
400 /dthree/ $ZERO_OID recurse check_only valid
401 three
402 /dtwo/ $ZERO_OID recurse check_only valid
405 test_cmp ../expect ../actual
408 test_expect_success 'new info/exclude invalidates everything' '
409 echo three >>.git/info/exclude &&
410 : >../trace.output &&
411 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
412 git status --porcelain >../actual &&
413 iuc status --porcelain >../status.iuc &&
414 cat >../status.expect <<EOF &&
415 A done/one
416 A one
417 A two
418 ?? .gitignore
419 ?? dtwo/
421 test_cmp ../status.expect ../status.iuc &&
422 test_cmp ../status.expect ../actual &&
423 get_relevant_traces ../trace.output ../trace.relevant &&
424 cat >../trace.expect <<EOF &&
425 ....path:
426 ....node-creation:0
427 ....gitignore-invalidation:1
428 ....directory-invalidation:0
429 ....opendir:4
431 test_cmp ../trace.expect ../trace.relevant
434 test_expect_success 'verify untracked cache dump' '
435 test-tool dump-untracked-cache >../actual &&
436 cat >../expect <<EOF &&
437 info/exclude $(test_oid exclude)
438 core.excludesfile $ZERO_OID
439 exclude_per_dir .gitignore
440 flags 00000006
441 / $(test_oid root) recurse valid
442 .gitignore
443 dtwo/
444 /done/ $ZERO_OID recurse valid
445 /dthree/ $ZERO_OID recurse check_only valid
446 /dtwo/ $ZERO_OID recurse check_only valid
449 test_cmp ../expect ../actual
452 test_expect_success 'move two from tracked to untracked' '
453 git rm --cached two &&
454 test-tool dump-untracked-cache >../actual &&
455 cat >../expect <<EOF &&
456 info/exclude $(test_oid exclude)
457 core.excludesfile $ZERO_OID
458 exclude_per_dir .gitignore
459 flags 00000006
460 / $(test_oid root) recurse
461 /done/ $ZERO_OID recurse valid
462 /dthree/ $ZERO_OID recurse check_only valid
463 /dtwo/ $ZERO_OID recurse check_only valid
466 test_cmp ../expect ../actual
469 test_expect_success 'status after the move' '
470 : >../trace.output &&
471 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
472 git status --porcelain >../actual &&
473 iuc status --porcelain >../status.iuc &&
474 cat >../status.expect <<EOF &&
475 A done/one
476 A one
477 ?? .gitignore
478 ?? dtwo/
479 ?? two
481 test_cmp ../status.expect ../status.iuc &&
482 test_cmp ../status.expect ../actual &&
483 get_relevant_traces ../trace.output ../trace.relevant &&
484 cat >../trace.expect <<EOF &&
485 ....path:
486 ....node-creation:0
487 ....gitignore-invalidation:0
488 ....directory-invalidation:0
489 ....opendir:1
491 test_cmp ../trace.expect ../trace.relevant
494 test_expect_success 'verify untracked cache dump' '
495 test-tool dump-untracked-cache >../actual &&
496 cat >../expect <<EOF &&
497 info/exclude $(test_oid exclude)
498 core.excludesfile $ZERO_OID
499 exclude_per_dir .gitignore
500 flags 00000006
501 / $(test_oid root) recurse valid
502 .gitignore
503 dtwo/
505 /done/ $ZERO_OID recurse valid
506 /dthree/ $ZERO_OID recurse check_only valid
507 /dtwo/ $ZERO_OID recurse check_only valid
510 test_cmp ../expect ../actual
513 test_expect_success 'move two from untracked to tracked' '
514 git add two &&
515 test-tool dump-untracked-cache >../actual &&
516 cat >../expect <<EOF &&
517 info/exclude $(test_oid exclude)
518 core.excludesfile $ZERO_OID
519 exclude_per_dir .gitignore
520 flags 00000006
521 / $(test_oid root) recurse
522 /done/ $ZERO_OID recurse valid
523 /dthree/ $ZERO_OID recurse check_only valid
524 /dtwo/ $ZERO_OID recurse check_only valid
527 test_cmp ../expect ../actual
530 test_expect_success 'status after the move' '
531 : >../trace.output &&
532 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
533 git status --porcelain >../actual &&
534 iuc status --porcelain >../status.iuc &&
535 cat >../status.expect <<EOF &&
536 A done/one
537 A one
538 A two
539 ?? .gitignore
540 ?? dtwo/
542 test_cmp ../status.expect ../status.iuc &&
543 test_cmp ../status.expect ../actual &&
544 get_relevant_traces ../trace.output ../trace.relevant &&
545 cat >../trace.expect <<EOF &&
546 ....path:
547 ....node-creation:0
548 ....gitignore-invalidation:0
549 ....directory-invalidation:0
550 ....opendir:1
552 test_cmp ../trace.expect ../trace.relevant
555 test_expect_success 'verify untracked cache dump' '
556 test-tool dump-untracked-cache >../actual &&
557 cat >../expect <<EOF &&
558 info/exclude $(test_oid exclude)
559 core.excludesfile $ZERO_OID
560 exclude_per_dir .gitignore
561 flags 00000006
562 / $(test_oid root) recurse valid
563 .gitignore
564 dtwo/
565 /done/ $ZERO_OID recurse valid
566 /dthree/ $ZERO_OID recurse check_only valid
567 /dtwo/ $ZERO_OID recurse check_only valid
570 test_cmp ../expect ../actual
573 test_expect_success 'set up for sparse checkout testing' '
574 echo two >done/.gitignore &&
575 echo three >>done/.gitignore &&
576 echo two >done/two &&
577 git add -f done/two done/.gitignore &&
578 git commit -m "first commit"
581 test_expect_success 'status after commit' '
582 : >../trace.output &&
583 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
584 git status --porcelain >../actual &&
585 iuc status --porcelain >../status.iuc &&
586 cat >../status.expect <<EOF &&
587 ?? .gitignore
588 ?? dtwo/
590 test_cmp ../status.expect ../status.iuc &&
591 test_cmp ../status.expect ../actual &&
592 get_relevant_traces ../trace.output ../trace.relevant &&
593 cat >../trace.expect <<EOF &&
594 ....path:
595 ....node-creation:0
596 ....gitignore-invalidation:0
597 ....directory-invalidation:0
598 ....opendir:2
600 test_cmp ../trace.expect ../trace.relevant
603 test_expect_success 'untracked cache correct after commit' '
604 test-tool dump-untracked-cache >../actual &&
605 cat >../expect <<EOF &&
606 info/exclude $(test_oid exclude)
607 core.excludesfile $ZERO_OID
608 exclude_per_dir .gitignore
609 flags 00000006
610 / $(test_oid root) recurse valid
611 .gitignore
612 dtwo/
613 /done/ $ZERO_OID recurse valid
614 /dthree/ $ZERO_OID recurse check_only valid
615 /dtwo/ $ZERO_OID recurse check_only valid
618 test_cmp ../expect ../actual
621 test_expect_success 'set up sparse checkout' '
622 echo "done/[a-z]*" >.git/info/sparse-checkout &&
623 test_config core.sparsecheckout true &&
624 git checkout main &&
625 git update-index --force-untracked-cache &&
626 git status --porcelain >/dev/null && # prime the cache
627 test_path_is_missing done/.gitignore &&
628 test_path_is_file done/one
631 test_expect_success 'create/modify files, some of which are gitignored' '
632 echo two bis >done/two &&
633 echo three >done/three && # three is gitignored
634 echo four >done/four && # four is gitignored at a higher level
635 echo five >done/five && # five is not gitignored
636 test-tool chmtime =-180 done/two done/three done/four done/five done &&
637 # we need to ensure that the root dir is touched (in the past);
638 test-tool chmtime =-180 . &&
639 sync_mtime
642 test_expect_success 'test sparse status with untracked cache' '
643 : >../trace.output &&
644 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
645 git status --porcelain >../status.actual &&
646 iuc status --porcelain >../status.iuc &&
647 cat >../status.expect <<EOF &&
648 M done/two
649 ?? .gitignore
650 ?? done/five
651 ?? dtwo/
653 test_cmp ../status.expect ../status.iuc &&
654 test_cmp ../status.expect ../status.actual &&
655 get_relevant_traces ../trace.output ../trace.relevant &&
656 cat >../trace.expect <<EOF &&
657 ....path:
658 ....node-creation:0
659 ....gitignore-invalidation:1
660 ....directory-invalidation:2
661 ....opendir:2
663 test_cmp ../trace.expect ../trace.relevant
666 test_expect_success 'untracked cache correct after status' '
667 test-tool dump-untracked-cache >../actual &&
668 cat >../expect <<EOF &&
669 info/exclude $(test_oid exclude)
670 core.excludesfile $ZERO_OID
671 exclude_per_dir .gitignore
672 flags 00000006
673 / $(test_oid root) recurse valid
674 .gitignore
675 dtwo/
676 /done/ $(test_oid done) recurse valid
677 five
678 /dthree/ $ZERO_OID recurse check_only valid
679 /dtwo/ $ZERO_OID recurse check_only valid
682 test_cmp ../expect ../actual
685 test_expect_success 'test sparse status again with untracked cache' '
686 : >../trace.output &&
687 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
688 git status --porcelain >../status.actual &&
689 iuc status --porcelain >../status.iuc &&
690 cat >../status.expect <<EOF &&
691 M done/two
692 ?? .gitignore
693 ?? done/five
694 ?? dtwo/
696 test_cmp ../status.expect ../status.iuc &&
697 test_cmp ../status.expect ../status.actual &&
698 get_relevant_traces ../trace.output ../trace.relevant &&
699 cat >../trace.expect <<EOF &&
700 ....path:
701 ....node-creation:0
702 ....gitignore-invalidation:0
703 ....directory-invalidation:0
704 ....opendir:0
706 test_cmp ../trace.expect ../trace.relevant
709 test_expect_success 'set up for test of subdir and sparse checkouts' '
710 mkdir done/sub &&
711 mkdir done/sub/sub &&
712 echo "sub" > done/sub/sub/file &&
713 test-tool chmtime =-120 done/sub/sub/file done/sub/sub done/sub done
716 test_expect_success 'test sparse status with untracked cache and subdir' '
717 : >../trace.output &&
718 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
719 git status --porcelain >../status.actual &&
720 iuc status --porcelain >../status.iuc &&
721 cat >../status.expect <<EOF &&
722 M done/two
723 ?? .gitignore
724 ?? done/five
725 ?? done/sub/
726 ?? dtwo/
728 test_cmp ../status.expect ../status.iuc &&
729 test_cmp ../status.expect ../status.actual &&
730 get_relevant_traces ../trace.output ../trace.relevant &&
731 cat >../trace.expect <<EOF &&
732 ....path:
733 ....node-creation:2
734 ....gitignore-invalidation:0
735 ....directory-invalidation:1
736 ....opendir:3
738 test_cmp ../trace.expect ../trace.relevant
741 test_expect_success 'verify untracked cache dump (sparse/subdirs)' '
742 test-tool dump-untracked-cache >../actual &&
743 cat >../expect-from-test-dump <<EOF &&
744 info/exclude $(test_oid exclude)
745 core.excludesfile $ZERO_OID
746 exclude_per_dir .gitignore
747 flags 00000006
748 / $(test_oid root) recurse valid
749 .gitignore
750 dtwo/
751 /done/ $(test_oid done) recurse valid
752 five
753 sub/
754 /done/sub/ $ZERO_OID recurse check_only valid
755 sub/
756 /done/sub/sub/ $ZERO_OID recurse check_only valid
757 file
758 /dthree/ $ZERO_OID recurse check_only valid
759 /dtwo/ $ZERO_OID recurse check_only valid
762 test_cmp ../expect-from-test-dump ../actual
765 test_expect_success 'test sparse status again with untracked cache and subdir' '
766 : >../trace.output &&
767 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
768 git status --porcelain >../status.actual &&
769 iuc status --porcelain >../status.iuc &&
770 test_cmp ../status.expect ../status.iuc &&
771 test_cmp ../status.expect ../status.actual &&
772 get_relevant_traces ../trace.output ../trace.relevant &&
773 cat >../trace.expect <<EOF &&
774 ....path:
775 ....node-creation:0
776 ....gitignore-invalidation:0
777 ....directory-invalidation:0
778 ....opendir:0
780 test_cmp ../trace.expect ../trace.relevant
783 test_expect_success 'move entry in subdir from untracked to cached' '
784 git add dtwo/two &&
785 git status --porcelain >../status.actual &&
786 iuc status --porcelain >../status.iuc &&
787 cat >../status.expect <<EOF &&
788 M done/two
789 A dtwo/two
790 ?? .gitignore
791 ?? done/five
792 ?? done/sub/
794 test_cmp ../status.expect ../status.iuc &&
795 test_cmp ../status.expect ../status.actual
798 test_expect_success 'move entry in subdir from cached to untracked' '
799 git rm --cached dtwo/two &&
800 git status --porcelain >../status.actual &&
801 iuc status --porcelain >../status.iuc &&
802 cat >../status.expect <<EOF &&
803 M done/two
804 ?? .gitignore
805 ?? done/five
806 ?? done/sub/
807 ?? dtwo/
809 test_cmp ../status.expect ../status.iuc &&
810 test_cmp ../status.expect ../status.actual
813 test_expect_success '--no-untracked-cache removes the cache' '
814 git update-index --no-untracked-cache &&
815 test-tool dump-untracked-cache >../actual &&
816 echo "no untracked cache" >../expect-no-uc &&
817 test_cmp ../expect-no-uc ../actual
820 test_expect_success 'git status does not change anything' '
821 git status &&
822 test-tool dump-untracked-cache >../actual &&
823 test_cmp ../expect-no-uc ../actual
826 test_expect_success 'setting core.untrackedCache to true and using git status creates the cache' '
827 git config core.untrackedCache true &&
828 test-tool dump-untracked-cache >../actual &&
829 test_cmp ../expect-no-uc ../actual &&
830 git status &&
831 test-tool dump-untracked-cache >../actual &&
832 test_cmp ../expect-from-test-dump ../actual
835 test_expect_success 'using --no-untracked-cache does not fail when core.untrackedCache is true' '
836 git update-index --no-untracked-cache &&
837 test-tool dump-untracked-cache >../actual &&
838 test_cmp ../expect-no-uc ../actual &&
839 git update-index --untracked-cache &&
840 test-tool dump-untracked-cache >../actual &&
841 test_cmp ../expect-empty ../actual
844 test_expect_success 'setting core.untrackedCache to false and using git status removes the cache' '
845 git config core.untrackedCache false &&
846 test-tool dump-untracked-cache >../actual &&
847 test_cmp ../expect-empty ../actual &&
848 git status &&
849 test-tool dump-untracked-cache >../actual &&
850 test_cmp ../expect-no-uc ../actual
853 test_expect_success 'using --untracked-cache does not fail when core.untrackedCache is false' '
854 git update-index --untracked-cache &&
855 test-tool dump-untracked-cache >../actual &&
856 test_cmp ../expect-empty ../actual
859 test_expect_success 'setting core.untrackedCache to keep' '
860 git config core.untrackedCache keep &&
861 git update-index --untracked-cache &&
862 test-tool dump-untracked-cache >../actual &&
863 test_cmp ../expect-empty ../actual &&
864 git status &&
865 test-tool dump-untracked-cache >../actual &&
866 test_cmp ../expect-from-test-dump ../actual &&
867 git update-index --no-untracked-cache &&
868 test-tool dump-untracked-cache >../actual &&
869 test_cmp ../expect-no-uc ../actual &&
870 git update-index --force-untracked-cache &&
871 test-tool dump-untracked-cache >../actual &&
872 test_cmp ../expect-empty ../actual &&
873 git status &&
874 test-tool dump-untracked-cache >../actual &&
875 test_cmp ../expect-from-test-dump ../actual
878 test_expect_success 'test ident field is working' '
879 mkdir ../other_worktree &&
880 cp -R done dthree dtwo four three ../other_worktree &&
881 GIT_WORK_TREE=../other_worktree git status 2>../err &&
882 echo "warning: untracked cache is disabled on this system or location" >../expect &&
883 test_cmp ../expect ../err
886 test_expect_success 'untracked cache survives a checkout' '
887 git commit --allow-empty -m empty &&
888 test-tool dump-untracked-cache >../before &&
889 test_when_finished "git checkout main" &&
890 git checkout -b other_branch &&
891 test-tool dump-untracked-cache >../after &&
892 test_cmp ../before ../after &&
893 test_commit test &&
894 test-tool dump-untracked-cache >../before &&
895 git checkout main &&
896 test-tool dump-untracked-cache >../after &&
897 test_cmp ../before ../after
900 test_expect_success 'untracked cache survives a commit' '
901 test-tool dump-untracked-cache >../before &&
902 git add done/two &&
903 git commit -m commit &&
904 test-tool dump-untracked-cache >../after &&
905 test_cmp ../before ../after
908 test_expect_success 'teardown worktree' '
909 cd ..
912 test_expect_success SYMLINKS 'setup worktree for symlink test' '
913 git init worktree-symlink &&
914 cd worktree-symlink &&
915 git config core.untrackedCache true &&
916 mkdir one two &&
917 touch one/file two/file &&
918 git add one/file two/file &&
919 git commit -m"first commit" &&
920 git rm -rf one &&
921 ln -s two one &&
922 git add one &&
923 git commit -m"second commit"
926 test_expect_success SYMLINKS '"status" after symlink replacement should be clean with UC=true' '
927 git checkout HEAD~ &&
928 status_is_clean &&
929 status_is_clean &&
930 git checkout main &&
931 avoid_racy &&
932 status_is_clean &&
933 status_is_clean
936 test_expect_success SYMLINKS '"status" after symlink replacement should be clean with UC=false' '
937 git config core.untrackedCache false &&
938 git checkout HEAD~ &&
939 status_is_clean &&
940 status_is_clean &&
941 git checkout main &&
942 avoid_racy &&
943 status_is_clean &&
944 status_is_clean
947 test_expect_success 'setup worktree for non-symlink test' '
948 git init worktree-non-symlink &&
949 cd worktree-non-symlink &&
950 git config core.untrackedCache true &&
951 mkdir one two &&
952 touch one/file two/file &&
953 git add one/file two/file &&
954 git commit -m"first commit" &&
955 git rm -rf one &&
956 cp two/file one &&
957 git add one &&
958 git commit -m"second commit"
961 test_expect_success '"status" after file replacement should be clean with UC=true' '
962 git checkout HEAD~ &&
963 status_is_clean &&
964 status_is_clean &&
965 git checkout main &&
966 avoid_racy &&
967 status_is_clean &&
968 test-tool dump-untracked-cache >../actual &&
969 grep -F "recurse valid" ../actual >../actual.grep &&
970 cat >../expect.grep <<EOF &&
971 / $ZERO_OID recurse valid
972 /two/ $ZERO_OID recurse valid
974 status_is_clean &&
975 test_cmp ../expect.grep ../actual.grep
978 test_expect_success '"status" after file replacement should be clean with UC=false' '
979 git config core.untrackedCache false &&
980 git checkout HEAD~ &&
981 status_is_clean &&
982 status_is_clean &&
983 git checkout main &&
984 avoid_racy &&
985 status_is_clean &&
986 status_is_clean
989 test_expect_success 'empty repo (no index) and core.untrackedCache' '
990 git init emptyrepo &&
991 git -C emptyrepo -c core.untrackedCache=true write-tree
994 test_done