]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7063-status-untracked-cache.sh
Start the 2.46 cycle
[thirdparty/git.git] / t / t7063-status-untracked-cache.sh
CommitLineData
a3ddcefd
NTND
1#!/bin/sh
2
3test_description='test untracked cache'
4
01dc8133 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
a3ddcefd
NTND
8. ./test-lib.sh
9
6b7728db
NTND
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.
16#
17# See <20160803174522.5571-1-pclouds@gmail.com> if you want to know
18# more.
19
026336cb
JH
20GIT_FORCE_UNTRACKED_CACHE=true
21export GIT_FORCE_UNTRACKED_CACHE
fc9ecbeb 22
6b7728db 23sync_mtime () {
d51dd4ca 24 find . -type d -exec ls -ld {} + >/dev/null
6b7728db
NTND
25}
26
a3ddcefd
NTND
27avoid_racy() {
28 sleep 1
29}
30
ce0330ca 31status_is_clean() {
ce0330ca 32 git status --porcelain >../status.actual &&
d3c6751b 33 test_must_be_empty ../status.actual
ce0330ca
ÆAB
34}
35
ce5c61a3
EN
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
41iuc () {
42 git ls-files -s >../current-index-entries
43 git ls-files -t | sed -ne s/^S.//p >../current-sparse-entries
44
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)
49
50 git -c core.untrackedCache=false "$@"
51 ret=$?
52
53 rm ../current-index-entries
54 rm $GIT_INDEX_FILE
55 unset GIT_INDEX_FILE
56
57 return $ret
58}
59
7f9dd879
EN
60get_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 |
7fe1ffda
EN
68 cut -d "|" -f 9 |
69 grep -v visited \
7f9dd879
EN
70 >"$OUTPUT_FILE"
71}
72
73
fa73a582 74test_lazy_prereq UNTRACKED_CACHE '
435ec090 75 { git update-index --test-untracked-cache; ret=$?; } &&
fa73a582
JK
76 test $ret -ne 1
77'
78
79if ! test_have_prereq UNTRACKED_CACHE; then
a3ddcefd
NTND
80 skip_all='This system does not support untracked cache'
81 test_done
82fi
83
7c121788
CC
84test_expect_success 'core.untrackedCache is unset' '
85 test_must_fail git config --get core.untrackedCache
86'
87
a3ddcefd 88test_expect_success 'setup' '
1d758728 89 git init --template= worktree &&
a3ddcefd
NTND
90 cd worktree &&
91 mkdir done dtwo dthree &&
92 touch one two three done/one dtwo/two dthree/three &&
9ba83ebf
TK
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 . &&
a3ddcefd 96 git add one two done/one &&
1d758728 97 mkdir .git/info &&
a3ddcefd 98 : >.git/info/exclude &&
866be6ec 99 git update-index --untracked-cache &&
100 test_oid_cache <<-EOF
101 root sha1:e6fcc8f2ee31bae321d66afd183fcb7237afae6e
102 root sha256:b90c672088c015b9c83876e919da311bad4cd39639fb139f988af6a11493b974
103
104 exclude sha1:13263c0978fb9fad16b2d580fb800b6d811c3ff0
105 exclude sha256:fe4aaa1bbbbce4cb8f73426748a14c5ad6026b26f90505a0bf2494b165a5b76c
106
107 done sha1:1946f0437f90c5005533cbe1736a6451ca301714
108 done sha256:7f079501d79f665b3acc50f5e0e9e94509084d5032ac20113a37dd5029b757cc
109 EOF
a3ddcefd
NTND
110'
111
112test_expect_success 'untracked cache is empty' '
cd780f0b 113 test-tool dump-untracked-cache >../actual &&
7c121788 114 cat >../expect-empty <<EOF &&
866be6ec 115info/exclude $ZERO_OID
116core.excludesfile $ZERO_OID
a3ddcefd
NTND
117exclude_per_dir .gitignore
118flags 00000006
119EOF
7c121788 120 test_cmp ../expect-empty ../actual
a3ddcefd
NTND
121'
122
123cat >../status.expect <<EOF &&
124A done/one
125A one
126A two
127?? dthree/
128?? dtwo/
129?? three
130EOF
131
132cat >../dump.expect <<EOF &&
378932d3 133info/exclude $EMPTY_BLOB
866be6ec 134core.excludesfile $ZERO_OID
a3ddcefd
NTND
135exclude_per_dir .gitignore
136flags 00000006
866be6ec 137/ $ZERO_OID recurse valid
a3ddcefd
NTND
138dthree/
139dtwo/
140three
866be6ec 141/done/ $ZERO_OID recurse valid
142/dthree/ $ZERO_OID recurse check_only valid
a3ddcefd 143three
866be6ec 144/dtwo/ $ZERO_OID recurse check_only valid
a3ddcefd
NTND
145two
146EOF
147
148test_expect_success 'status first time (empty cache)' '
7f9dd879
EN
149 : >../trace.output &&
150 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
a3ddcefd 151 git status --porcelain >../actual &&
ce5c61a3
EN
152 iuc status --porcelain >../status.iuc &&
153 test_cmp ../status.expect ../status.iuc &&
a3ddcefd 154 test_cmp ../status.expect ../actual &&
7f9dd879 155 get_relevant_traces ../trace.output ../trace.relevant &&
a3ddcefd 156 cat >../trace.expect <<EOF &&
7f9dd879
EN
157 ....path:
158 ....node-creation:3
159 ....gitignore-invalidation:1
160 ....directory-invalidation:0
161 ....opendir:4
a3ddcefd 162EOF
7f9dd879 163 test_cmp ../trace.expect ../trace.relevant
a3ddcefd
NTND
164'
165
166test_expect_success 'untracked cache after first status' '
cd780f0b 167 test-tool dump-untracked-cache >../actual &&
a3ddcefd
NTND
168 test_cmp ../dump.expect ../actual
169'
170
171test_expect_success 'status second time (fully populated cache)' '
7f9dd879
EN
172 : >../trace.output &&
173 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
a3ddcefd 174 git status --porcelain >../actual &&
ce5c61a3
EN
175 iuc status --porcelain >../status.iuc &&
176 test_cmp ../status.expect ../status.iuc &&
a3ddcefd 177 test_cmp ../status.expect ../actual &&
7f9dd879 178 get_relevant_traces ../trace.output ../trace.relevant &&
a3ddcefd 179 cat >../trace.expect <<EOF &&
7f9dd879
EN
180 ....path:
181 ....node-creation:0
182 ....gitignore-invalidation:0
183 ....directory-invalidation:0
184 ....opendir:0
a3ddcefd 185EOF
7f9dd879 186 test_cmp ../trace.expect ../trace.relevant
a3ddcefd
NTND
187'
188
189test_expect_success 'untracked cache after second status' '
cd780f0b 190 test-tool dump-untracked-cache >../actual &&
a3ddcefd
NTND
191 test_cmp ../dump.expect ../actual
192'
193
a0231869
TK
194cat >../status_uall.expect <<EOF &&
195A done/one
196A one
197A two
198?? dthree/three
199?? dtwo/two
200?? three
201EOF
202
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.
207test_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:
217EOF
218 test_cmp ../trace.expect ../trace.relevant
219'
220
221test_expect_success 'untracked cache remains after bypass' '
222 test-tool dump-untracked-cache >../actual &&
223 test_cmp ../dump.expect ../actual
224'
225
e6a65355
TK
226test_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
241EOF
242 test_cmp ../trace.expect ../trace.relevant
243'
244
245cat >../dump_uall.expect <<EOF &&
246info/exclude $EMPTY_BLOB
247core.excludesfile $ZERO_OID
248exclude_per_dir .gitignore
249flags 00000000
250/ $ZERO_OID recurse valid
251three
252/done/ $ZERO_OID recurse valid
253/dthree/ $ZERO_OID recurse valid
254three
255/dtwo/ $ZERO_OID recurse valid
256two
257EOF
258
259test_expect_success 'if -uall was configured, untracked cache is populated' '
260 test-tool dump-untracked-cache >../actual &&
261 test_cmp ../dump_uall.expect ../actual
262'
263
264test_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
279EOF
280 test_cmp ../trace.expect ../trace.relevant
281'
282
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.
288test_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:
299EOF
300 test_cmp ../trace.expect ../trace.relevant
301'
302
303test_expect_success 'repopulate untracked cache for -unormal' '
304 git status --porcelain
305'
306
a3ddcefd 307test_expect_success 'modify in root directory, one dir invalidation' '
a3ddcefd 308 : >four &&
9ba83ebf 309 test-tool chmtime =-240 four &&
7f9dd879
EN
310 : >../trace.output &&
311 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
a3ddcefd 312 git status --porcelain >../actual &&
ce5c61a3 313 iuc status --porcelain >../status.iuc &&
a3ddcefd
NTND
314 cat >../status.expect <<EOF &&
315A done/one
316A one
317A two
318?? dthree/
319?? dtwo/
320?? four
321?? three
322EOF
ce5c61a3 323 test_cmp ../status.expect ../status.iuc &&
a3ddcefd 324 test_cmp ../status.expect ../actual &&
7f9dd879 325 get_relevant_traces ../trace.output ../trace.relevant &&
a3ddcefd 326 cat >../trace.expect <<EOF &&
7f9dd879
EN
327 ....path:
328 ....node-creation:0
329 ....gitignore-invalidation:0
330 ....directory-invalidation:1
331 ....opendir:1
a3ddcefd 332EOF
7f9dd879 333 test_cmp ../trace.expect ../trace.relevant
a3ddcefd
NTND
334
335'
336
337test_expect_success 'verify untracked cache dump' '
cd780f0b 338 test-tool dump-untracked-cache >../actual &&
a3ddcefd 339 cat >../expect <<EOF &&
378932d3 340info/exclude $EMPTY_BLOB
866be6ec 341core.excludesfile $ZERO_OID
a3ddcefd
NTND
342exclude_per_dir .gitignore
343flags 00000006
866be6ec 344/ $ZERO_OID recurse valid
a3ddcefd
NTND
345dthree/
346dtwo/
347four
348three
866be6ec 349/done/ $ZERO_OID recurse valid
350/dthree/ $ZERO_OID recurse check_only valid
a3ddcefd 351three
866be6ec 352/dtwo/ $ZERO_OID recurse check_only valid
a3ddcefd
NTND
353two
354EOF
355 test_cmp ../expect ../actual
356'
357
358test_expect_success 'new .gitignore invalidates recursively' '
a3ddcefd 359 echo four >.gitignore &&
7f9dd879
EN
360 : >../trace.output &&
361 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
a3ddcefd 362 git status --porcelain >../actual &&
ce5c61a3 363 iuc status --porcelain >../status.iuc &&
a3ddcefd
NTND
364 cat >../status.expect <<EOF &&
365A done/one
366A one
367A two
368?? .gitignore
369?? dthree/
370?? dtwo/
371?? three
372EOF
ce5c61a3 373 test_cmp ../status.expect ../status.iuc &&
a3ddcefd 374 test_cmp ../status.expect ../actual &&
7f9dd879 375 get_relevant_traces ../trace.output ../trace.relevant &&
a3ddcefd 376 cat >../trace.expect <<EOF &&
7f9dd879
EN
377 ....path:
378 ....node-creation:0
379 ....gitignore-invalidation:1
380 ....directory-invalidation:1
381 ....opendir:4
a3ddcefd 382EOF
7f9dd879 383 test_cmp ../trace.expect ../trace.relevant
a3ddcefd
NTND
384
385'
386
387test_expect_success 'verify untracked cache dump' '
cd780f0b 388 test-tool dump-untracked-cache >../actual &&
a3ddcefd 389 cat >../expect <<EOF &&
378932d3 390info/exclude $EMPTY_BLOB
866be6ec 391core.excludesfile $ZERO_OID
a3ddcefd
NTND
392exclude_per_dir .gitignore
393flags 00000006
866be6ec 394/ $(test_oid root) recurse valid
a3ddcefd
NTND
395.gitignore
396dthree/
397dtwo/
398three
866be6ec 399/done/ $ZERO_OID recurse valid
400/dthree/ $ZERO_OID recurse check_only valid
a3ddcefd 401three
866be6ec 402/dtwo/ $ZERO_OID recurse check_only valid
a3ddcefd
NTND
403two
404EOF
405 test_cmp ../expect ../actual
406'
407
408test_expect_success 'new info/exclude invalidates everything' '
a3ddcefd 409 echo three >>.git/info/exclude &&
7f9dd879
EN
410 : >../trace.output &&
411 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
a3ddcefd 412 git status --porcelain >../actual &&
ce5c61a3 413 iuc status --porcelain >../status.iuc &&
a3ddcefd
NTND
414 cat >../status.expect <<EOF &&
415A done/one
416A one
417A two
418?? .gitignore
419?? dtwo/
420EOF
ce5c61a3 421 test_cmp ../status.expect ../status.iuc &&
a3ddcefd 422 test_cmp ../status.expect ../actual &&
7f9dd879 423 get_relevant_traces ../trace.output ../trace.relevant &&
a3ddcefd 424 cat >../trace.expect <<EOF &&
7f9dd879
EN
425 ....path:
426 ....node-creation:0
427 ....gitignore-invalidation:1
428 ....directory-invalidation:0
429 ....opendir:4
a3ddcefd 430EOF
7f9dd879 431 test_cmp ../trace.expect ../trace.relevant
a3ddcefd
NTND
432'
433
434test_expect_success 'verify untracked cache dump' '
cd780f0b 435 test-tool dump-untracked-cache >../actual &&
a3ddcefd 436 cat >../expect <<EOF &&
866be6ec 437info/exclude $(test_oid exclude)
438core.excludesfile $ZERO_OID
a3ddcefd
NTND
439exclude_per_dir .gitignore
440flags 00000006
866be6ec 441/ $(test_oid root) recurse valid
a3ddcefd
NTND
442.gitignore
443dtwo/
866be6ec 444/done/ $ZERO_OID recurse valid
445/dthree/ $ZERO_OID recurse check_only valid
446/dtwo/ $ZERO_OID recurse check_only valid
a3ddcefd
NTND
447two
448EOF
449 test_cmp ../expect ../actual
450'
451
452test_expect_success 'move two from tracked to untracked' '
453 git rm --cached two &&
cd780f0b 454 test-tool dump-untracked-cache >../actual &&
a3ddcefd 455 cat >../expect <<EOF &&
866be6ec 456info/exclude $(test_oid exclude)
457core.excludesfile $ZERO_OID
a3ddcefd
NTND
458exclude_per_dir .gitignore
459flags 00000006
866be6ec 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
a3ddcefd
NTND
464two
465EOF
466 test_cmp ../expect ../actual
467'
468
469test_expect_success 'status after the move' '
7f9dd879
EN
470 : >../trace.output &&
471 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
a3ddcefd 472 git status --porcelain >../actual &&
ce5c61a3 473 iuc status --porcelain >../status.iuc &&
a3ddcefd
NTND
474 cat >../status.expect <<EOF &&
475A done/one
476A one
477?? .gitignore
478?? dtwo/
479?? two
480EOF
ce5c61a3 481 test_cmp ../status.expect ../status.iuc &&
a3ddcefd 482 test_cmp ../status.expect ../actual &&
7f9dd879 483 get_relevant_traces ../trace.output ../trace.relevant &&
a3ddcefd 484 cat >../trace.expect <<EOF &&
7f9dd879
EN
485 ....path:
486 ....node-creation:0
487 ....gitignore-invalidation:0
488 ....directory-invalidation:0
489 ....opendir:1
a3ddcefd 490EOF
7f9dd879 491 test_cmp ../trace.expect ../trace.relevant
a3ddcefd
NTND
492'
493
494test_expect_success 'verify untracked cache dump' '
cd780f0b 495 test-tool dump-untracked-cache >../actual &&
a3ddcefd 496 cat >../expect <<EOF &&
866be6ec 497info/exclude $(test_oid exclude)
498core.excludesfile $ZERO_OID
a3ddcefd
NTND
499exclude_per_dir .gitignore
500flags 00000006
866be6ec 501/ $(test_oid root) recurse valid
a3ddcefd
NTND
502.gitignore
503dtwo/
504two
866be6ec 505/done/ $ZERO_OID recurse valid
506/dthree/ $ZERO_OID recurse check_only valid
507/dtwo/ $ZERO_OID recurse check_only valid
a3ddcefd
NTND
508two
509EOF
510 test_cmp ../expect ../actual
511'
512
513test_expect_success 'move two from untracked to tracked' '
514 git add two &&
cd780f0b 515 test-tool dump-untracked-cache >../actual &&
a3ddcefd 516 cat >../expect <<EOF &&
866be6ec 517info/exclude $(test_oid exclude)
518core.excludesfile $ZERO_OID
a3ddcefd
NTND
519exclude_per_dir .gitignore
520flags 00000006
866be6ec 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
a3ddcefd
NTND
525two
526EOF
527 test_cmp ../expect ../actual
528'
529
530test_expect_success 'status after the move' '
7f9dd879
EN
531 : >../trace.output &&
532 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
a3ddcefd 533 git status --porcelain >../actual &&
ce5c61a3 534 iuc status --porcelain >../status.iuc &&
a3ddcefd
NTND
535 cat >../status.expect <<EOF &&
536A done/one
537A one
538A two
539?? .gitignore
540?? dtwo/
541EOF
ce5c61a3 542 test_cmp ../status.expect ../status.iuc &&
a3ddcefd 543 test_cmp ../status.expect ../actual &&
7f9dd879 544 get_relevant_traces ../trace.output ../trace.relevant &&
a3ddcefd 545 cat >../trace.expect <<EOF &&
7f9dd879
EN
546 ....path:
547 ....node-creation:0
548 ....gitignore-invalidation:0
549 ....directory-invalidation:0
550 ....opendir:1
a3ddcefd 551EOF
7f9dd879 552 test_cmp ../trace.expect ../trace.relevant
a3ddcefd
NTND
553'
554
555test_expect_success 'verify untracked cache dump' '
cd780f0b 556 test-tool dump-untracked-cache >../actual &&
a3ddcefd 557 cat >../expect <<EOF &&
866be6ec 558info/exclude $(test_oid exclude)
559core.excludesfile $ZERO_OID
a3ddcefd
NTND
560exclude_per_dir .gitignore
561flags 00000006
866be6ec 562/ $(test_oid root) recurse valid
a3ddcefd
NTND
563.gitignore
564dtwo/
866be6ec 565/done/ $ZERO_OID recurse valid
566/dthree/ $ZERO_OID recurse check_only valid
567/dtwo/ $ZERO_OID recurse check_only valid
a3ddcefd
NTND
568two
569EOF
570 test_cmp ../expect ../actual
571'
572
7687252f
DT
573test_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"
579'
580
581test_expect_success 'status after commit' '
7f9dd879
EN
582 : >../trace.output &&
583 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
7687252f 584 git status --porcelain >../actual &&
ce5c61a3 585 iuc status --porcelain >../status.iuc &&
7687252f
DT
586 cat >../status.expect <<EOF &&
587?? .gitignore
588?? dtwo/
589EOF
ce5c61a3 590 test_cmp ../status.expect ../status.iuc &&
7687252f 591 test_cmp ../status.expect ../actual &&
7f9dd879 592 get_relevant_traces ../trace.output ../trace.relevant &&
7687252f 593 cat >../trace.expect <<EOF &&
7f9dd879
EN
594 ....path:
595 ....node-creation:0
596 ....gitignore-invalidation:0
597 ....directory-invalidation:0
598 ....opendir:2
7687252f 599EOF
7f9dd879 600 test_cmp ../trace.expect ../trace.relevant
7687252f
DT
601'
602
603test_expect_success 'untracked cache correct after commit' '
cd780f0b 604 test-tool dump-untracked-cache >../actual &&
7687252f 605 cat >../expect <<EOF &&
866be6ec 606info/exclude $(test_oid exclude)
607core.excludesfile $ZERO_OID
7687252f
DT
608exclude_per_dir .gitignore
609flags 00000006
866be6ec 610/ $(test_oid root) recurse valid
7687252f
DT
611.gitignore
612dtwo/
866be6ec 613/done/ $ZERO_OID recurse valid
614/dthree/ $ZERO_OID recurse check_only valid
615/dtwo/ $ZERO_OID recurse check_only valid
7687252f
DT
616two
617EOF
618 test_cmp ../expect ../actual
619'
620
621test_expect_success 'set up sparse checkout' '
622 echo "done/[a-z]*" >.git/info/sparse-checkout &&
623 test_config core.sparsecheckout true &&
01dc8133 624 git checkout main &&
f178136e 625 git update-index --force-untracked-cache &&
7687252f
DT
626 git status --porcelain >/dev/null && # prime the cache
627 test_path_is_missing done/.gitignore &&
628 test_path_is_file done/one
629'
630
2e5910f2
DT
631test_expect_success 'create/modify files, some of which are gitignored' '
632 echo two bis >done/two &&
7687252f
DT
633 echo three >done/three && # three is gitignored
634 echo four >done/four && # four is gitignored at a higher level
9b680fbd 635 echo five >done/five && # five is not gitignored
9ba83ebf
TK
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 . &&
6b7728db 639 sync_mtime
7687252f
DT
640'
641
642test_expect_success 'test sparse status with untracked cache' '
7f9dd879 643 : >../trace.output &&
7f9dd879 644 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
7687252f 645 git status --porcelain >../status.actual &&
ce5c61a3 646 iuc status --porcelain >../status.iuc &&
7687252f 647 cat >../status.expect <<EOF &&
2e5910f2 648 M done/two
7687252f
DT
649?? .gitignore
650?? done/five
651?? dtwo/
652EOF
ce5c61a3 653 test_cmp ../status.expect ../status.iuc &&
7687252f 654 test_cmp ../status.expect ../status.actual &&
7f9dd879 655 get_relevant_traces ../trace.output ../trace.relevant &&
7687252f 656 cat >../trace.expect <<EOF &&
7f9dd879
EN
657 ....path:
658 ....node-creation:0
659 ....gitignore-invalidation:1
660 ....directory-invalidation:2
661 ....opendir:2
7687252f 662EOF
7f9dd879 663 test_cmp ../trace.expect ../trace.relevant
7687252f
DT
664'
665
666test_expect_success 'untracked cache correct after status' '
cd780f0b 667 test-tool dump-untracked-cache >../actual &&
7687252f 668 cat >../expect <<EOF &&
866be6ec 669info/exclude $(test_oid exclude)
670core.excludesfile $ZERO_OID
7687252f
DT
671exclude_per_dir .gitignore
672flags 00000006
866be6ec 673/ $(test_oid root) recurse valid
7687252f
DT
674.gitignore
675dtwo/
866be6ec 676/done/ $(test_oid done) recurse valid
7687252f 677five
866be6ec 678/dthree/ $ZERO_OID recurse check_only valid
679/dtwo/ $ZERO_OID recurse check_only valid
7687252f
DT
680two
681EOF
682 test_cmp ../expect ../actual
683'
684
685test_expect_success 'test sparse status again with untracked cache' '
7f9dd879
EN
686 : >../trace.output &&
687 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
7687252f 688 git status --porcelain >../status.actual &&
ce5c61a3 689 iuc status --porcelain >../status.iuc &&
7687252f 690 cat >../status.expect <<EOF &&
2e5910f2 691 M done/two
7687252f
DT
692?? .gitignore
693?? done/five
694?? dtwo/
695EOF
ce5c61a3 696 test_cmp ../status.expect ../status.iuc &&
7687252f 697 test_cmp ../status.expect ../status.actual &&
7f9dd879 698 get_relevant_traces ../trace.output ../trace.relevant &&
7687252f 699 cat >../trace.expect <<EOF &&
7f9dd879
EN
700 ....path:
701 ....node-creation:0
702 ....gitignore-invalidation:0
703 ....directory-invalidation:0
704 ....opendir:0
7687252f 705EOF
7f9dd879 706 test_cmp ../trace.expect ../trace.relevant
7687252f
DT
707'
708
2e5910f2
DT
709test_expect_success 'set up for test of subdir and sparse checkouts' '
710 mkdir done/sub &&
711 mkdir done/sub/sub &&
9ba83ebf
TK
712 echo "sub" > done/sub/sub/file &&
713 test-tool chmtime =-120 done/sub/sub/file done/sub/sub done/sub done
2e5910f2
DT
714'
715
716test_expect_success 'test sparse status with untracked cache and subdir' '
7f9dd879
EN
717 : >../trace.output &&
718 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
2e5910f2 719 git status --porcelain >../status.actual &&
ce5c61a3 720 iuc status --porcelain >../status.iuc &&
2e5910f2
DT
721 cat >../status.expect <<EOF &&
722 M done/two
723?? .gitignore
724?? done/five
725?? done/sub/
726?? dtwo/
727EOF
ce5c61a3 728 test_cmp ../status.expect ../status.iuc &&
2e5910f2 729 test_cmp ../status.expect ../status.actual &&
7f9dd879 730 get_relevant_traces ../trace.output ../trace.relevant &&
2e5910f2 731 cat >../trace.expect <<EOF &&
7f9dd879
EN
732 ....path:
733 ....node-creation:2
734 ....gitignore-invalidation:0
735 ....directory-invalidation:1
736 ....opendir:3
2e5910f2 737EOF
7f9dd879 738 test_cmp ../trace.expect ../trace.relevant
2e5910f2
DT
739'
740
741test_expect_success 'verify untracked cache dump (sparse/subdirs)' '
cd780f0b 742 test-tool dump-untracked-cache >../actual &&
7c121788 743 cat >../expect-from-test-dump <<EOF &&
866be6ec 744info/exclude $(test_oid exclude)
745core.excludesfile $ZERO_OID
2e5910f2
DT
746exclude_per_dir .gitignore
747flags 00000006
866be6ec 748/ $(test_oid root) recurse valid
2e5910f2
DT
749.gitignore
750dtwo/
866be6ec 751/done/ $(test_oid done) recurse valid
2e5910f2
DT
752five
753sub/
866be6ec 754/done/sub/ $ZERO_OID recurse check_only valid
2e5910f2 755sub/
866be6ec 756/done/sub/sub/ $ZERO_OID recurse check_only valid
2e5910f2 757file
866be6ec 758/dthree/ $ZERO_OID recurse check_only valid
759/dtwo/ $ZERO_OID recurse check_only valid
2e5910f2
DT
760two
761EOF
7c121788 762 test_cmp ../expect-from-test-dump ../actual
2e5910f2
DT
763'
764
765test_expect_success 'test sparse status again with untracked cache and subdir' '
7f9dd879
EN
766 : >../trace.output &&
767 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
2e5910f2 768 git status --porcelain >../status.actual &&
ce5c61a3
EN
769 iuc status --porcelain >../status.iuc &&
770 test_cmp ../status.expect ../status.iuc &&
2e5910f2 771 test_cmp ../status.expect ../status.actual &&
7f9dd879 772 get_relevant_traces ../trace.output ../trace.relevant &&
2e5910f2 773 cat >../trace.expect <<EOF &&
7f9dd879
EN
774 ....path:
775 ....node-creation:0
776 ....gitignore-invalidation:0
777 ....directory-invalidation:0
778 ....opendir:0
2e5910f2 779EOF
7f9dd879 780 test_cmp ../trace.expect ../trace.relevant
2e5910f2
DT
781'
782
73f9145f
NTND
783test_expect_success 'move entry in subdir from untracked to cached' '
784 git add dtwo/two &&
785 git status --porcelain >../status.actual &&
ce5c61a3 786 iuc status --porcelain >../status.iuc &&
73f9145f
NTND
787 cat >../status.expect <<EOF &&
788 M done/two
789A dtwo/two
790?? .gitignore
791?? done/five
792?? done/sub/
793EOF
ce5c61a3 794 test_cmp ../status.expect ../status.iuc &&
73f9145f
NTND
795 test_cmp ../status.expect ../status.actual
796'
797
798test_expect_success 'move entry in subdir from cached to untracked' '
799 git rm --cached dtwo/two &&
800 git status --porcelain >../status.actual &&
ce5c61a3 801 iuc status --porcelain >../status.iuc &&
73f9145f
NTND
802 cat >../status.expect <<EOF &&
803 M done/two
804?? .gitignore
805?? done/five
806?? done/sub/
807?? dtwo/
808EOF
ce5c61a3 809 test_cmp ../status.expect ../status.iuc &&
73f9145f
NTND
810 test_cmp ../status.expect ../status.actual
811'
812
7c121788
CC
813test_expect_success '--no-untracked-cache removes the cache' '
814 git update-index --no-untracked-cache &&
cd780f0b 815 test-tool dump-untracked-cache >../actual &&
7c121788
CC
816 echo "no untracked cache" >../expect-no-uc &&
817 test_cmp ../expect-no-uc ../actual
818'
819
820test_expect_success 'git status does not change anything' '
821 git status &&
cd780f0b 822 test-tool dump-untracked-cache >../actual &&
7c121788
CC
823 test_cmp ../expect-no-uc ../actual
824'
825
826test_expect_success 'setting core.untrackedCache to true and using git status creates the cache' '
827 git config core.untrackedCache true &&
cd780f0b 828 test-tool dump-untracked-cache >../actual &&
7c121788
CC
829 test_cmp ../expect-no-uc ../actual &&
830 git status &&
cd780f0b 831 test-tool dump-untracked-cache >../actual &&
7c121788
CC
832 test_cmp ../expect-from-test-dump ../actual
833'
834
835test_expect_success 'using --no-untracked-cache does not fail when core.untrackedCache is true' '
836 git update-index --no-untracked-cache &&
cd780f0b 837 test-tool dump-untracked-cache >../actual &&
7c121788
CC
838 test_cmp ../expect-no-uc ../actual &&
839 git update-index --untracked-cache &&
cd780f0b 840 test-tool dump-untracked-cache >../actual &&
7c121788
CC
841 test_cmp ../expect-empty ../actual
842'
843
844test_expect_success 'setting core.untrackedCache to false and using git status removes the cache' '
845 git config core.untrackedCache false &&
cd780f0b 846 test-tool dump-untracked-cache >../actual &&
7c121788
CC
847 test_cmp ../expect-empty ../actual &&
848 git status &&
cd780f0b 849 test-tool dump-untracked-cache >../actual &&
7c121788
CC
850 test_cmp ../expect-no-uc ../actual
851'
852
853test_expect_success 'using --untracked-cache does not fail when core.untrackedCache is false' '
854 git update-index --untracked-cache &&
cd780f0b 855 test-tool dump-untracked-cache >../actual &&
7c121788
CC
856 test_cmp ../expect-empty ../actual
857'
858
859test_expect_success 'setting core.untrackedCache to keep' '
860 git config core.untrackedCache keep &&
861 git update-index --untracked-cache &&
cd780f0b 862 test-tool dump-untracked-cache >../actual &&
7c121788
CC
863 test_cmp ../expect-empty ../actual &&
864 git status &&
cd780f0b 865 test-tool dump-untracked-cache >../actual &&
7c121788
CC
866 test_cmp ../expect-from-test-dump ../actual &&
867 git update-index --no-untracked-cache &&
cd780f0b 868 test-tool dump-untracked-cache >../actual &&
7c121788
CC
869 test_cmp ../expect-no-uc ../actual &&
870 git update-index --force-untracked-cache &&
cd780f0b 871 test-tool dump-untracked-cache >../actual &&
7c121788
CC
872 test_cmp ../expect-empty ../actual &&
873 git status &&
cd780f0b 874 test-tool dump-untracked-cache >../actual &&
7c121788
CC
875 test_cmp ../expect-from-test-dump ../actual
876'
877
878test_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 &&
1a07e59c 882 echo "warning: untracked cache is disabled on this system or location" >../expect &&
1108cea7 883 test_cmp ../expect ../err
7c121788
CC
884'
885
edf3b905
DT
886test_expect_success 'untracked cache survives a checkout' '
887 git commit --allow-empty -m empty &&
cd780f0b 888 test-tool dump-untracked-cache >../before &&
01dc8133 889 test_when_finished "git checkout main" &&
edf3b905 890 git checkout -b other_branch &&
cd780f0b 891 test-tool dump-untracked-cache >../after &&
edf3b905
DT
892 test_cmp ../before ../after &&
893 test_commit test &&
cd780f0b 894 test-tool dump-untracked-cache >../before &&
01dc8133 895 git checkout main &&
cd780f0b 896 test-tool dump-untracked-cache >../after &&
edf3b905
DT
897 test_cmp ../before ../after
898'
899
900test_expect_success 'untracked cache survives a commit' '
cd780f0b 901 test-tool dump-untracked-cache >../before &&
edf3b905
DT
902 git add done/two &&
903 git commit -m commit &&
cd780f0b 904 test-tool dump-untracked-cache >../after &&
edf3b905
DT
905 test_cmp ../before ../after
906'
907
ce0330ca
ÆAB
908test_expect_success 'teardown worktree' '
909 cd ..
910'
911
912test_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"
924'
925
b6403131 926test_expect_success SYMLINKS '"status" after symlink replacement should be clean with UC=true' '
ce0330ca
ÆAB
927 git checkout HEAD~ &&
928 status_is_clean &&
929 status_is_clean &&
01dc8133 930 git checkout main &&
ce0330ca
ÆAB
931 avoid_racy &&
932 status_is_clean &&
933 status_is_clean
934'
935
936test_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 &&
01dc8133 941 git checkout main &&
ce0330ca
ÆAB
942 avoid_racy &&
943 status_is_clean &&
944 status_is_clean
945'
946
947test_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"
959'
960
b6403131 961test_expect_success '"status" after file replacement should be clean with UC=true' '
ce0330ca
ÆAB
962 git checkout HEAD~ &&
963 status_is_clean &&
964 status_is_clean &&
01dc8133 965 git checkout main &&
ce0330ca
ÆAB
966 avoid_racy &&
967 status_is_clean &&
cd780f0b 968 test-tool dump-untracked-cache >../actual &&
ce0330ca
ÆAB
969 grep -F "recurse valid" ../actual >../actual.grep &&
970 cat >../expect.grep <<EOF &&
866be6ec 971/ $ZERO_OID recurse valid
972/two/ $ZERO_OID recurse valid
ce0330ca
ÆAB
973EOF
974 status_is_clean &&
975 test_cmp ../expect.grep ../actual.grep
976'
977
978test_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 &&
01dc8133 983 git checkout main &&
ce0330ca
ÆAB
984 avoid_racy &&
985 status_is_clean &&
986 status_is_clean
987'
988
4447d412
989test_expect_success 'empty repo (no index) and core.untrackedCache' '
990 git init emptyrepo &&
991 git -C emptyrepo -c core.untrackedCache=true write-tree
992'
993
a3ddcefd 994test_done