]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7063-status-untracked-cache.sh
Sync with 2.36.3
[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
NTND
88test_expect_success 'setup' '
89 git init worktree &&
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
NTND
96 git add one two done/one &&
97 : >.git/info/exclude &&
866be6ec 98 git update-index --untracked-cache &&
99 test_oid_cache <<-EOF
100 root sha1:e6fcc8f2ee31bae321d66afd183fcb7237afae6e
101 root sha256:b90c672088c015b9c83876e919da311bad4cd39639fb139f988af6a11493b974
102
103 exclude sha1:13263c0978fb9fad16b2d580fb800b6d811c3ff0
104 exclude sha256:fe4aaa1bbbbce4cb8f73426748a14c5ad6026b26f90505a0bf2494b165a5b76c
105
106 done sha1:1946f0437f90c5005533cbe1736a6451ca301714
107 done sha256:7f079501d79f665b3acc50f5e0e9e94509084d5032ac20113a37dd5029b757cc
108 EOF
a3ddcefd
NTND
109'
110
111test_expect_success 'untracked cache is empty' '
cd780f0b 112 test-tool dump-untracked-cache >../actual &&
7c121788 113 cat >../expect-empty <<EOF &&
866be6ec 114info/exclude $ZERO_OID
115core.excludesfile $ZERO_OID
a3ddcefd
NTND
116exclude_per_dir .gitignore
117flags 00000006
118EOF
7c121788 119 test_cmp ../expect-empty ../actual
a3ddcefd
NTND
120'
121
122cat >../status.expect <<EOF &&
123A done/one
124A one
125A two
126?? dthree/
127?? dtwo/
128?? three
129EOF
130
131cat >../dump.expect <<EOF &&
378932d3 132info/exclude $EMPTY_BLOB
866be6ec 133core.excludesfile $ZERO_OID
a3ddcefd
NTND
134exclude_per_dir .gitignore
135flags 00000006
866be6ec 136/ $ZERO_OID recurse valid
a3ddcefd
NTND
137dthree/
138dtwo/
139three
866be6ec 140/done/ $ZERO_OID recurse valid
141/dthree/ $ZERO_OID recurse check_only valid
a3ddcefd 142three
866be6ec 143/dtwo/ $ZERO_OID recurse check_only valid
a3ddcefd
NTND
144two
145EOF
146
147test_expect_success 'status first time (empty cache)' '
7f9dd879
EN
148 : >../trace.output &&
149 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
a3ddcefd 150 git status --porcelain >../actual &&
ce5c61a3
EN
151 iuc status --porcelain >../status.iuc &&
152 test_cmp ../status.expect ../status.iuc &&
a3ddcefd 153 test_cmp ../status.expect ../actual &&
7f9dd879 154 get_relevant_traces ../trace.output ../trace.relevant &&
a3ddcefd 155 cat >../trace.expect <<EOF &&
7f9dd879
EN
156 ....path:
157 ....node-creation:3
158 ....gitignore-invalidation:1
159 ....directory-invalidation:0
160 ....opendir:4
a3ddcefd 161EOF
7f9dd879 162 test_cmp ../trace.expect ../trace.relevant
a3ddcefd
NTND
163'
164
165test_expect_success 'untracked cache after first status' '
cd780f0b 166 test-tool dump-untracked-cache >../actual &&
a3ddcefd
NTND
167 test_cmp ../dump.expect ../actual
168'
169
170test_expect_success 'status second time (fully populated cache)' '
7f9dd879
EN
171 : >../trace.output &&
172 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
a3ddcefd 173 git status --porcelain >../actual &&
ce5c61a3
EN
174 iuc status --porcelain >../status.iuc &&
175 test_cmp ../status.expect ../status.iuc &&
a3ddcefd 176 test_cmp ../status.expect ../actual &&
7f9dd879 177 get_relevant_traces ../trace.output ../trace.relevant &&
a3ddcefd 178 cat >../trace.expect <<EOF &&
7f9dd879
EN
179 ....path:
180 ....node-creation:0
181 ....gitignore-invalidation:0
182 ....directory-invalidation:0
183 ....opendir:0
a3ddcefd 184EOF
7f9dd879 185 test_cmp ../trace.expect ../trace.relevant
a3ddcefd
NTND
186'
187
188test_expect_success 'untracked cache after second status' '
cd780f0b 189 test-tool dump-untracked-cache >../actual &&
a3ddcefd
NTND
190 test_cmp ../dump.expect ../actual
191'
192
a0231869
TK
193cat >../status_uall.expect <<EOF &&
194A done/one
195A one
196A two
197?? dthree/three
198?? dtwo/two
199?? three
200EOF
201
202# Bypassing the untracked cache here is not desirable from an
203# end-user perspective, but is expected in the current design.
204# The untracked cache data stored for a -unormal run cannot be
205# correctly used in a -uall run - it would yield incorrect output.
206test_expect_success 'untracked cache is bypassed with -uall' '
207 : >../trace.output &&
208 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
209 git status -uall --porcelain >../actual &&
210 iuc status -uall --porcelain >../status.iuc &&
211 test_cmp ../status_uall.expect ../status.iuc &&
212 test_cmp ../status_uall.expect ../actual &&
213 get_relevant_traces ../trace.output ../trace.relevant &&
214 cat >../trace.expect <<EOF &&
215 ....path:
216EOF
217 test_cmp ../trace.expect ../trace.relevant
218'
219
220test_expect_success 'untracked cache remains after bypass' '
221 test-tool dump-untracked-cache >../actual &&
222 test_cmp ../dump.expect ../actual
223'
224
e6a65355
TK
225test_expect_success 'if -uall is configured, untracked cache gets populated by default' '
226 test_config status.showuntrackedfiles all &&
227 : >../trace.output &&
228 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
229 git status --porcelain >../actual &&
230 iuc status --porcelain >../status.iuc &&
231 test_cmp ../status_uall.expect ../status.iuc &&
232 test_cmp ../status_uall.expect ../actual &&
233 get_relevant_traces ../trace.output ../trace.relevant &&
234 cat >../trace.expect <<EOF &&
235 ....path:
236 ....node-creation:3
237 ....gitignore-invalidation:1
238 ....directory-invalidation:0
239 ....opendir:4
240EOF
241 test_cmp ../trace.expect ../trace.relevant
242'
243
244cat >../dump_uall.expect <<EOF &&
245info/exclude $EMPTY_BLOB
246core.excludesfile $ZERO_OID
247exclude_per_dir .gitignore
248flags 00000000
249/ $ZERO_OID recurse valid
250three
251/done/ $ZERO_OID recurse valid
252/dthree/ $ZERO_OID recurse valid
253three
254/dtwo/ $ZERO_OID recurse valid
255two
256EOF
257
258test_expect_success 'if -uall was configured, untracked cache is populated' '
259 test-tool dump-untracked-cache >../actual &&
260 test_cmp ../dump_uall.expect ../actual
261'
262
263test_expect_success 'if -uall is configured, untracked cache is used by default' '
264 test_config status.showuntrackedfiles all &&
265 : >../trace.output &&
266 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
267 git status --porcelain >../actual &&
268 iuc status --porcelain >../status.iuc &&
269 test_cmp ../status_uall.expect ../status.iuc &&
270 test_cmp ../status_uall.expect ../actual &&
271 get_relevant_traces ../trace.output ../trace.relevant &&
272 cat >../trace.expect <<EOF &&
273 ....path:
274 ....node-creation:0
275 ....gitignore-invalidation:0
276 ....directory-invalidation:0
277 ....opendir:0
278EOF
279 test_cmp ../trace.expect ../trace.relevant
280'
281
282# Bypassing the untracked cache here is not desirable from an
283# end-user perspective, but is expected in the current design.
284# The untracked cache data stored for a -all run cannot be
285# correctly used in a -unormal run - it would yield incorrect
286# output.
287test_expect_success 'if -uall is configured, untracked cache is bypassed with -unormal' '
288 test_config status.showuntrackedfiles all &&
289 : >../trace.output &&
290 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
291 git status -unormal --porcelain >../actual &&
292 iuc status -unormal --porcelain >../status.iuc &&
293 test_cmp ../status.expect ../status.iuc &&
294 test_cmp ../status.expect ../actual &&
295 get_relevant_traces ../trace.output ../trace.relevant &&
296 cat >../trace.expect <<EOF &&
297 ....path:
298EOF
299 test_cmp ../trace.expect ../trace.relevant
300'
301
302test_expect_success 'repopulate untracked cache for -unormal' '
303 git status --porcelain
304'
305
a3ddcefd 306test_expect_success 'modify in root directory, one dir invalidation' '
a3ddcefd 307 : >four &&
9ba83ebf 308 test-tool chmtime =-240 four &&
7f9dd879
EN
309 : >../trace.output &&
310 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
a3ddcefd 311 git status --porcelain >../actual &&
ce5c61a3 312 iuc status --porcelain >../status.iuc &&
a3ddcefd
NTND
313 cat >../status.expect <<EOF &&
314A done/one
315A one
316A two
317?? dthree/
318?? dtwo/
319?? four
320?? three
321EOF
ce5c61a3 322 test_cmp ../status.expect ../status.iuc &&
a3ddcefd 323 test_cmp ../status.expect ../actual &&
7f9dd879 324 get_relevant_traces ../trace.output ../trace.relevant &&
a3ddcefd 325 cat >../trace.expect <<EOF &&
7f9dd879
EN
326 ....path:
327 ....node-creation:0
328 ....gitignore-invalidation:0
329 ....directory-invalidation:1
330 ....opendir:1
a3ddcefd 331EOF
7f9dd879 332 test_cmp ../trace.expect ../trace.relevant
a3ddcefd
NTND
333
334'
335
336test_expect_success 'verify untracked cache dump' '
cd780f0b 337 test-tool dump-untracked-cache >../actual &&
a3ddcefd 338 cat >../expect <<EOF &&
378932d3 339info/exclude $EMPTY_BLOB
866be6ec 340core.excludesfile $ZERO_OID
a3ddcefd
NTND
341exclude_per_dir .gitignore
342flags 00000006
866be6ec 343/ $ZERO_OID recurse valid
a3ddcefd
NTND
344dthree/
345dtwo/
346four
347three
866be6ec 348/done/ $ZERO_OID recurse valid
349/dthree/ $ZERO_OID recurse check_only valid
a3ddcefd 350three
866be6ec 351/dtwo/ $ZERO_OID recurse check_only valid
a3ddcefd
NTND
352two
353EOF
354 test_cmp ../expect ../actual
355'
356
357test_expect_success 'new .gitignore invalidates recursively' '
a3ddcefd 358 echo four >.gitignore &&
7f9dd879
EN
359 : >../trace.output &&
360 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
a3ddcefd 361 git status --porcelain >../actual &&
ce5c61a3 362 iuc status --porcelain >../status.iuc &&
a3ddcefd
NTND
363 cat >../status.expect <<EOF &&
364A done/one
365A one
366A two
367?? .gitignore
368?? dthree/
369?? dtwo/
370?? three
371EOF
ce5c61a3 372 test_cmp ../status.expect ../status.iuc &&
a3ddcefd 373 test_cmp ../status.expect ../actual &&
7f9dd879 374 get_relevant_traces ../trace.output ../trace.relevant &&
a3ddcefd 375 cat >../trace.expect <<EOF &&
7f9dd879
EN
376 ....path:
377 ....node-creation:0
378 ....gitignore-invalidation:1
379 ....directory-invalidation:1
380 ....opendir:4
a3ddcefd 381EOF
7f9dd879 382 test_cmp ../trace.expect ../trace.relevant
a3ddcefd
NTND
383
384'
385
386test_expect_success 'verify untracked cache dump' '
cd780f0b 387 test-tool dump-untracked-cache >../actual &&
a3ddcefd 388 cat >../expect <<EOF &&
378932d3 389info/exclude $EMPTY_BLOB
866be6ec 390core.excludesfile $ZERO_OID
a3ddcefd
NTND
391exclude_per_dir .gitignore
392flags 00000006
866be6ec 393/ $(test_oid root) recurse valid
a3ddcefd
NTND
394.gitignore
395dthree/
396dtwo/
397three
866be6ec 398/done/ $ZERO_OID recurse valid
399/dthree/ $ZERO_OID recurse check_only valid
a3ddcefd 400three
866be6ec 401/dtwo/ $ZERO_OID recurse check_only valid
a3ddcefd
NTND
402two
403EOF
404 test_cmp ../expect ../actual
405'
406
407test_expect_success 'new info/exclude invalidates everything' '
a3ddcefd 408 echo three >>.git/info/exclude &&
7f9dd879
EN
409 : >../trace.output &&
410 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
a3ddcefd 411 git status --porcelain >../actual &&
ce5c61a3 412 iuc status --porcelain >../status.iuc &&
a3ddcefd
NTND
413 cat >../status.expect <<EOF &&
414A done/one
415A one
416A two
417?? .gitignore
418?? dtwo/
419EOF
ce5c61a3 420 test_cmp ../status.expect ../status.iuc &&
a3ddcefd 421 test_cmp ../status.expect ../actual &&
7f9dd879 422 get_relevant_traces ../trace.output ../trace.relevant &&
a3ddcefd 423 cat >../trace.expect <<EOF &&
7f9dd879
EN
424 ....path:
425 ....node-creation:0
426 ....gitignore-invalidation:1
427 ....directory-invalidation:0
428 ....opendir:4
a3ddcefd 429EOF
7f9dd879 430 test_cmp ../trace.expect ../trace.relevant
a3ddcefd
NTND
431'
432
433test_expect_success 'verify untracked cache dump' '
cd780f0b 434 test-tool dump-untracked-cache >../actual &&
a3ddcefd 435 cat >../expect <<EOF &&
866be6ec 436info/exclude $(test_oid exclude)
437core.excludesfile $ZERO_OID
a3ddcefd
NTND
438exclude_per_dir .gitignore
439flags 00000006
866be6ec 440/ $(test_oid root) recurse valid
a3ddcefd
NTND
441.gitignore
442dtwo/
866be6ec 443/done/ $ZERO_OID recurse valid
444/dthree/ $ZERO_OID recurse check_only valid
445/dtwo/ $ZERO_OID recurse check_only valid
a3ddcefd
NTND
446two
447EOF
448 test_cmp ../expect ../actual
449'
450
451test_expect_success 'move two from tracked to untracked' '
452 git rm --cached two &&
cd780f0b 453 test-tool dump-untracked-cache >../actual &&
a3ddcefd 454 cat >../expect <<EOF &&
866be6ec 455info/exclude $(test_oid exclude)
456core.excludesfile $ZERO_OID
a3ddcefd
NTND
457exclude_per_dir .gitignore
458flags 00000006
866be6ec 459/ $(test_oid root) recurse
460/done/ $ZERO_OID recurse valid
461/dthree/ $ZERO_OID recurse check_only valid
462/dtwo/ $ZERO_OID recurse check_only valid
a3ddcefd
NTND
463two
464EOF
465 test_cmp ../expect ../actual
466'
467
468test_expect_success 'status after the move' '
7f9dd879
EN
469 : >../trace.output &&
470 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
a3ddcefd 471 git status --porcelain >../actual &&
ce5c61a3 472 iuc status --porcelain >../status.iuc &&
a3ddcefd
NTND
473 cat >../status.expect <<EOF &&
474A done/one
475A one
476?? .gitignore
477?? dtwo/
478?? two
479EOF
ce5c61a3 480 test_cmp ../status.expect ../status.iuc &&
a3ddcefd 481 test_cmp ../status.expect ../actual &&
7f9dd879 482 get_relevant_traces ../trace.output ../trace.relevant &&
a3ddcefd 483 cat >../trace.expect <<EOF &&
7f9dd879
EN
484 ....path:
485 ....node-creation:0
486 ....gitignore-invalidation:0
487 ....directory-invalidation:0
488 ....opendir:1
a3ddcefd 489EOF
7f9dd879 490 test_cmp ../trace.expect ../trace.relevant
a3ddcefd
NTND
491'
492
493test_expect_success 'verify untracked cache dump' '
cd780f0b 494 test-tool dump-untracked-cache >../actual &&
a3ddcefd 495 cat >../expect <<EOF &&
866be6ec 496info/exclude $(test_oid exclude)
497core.excludesfile $ZERO_OID
a3ddcefd
NTND
498exclude_per_dir .gitignore
499flags 00000006
866be6ec 500/ $(test_oid root) recurse valid
a3ddcefd
NTND
501.gitignore
502dtwo/
503two
866be6ec 504/done/ $ZERO_OID recurse valid
505/dthree/ $ZERO_OID recurse check_only valid
506/dtwo/ $ZERO_OID recurse check_only valid
a3ddcefd
NTND
507two
508EOF
509 test_cmp ../expect ../actual
510'
511
512test_expect_success 'move two from untracked to tracked' '
513 git add two &&
cd780f0b 514 test-tool dump-untracked-cache >../actual &&
a3ddcefd 515 cat >../expect <<EOF &&
866be6ec 516info/exclude $(test_oid exclude)
517core.excludesfile $ZERO_OID
a3ddcefd
NTND
518exclude_per_dir .gitignore
519flags 00000006
866be6ec 520/ $(test_oid root) recurse
521/done/ $ZERO_OID recurse valid
522/dthree/ $ZERO_OID recurse check_only valid
523/dtwo/ $ZERO_OID recurse check_only valid
a3ddcefd
NTND
524two
525EOF
526 test_cmp ../expect ../actual
527'
528
529test_expect_success 'status after the move' '
7f9dd879
EN
530 : >../trace.output &&
531 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
a3ddcefd 532 git status --porcelain >../actual &&
ce5c61a3 533 iuc status --porcelain >../status.iuc &&
a3ddcefd
NTND
534 cat >../status.expect <<EOF &&
535A done/one
536A one
537A two
538?? .gitignore
539?? dtwo/
540EOF
ce5c61a3 541 test_cmp ../status.expect ../status.iuc &&
a3ddcefd 542 test_cmp ../status.expect ../actual &&
7f9dd879 543 get_relevant_traces ../trace.output ../trace.relevant &&
a3ddcefd 544 cat >../trace.expect <<EOF &&
7f9dd879
EN
545 ....path:
546 ....node-creation:0
547 ....gitignore-invalidation:0
548 ....directory-invalidation:0
549 ....opendir:1
a3ddcefd 550EOF
7f9dd879 551 test_cmp ../trace.expect ../trace.relevant
a3ddcefd
NTND
552'
553
554test_expect_success 'verify untracked cache dump' '
cd780f0b 555 test-tool dump-untracked-cache >../actual &&
a3ddcefd 556 cat >../expect <<EOF &&
866be6ec 557info/exclude $(test_oid exclude)
558core.excludesfile $ZERO_OID
a3ddcefd
NTND
559exclude_per_dir .gitignore
560flags 00000006
866be6ec 561/ $(test_oid root) recurse valid
a3ddcefd
NTND
562.gitignore
563dtwo/
866be6ec 564/done/ $ZERO_OID recurse valid
565/dthree/ $ZERO_OID recurse check_only valid
566/dtwo/ $ZERO_OID recurse check_only valid
a3ddcefd
NTND
567two
568EOF
569 test_cmp ../expect ../actual
570'
571
7687252f
DT
572test_expect_success 'set up for sparse checkout testing' '
573 echo two >done/.gitignore &&
574 echo three >>done/.gitignore &&
575 echo two >done/two &&
576 git add -f done/two done/.gitignore &&
577 git commit -m "first commit"
578'
579
580test_expect_success 'status after commit' '
7f9dd879
EN
581 : >../trace.output &&
582 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
7687252f 583 git status --porcelain >../actual &&
ce5c61a3 584 iuc status --porcelain >../status.iuc &&
7687252f
DT
585 cat >../status.expect <<EOF &&
586?? .gitignore
587?? dtwo/
588EOF
ce5c61a3 589 test_cmp ../status.expect ../status.iuc &&
7687252f 590 test_cmp ../status.expect ../actual &&
7f9dd879 591 get_relevant_traces ../trace.output ../trace.relevant &&
7687252f 592 cat >../trace.expect <<EOF &&
7f9dd879
EN
593 ....path:
594 ....node-creation:0
595 ....gitignore-invalidation:0
596 ....directory-invalidation:0
597 ....opendir:2
7687252f 598EOF
7f9dd879 599 test_cmp ../trace.expect ../trace.relevant
7687252f
DT
600'
601
602test_expect_success 'untracked cache correct after commit' '
cd780f0b 603 test-tool dump-untracked-cache >../actual &&
7687252f 604 cat >../expect <<EOF &&
866be6ec 605info/exclude $(test_oid exclude)
606core.excludesfile $ZERO_OID
7687252f
DT
607exclude_per_dir .gitignore
608flags 00000006
866be6ec 609/ $(test_oid root) recurse valid
7687252f
DT
610.gitignore
611dtwo/
866be6ec 612/done/ $ZERO_OID recurse valid
613/dthree/ $ZERO_OID recurse check_only valid
614/dtwo/ $ZERO_OID recurse check_only valid
7687252f
DT
615two
616EOF
617 test_cmp ../expect ../actual
618'
619
620test_expect_success 'set up sparse checkout' '
621 echo "done/[a-z]*" >.git/info/sparse-checkout &&
622 test_config core.sparsecheckout true &&
01dc8133 623 git checkout main &&
f178136e 624 git update-index --force-untracked-cache &&
7687252f
DT
625 git status --porcelain >/dev/null && # prime the cache
626 test_path_is_missing done/.gitignore &&
627 test_path_is_file done/one
628'
629
2e5910f2
DT
630test_expect_success 'create/modify files, some of which are gitignored' '
631 echo two bis >done/two &&
7687252f
DT
632 echo three >done/three && # three is gitignored
633 echo four >done/four && # four is gitignored at a higher level
9b680fbd 634 echo five >done/five && # five is not gitignored
9ba83ebf
TK
635 test-tool chmtime =-180 done/two done/three done/four done/five done &&
636 # we need to ensure that the root dir is touched (in the past);
637 test-tool chmtime =-180 . &&
6b7728db 638 sync_mtime
7687252f
DT
639'
640
641test_expect_success 'test sparse status with untracked cache' '
7f9dd879 642 : >../trace.output &&
7f9dd879 643 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
7687252f 644 git status --porcelain >../status.actual &&
ce5c61a3 645 iuc status --porcelain >../status.iuc &&
7687252f 646 cat >../status.expect <<EOF &&
2e5910f2 647 M done/two
7687252f
DT
648?? .gitignore
649?? done/five
650?? dtwo/
651EOF
ce5c61a3 652 test_cmp ../status.expect ../status.iuc &&
7687252f 653 test_cmp ../status.expect ../status.actual &&
7f9dd879 654 get_relevant_traces ../trace.output ../trace.relevant &&
7687252f 655 cat >../trace.expect <<EOF &&
7f9dd879
EN
656 ....path:
657 ....node-creation:0
658 ....gitignore-invalidation:1
659 ....directory-invalidation:2
660 ....opendir:2
7687252f 661EOF
7f9dd879 662 test_cmp ../trace.expect ../trace.relevant
7687252f
DT
663'
664
665test_expect_success 'untracked cache correct after status' '
cd780f0b 666 test-tool dump-untracked-cache >../actual &&
7687252f 667 cat >../expect <<EOF &&
866be6ec 668info/exclude $(test_oid exclude)
669core.excludesfile $ZERO_OID
7687252f
DT
670exclude_per_dir .gitignore
671flags 00000006
866be6ec 672/ $(test_oid root) recurse valid
7687252f
DT
673.gitignore
674dtwo/
866be6ec 675/done/ $(test_oid done) recurse valid
7687252f 676five
866be6ec 677/dthree/ $ZERO_OID recurse check_only valid
678/dtwo/ $ZERO_OID recurse check_only valid
7687252f
DT
679two
680EOF
681 test_cmp ../expect ../actual
682'
683
684test_expect_success 'test sparse status again with untracked cache' '
7f9dd879
EN
685 : >../trace.output &&
686 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
7687252f 687 git status --porcelain >../status.actual &&
ce5c61a3 688 iuc status --porcelain >../status.iuc &&
7687252f 689 cat >../status.expect <<EOF &&
2e5910f2 690 M done/two
7687252f
DT
691?? .gitignore
692?? done/five
693?? dtwo/
694EOF
ce5c61a3 695 test_cmp ../status.expect ../status.iuc &&
7687252f 696 test_cmp ../status.expect ../status.actual &&
7f9dd879 697 get_relevant_traces ../trace.output ../trace.relevant &&
7687252f 698 cat >../trace.expect <<EOF &&
7f9dd879
EN
699 ....path:
700 ....node-creation:0
701 ....gitignore-invalidation:0
702 ....directory-invalidation:0
703 ....opendir:0
7687252f 704EOF
7f9dd879 705 test_cmp ../trace.expect ../trace.relevant
7687252f
DT
706'
707
2e5910f2
DT
708test_expect_success 'set up for test of subdir and sparse checkouts' '
709 mkdir done/sub &&
710 mkdir done/sub/sub &&
9ba83ebf
TK
711 echo "sub" > done/sub/sub/file &&
712 test-tool chmtime =-120 done/sub/sub/file done/sub/sub done/sub done
2e5910f2
DT
713'
714
715test_expect_success 'test sparse status with untracked cache and subdir' '
7f9dd879
EN
716 : >../trace.output &&
717 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
2e5910f2 718 git status --porcelain >../status.actual &&
ce5c61a3 719 iuc status --porcelain >../status.iuc &&
2e5910f2
DT
720 cat >../status.expect <<EOF &&
721 M done/two
722?? .gitignore
723?? done/five
724?? done/sub/
725?? dtwo/
726EOF
ce5c61a3 727 test_cmp ../status.expect ../status.iuc &&
2e5910f2 728 test_cmp ../status.expect ../status.actual &&
7f9dd879 729 get_relevant_traces ../trace.output ../trace.relevant &&
2e5910f2 730 cat >../trace.expect <<EOF &&
7f9dd879
EN
731 ....path:
732 ....node-creation:2
733 ....gitignore-invalidation:0
734 ....directory-invalidation:1
735 ....opendir:3
2e5910f2 736EOF
7f9dd879 737 test_cmp ../trace.expect ../trace.relevant
2e5910f2
DT
738'
739
740test_expect_success 'verify untracked cache dump (sparse/subdirs)' '
cd780f0b 741 test-tool dump-untracked-cache >../actual &&
7c121788 742 cat >../expect-from-test-dump <<EOF &&
866be6ec 743info/exclude $(test_oid exclude)
744core.excludesfile $ZERO_OID
2e5910f2
DT
745exclude_per_dir .gitignore
746flags 00000006
866be6ec 747/ $(test_oid root) recurse valid
2e5910f2
DT
748.gitignore
749dtwo/
866be6ec 750/done/ $(test_oid done) recurse valid
2e5910f2
DT
751five
752sub/
866be6ec 753/done/sub/ $ZERO_OID recurse check_only valid
2e5910f2 754sub/
866be6ec 755/done/sub/sub/ $ZERO_OID recurse check_only valid
2e5910f2 756file
866be6ec 757/dthree/ $ZERO_OID recurse check_only valid
758/dtwo/ $ZERO_OID recurse check_only valid
2e5910f2
DT
759two
760EOF
7c121788 761 test_cmp ../expect-from-test-dump ../actual
2e5910f2
DT
762'
763
764test_expect_success 'test sparse status again with untracked cache and subdir' '
7f9dd879
EN
765 : >../trace.output &&
766 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
2e5910f2 767 git status --porcelain >../status.actual &&
ce5c61a3
EN
768 iuc status --porcelain >../status.iuc &&
769 test_cmp ../status.expect ../status.iuc &&
2e5910f2 770 test_cmp ../status.expect ../status.actual &&
7f9dd879 771 get_relevant_traces ../trace.output ../trace.relevant &&
2e5910f2 772 cat >../trace.expect <<EOF &&
7f9dd879
EN
773 ....path:
774 ....node-creation:0
775 ....gitignore-invalidation:0
776 ....directory-invalidation:0
777 ....opendir:0
2e5910f2 778EOF
7f9dd879 779 test_cmp ../trace.expect ../trace.relevant
2e5910f2
DT
780'
781
73f9145f
NTND
782test_expect_success 'move entry in subdir from untracked to cached' '
783 git add dtwo/two &&
784 git status --porcelain >../status.actual &&
ce5c61a3 785 iuc status --porcelain >../status.iuc &&
73f9145f
NTND
786 cat >../status.expect <<EOF &&
787 M done/two
788A dtwo/two
789?? .gitignore
790?? done/five
791?? done/sub/
792EOF
ce5c61a3 793 test_cmp ../status.expect ../status.iuc &&
73f9145f
NTND
794 test_cmp ../status.expect ../status.actual
795'
796
797test_expect_success 'move entry in subdir from cached to untracked' '
798 git rm --cached dtwo/two &&
799 git status --porcelain >../status.actual &&
ce5c61a3 800 iuc status --porcelain >../status.iuc &&
73f9145f
NTND
801 cat >../status.expect <<EOF &&
802 M done/two
803?? .gitignore
804?? done/five
805?? done/sub/
806?? dtwo/
807EOF
ce5c61a3 808 test_cmp ../status.expect ../status.iuc &&
73f9145f
NTND
809 test_cmp ../status.expect ../status.actual
810'
811
7c121788
CC
812test_expect_success '--no-untracked-cache removes the cache' '
813 git update-index --no-untracked-cache &&
cd780f0b 814 test-tool dump-untracked-cache >../actual &&
7c121788
CC
815 echo "no untracked cache" >../expect-no-uc &&
816 test_cmp ../expect-no-uc ../actual
817'
818
819test_expect_success 'git status does not change anything' '
820 git status &&
cd780f0b 821 test-tool dump-untracked-cache >../actual &&
7c121788
CC
822 test_cmp ../expect-no-uc ../actual
823'
824
825test_expect_success 'setting core.untrackedCache to true and using git status creates the cache' '
826 git config core.untrackedCache true &&
cd780f0b 827 test-tool dump-untracked-cache >../actual &&
7c121788
CC
828 test_cmp ../expect-no-uc ../actual &&
829 git status &&
cd780f0b 830 test-tool dump-untracked-cache >../actual &&
7c121788
CC
831 test_cmp ../expect-from-test-dump ../actual
832'
833
834test_expect_success 'using --no-untracked-cache does not fail when core.untrackedCache is true' '
835 git update-index --no-untracked-cache &&
cd780f0b 836 test-tool dump-untracked-cache >../actual &&
7c121788
CC
837 test_cmp ../expect-no-uc ../actual &&
838 git update-index --untracked-cache &&
cd780f0b 839 test-tool dump-untracked-cache >../actual &&
7c121788
CC
840 test_cmp ../expect-empty ../actual
841'
842
843test_expect_success 'setting core.untrackedCache to false and using git status removes the cache' '
844 git config core.untrackedCache false &&
cd780f0b 845 test-tool dump-untracked-cache >../actual &&
7c121788
CC
846 test_cmp ../expect-empty ../actual &&
847 git status &&
cd780f0b 848 test-tool dump-untracked-cache >../actual &&
7c121788
CC
849 test_cmp ../expect-no-uc ../actual
850'
851
852test_expect_success 'using --untracked-cache does not fail when core.untrackedCache is false' '
853 git update-index --untracked-cache &&
cd780f0b 854 test-tool dump-untracked-cache >../actual &&
7c121788
CC
855 test_cmp ../expect-empty ../actual
856'
857
858test_expect_success 'setting core.untrackedCache to keep' '
859 git config core.untrackedCache keep &&
860 git update-index --untracked-cache &&
cd780f0b 861 test-tool dump-untracked-cache >../actual &&
7c121788
CC
862 test_cmp ../expect-empty ../actual &&
863 git status &&
cd780f0b 864 test-tool dump-untracked-cache >../actual &&
7c121788
CC
865 test_cmp ../expect-from-test-dump ../actual &&
866 git update-index --no-untracked-cache &&
cd780f0b 867 test-tool dump-untracked-cache >../actual &&
7c121788
CC
868 test_cmp ../expect-no-uc ../actual &&
869 git update-index --force-untracked-cache &&
cd780f0b 870 test-tool dump-untracked-cache >../actual &&
7c121788
CC
871 test_cmp ../expect-empty ../actual &&
872 git status &&
cd780f0b 873 test-tool dump-untracked-cache >../actual &&
7c121788
CC
874 test_cmp ../expect-from-test-dump ../actual
875'
876
877test_expect_success 'test ident field is working' '
878 mkdir ../other_worktree &&
879 cp -R done dthree dtwo four three ../other_worktree &&
880 GIT_WORK_TREE=../other_worktree git status 2>../err &&
1a07e59c 881 echo "warning: untracked cache is disabled on this system or location" >../expect &&
1108cea7 882 test_cmp ../expect ../err
7c121788
CC
883'
884
edf3b905
DT
885test_expect_success 'untracked cache survives a checkout' '
886 git commit --allow-empty -m empty &&
cd780f0b 887 test-tool dump-untracked-cache >../before &&
01dc8133 888 test_when_finished "git checkout main" &&
edf3b905 889 git checkout -b other_branch &&
cd780f0b 890 test-tool dump-untracked-cache >../after &&
edf3b905
DT
891 test_cmp ../before ../after &&
892 test_commit test &&
cd780f0b 893 test-tool dump-untracked-cache >../before &&
01dc8133 894 git checkout main &&
cd780f0b 895 test-tool dump-untracked-cache >../after &&
edf3b905
DT
896 test_cmp ../before ../after
897'
898
899test_expect_success 'untracked cache survives a commit' '
cd780f0b 900 test-tool dump-untracked-cache >../before &&
edf3b905
DT
901 git add done/two &&
902 git commit -m commit &&
cd780f0b 903 test-tool dump-untracked-cache >../after &&
edf3b905
DT
904 test_cmp ../before ../after
905'
906
ce0330ca
ÆAB
907test_expect_success 'teardown worktree' '
908 cd ..
909'
910
911test_expect_success SYMLINKS 'setup worktree for symlink test' '
912 git init worktree-symlink &&
913 cd worktree-symlink &&
914 git config core.untrackedCache true &&
915 mkdir one two &&
916 touch one/file two/file &&
917 git add one/file two/file &&
918 git commit -m"first commit" &&
919 git rm -rf one &&
920 ln -s two one &&
921 git add one &&
922 git commit -m"second commit"
923'
924
b6403131 925test_expect_success SYMLINKS '"status" after symlink replacement should be clean with UC=true' '
ce0330ca
ÆAB
926 git checkout HEAD~ &&
927 status_is_clean &&
928 status_is_clean &&
01dc8133 929 git checkout main &&
ce0330ca
ÆAB
930 avoid_racy &&
931 status_is_clean &&
932 status_is_clean
933'
934
935test_expect_success SYMLINKS '"status" after symlink replacement should be clean with UC=false' '
936 git config core.untrackedCache false &&
937 git checkout HEAD~ &&
938 status_is_clean &&
939 status_is_clean &&
01dc8133 940 git checkout main &&
ce0330ca
ÆAB
941 avoid_racy &&
942 status_is_clean &&
943 status_is_clean
944'
945
946test_expect_success 'setup worktree for non-symlink test' '
947 git init worktree-non-symlink &&
948 cd worktree-non-symlink &&
949 git config core.untrackedCache true &&
950 mkdir one two &&
951 touch one/file two/file &&
952 git add one/file two/file &&
953 git commit -m"first commit" &&
954 git rm -rf one &&
955 cp two/file one &&
956 git add one &&
957 git commit -m"second commit"
958'
959
b6403131 960test_expect_success '"status" after file replacement should be clean with UC=true' '
ce0330ca
ÆAB
961 git checkout HEAD~ &&
962 status_is_clean &&
963 status_is_clean &&
01dc8133 964 git checkout main &&
ce0330ca
ÆAB
965 avoid_racy &&
966 status_is_clean &&
cd780f0b 967 test-tool dump-untracked-cache >../actual &&
ce0330ca
ÆAB
968 grep -F "recurse valid" ../actual >../actual.grep &&
969 cat >../expect.grep <<EOF &&
866be6ec 970/ $ZERO_OID recurse valid
971/two/ $ZERO_OID recurse valid
ce0330ca
ÆAB
972EOF
973 status_is_clean &&
974 test_cmp ../expect.grep ../actual.grep
975'
976
977test_expect_success '"status" after file replacement should be clean with UC=false' '
978 git config core.untrackedCache false &&
979 git checkout HEAD~ &&
980 status_is_clean &&
981 status_is_clean &&
01dc8133 982 git checkout main &&
ce0330ca
ÆAB
983 avoid_racy &&
984 status_is_clean &&
985 status_is_clean
986'
987
4447d412
988test_expect_success 'empty repo (no index) and core.untrackedCache' '
989 git init emptyrepo &&
990 git -C emptyrepo -c core.untrackedCache=true write-tree
991'
992
a3ddcefd 993test_done