]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7063-status-untracked-cache.sh
tests: don't assume a .git/info for .git/info/refs
[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
193test_expect_success 'modify in root directory, one dir invalidation' '
a3ddcefd 194 : >four &&
9ba83ebf 195 test-tool chmtime =-240 four &&
7f9dd879
EN
196 : >../trace.output &&
197 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
a3ddcefd 198 git status --porcelain >../actual &&
ce5c61a3 199 iuc status --porcelain >../status.iuc &&
a3ddcefd
NTND
200 cat >../status.expect <<EOF &&
201A done/one
202A one
203A two
204?? dthree/
205?? dtwo/
206?? four
207?? three
208EOF
ce5c61a3 209 test_cmp ../status.expect ../status.iuc &&
a3ddcefd 210 test_cmp ../status.expect ../actual &&
7f9dd879 211 get_relevant_traces ../trace.output ../trace.relevant &&
a3ddcefd 212 cat >../trace.expect <<EOF &&
7f9dd879
EN
213 ....path:
214 ....node-creation:0
215 ....gitignore-invalidation:0
216 ....directory-invalidation:1
217 ....opendir:1
a3ddcefd 218EOF
7f9dd879 219 test_cmp ../trace.expect ../trace.relevant
a3ddcefd
NTND
220
221'
222
223test_expect_success 'verify untracked cache dump' '
cd780f0b 224 test-tool dump-untracked-cache >../actual &&
a3ddcefd 225 cat >../expect <<EOF &&
378932d3 226info/exclude $EMPTY_BLOB
866be6ec 227core.excludesfile $ZERO_OID
a3ddcefd
NTND
228exclude_per_dir .gitignore
229flags 00000006
866be6ec 230/ $ZERO_OID recurse valid
a3ddcefd
NTND
231dthree/
232dtwo/
233four
234three
866be6ec 235/done/ $ZERO_OID recurse valid
236/dthree/ $ZERO_OID recurse check_only valid
a3ddcefd 237three
866be6ec 238/dtwo/ $ZERO_OID recurse check_only valid
a3ddcefd
NTND
239two
240EOF
241 test_cmp ../expect ../actual
242'
243
244test_expect_success 'new .gitignore invalidates recursively' '
a3ddcefd 245 echo four >.gitignore &&
7f9dd879
EN
246 : >../trace.output &&
247 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
a3ddcefd 248 git status --porcelain >../actual &&
ce5c61a3 249 iuc status --porcelain >../status.iuc &&
a3ddcefd
NTND
250 cat >../status.expect <<EOF &&
251A done/one
252A one
253A two
254?? .gitignore
255?? dthree/
256?? dtwo/
257?? three
258EOF
ce5c61a3 259 test_cmp ../status.expect ../status.iuc &&
a3ddcefd 260 test_cmp ../status.expect ../actual &&
7f9dd879 261 get_relevant_traces ../trace.output ../trace.relevant &&
a3ddcefd 262 cat >../trace.expect <<EOF &&
7f9dd879
EN
263 ....path:
264 ....node-creation:0
265 ....gitignore-invalidation:1
266 ....directory-invalidation:1
267 ....opendir:4
a3ddcefd 268EOF
7f9dd879 269 test_cmp ../trace.expect ../trace.relevant
a3ddcefd
NTND
270
271'
272
273test_expect_success 'verify untracked cache dump' '
cd780f0b 274 test-tool dump-untracked-cache >../actual &&
a3ddcefd 275 cat >../expect <<EOF &&
378932d3 276info/exclude $EMPTY_BLOB
866be6ec 277core.excludesfile $ZERO_OID
a3ddcefd
NTND
278exclude_per_dir .gitignore
279flags 00000006
866be6ec 280/ $(test_oid root) recurse valid
a3ddcefd
NTND
281.gitignore
282dthree/
283dtwo/
284three
866be6ec 285/done/ $ZERO_OID recurse valid
286/dthree/ $ZERO_OID recurse check_only valid
a3ddcefd 287three
866be6ec 288/dtwo/ $ZERO_OID recurse check_only valid
a3ddcefd
NTND
289two
290EOF
291 test_cmp ../expect ../actual
292'
293
294test_expect_success 'new info/exclude invalidates everything' '
a3ddcefd 295 echo three >>.git/info/exclude &&
7f9dd879
EN
296 : >../trace.output &&
297 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
a3ddcefd 298 git status --porcelain >../actual &&
ce5c61a3 299 iuc status --porcelain >../status.iuc &&
a3ddcefd
NTND
300 cat >../status.expect <<EOF &&
301A done/one
302A one
303A two
304?? .gitignore
305?? dtwo/
306EOF
ce5c61a3 307 test_cmp ../status.expect ../status.iuc &&
a3ddcefd 308 test_cmp ../status.expect ../actual &&
7f9dd879 309 get_relevant_traces ../trace.output ../trace.relevant &&
a3ddcefd 310 cat >../trace.expect <<EOF &&
7f9dd879
EN
311 ....path:
312 ....node-creation:0
313 ....gitignore-invalidation:1
314 ....directory-invalidation:0
315 ....opendir:4
a3ddcefd 316EOF
7f9dd879 317 test_cmp ../trace.expect ../trace.relevant
a3ddcefd
NTND
318'
319
320test_expect_success 'verify untracked cache dump' '
cd780f0b 321 test-tool dump-untracked-cache >../actual &&
a3ddcefd 322 cat >../expect <<EOF &&
866be6ec 323info/exclude $(test_oid exclude)
324core.excludesfile $ZERO_OID
a3ddcefd
NTND
325exclude_per_dir .gitignore
326flags 00000006
866be6ec 327/ $(test_oid root) recurse valid
a3ddcefd
NTND
328.gitignore
329dtwo/
866be6ec 330/done/ $ZERO_OID recurse valid
331/dthree/ $ZERO_OID recurse check_only valid
332/dtwo/ $ZERO_OID recurse check_only valid
a3ddcefd
NTND
333two
334EOF
335 test_cmp ../expect ../actual
336'
337
338test_expect_success 'move two from tracked to untracked' '
339 git rm --cached two &&
cd780f0b 340 test-tool dump-untracked-cache >../actual &&
a3ddcefd 341 cat >../expect <<EOF &&
866be6ec 342info/exclude $(test_oid exclude)
343core.excludesfile $ZERO_OID
a3ddcefd
NTND
344exclude_per_dir .gitignore
345flags 00000006
866be6ec 346/ $(test_oid root) recurse
347/done/ $ZERO_OID recurse valid
348/dthree/ $ZERO_OID recurse check_only valid
349/dtwo/ $ZERO_OID recurse check_only valid
a3ddcefd
NTND
350two
351EOF
352 test_cmp ../expect ../actual
353'
354
355test_expect_success 'status after the move' '
7f9dd879
EN
356 : >../trace.output &&
357 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
a3ddcefd 358 git status --porcelain >../actual &&
ce5c61a3 359 iuc status --porcelain >../status.iuc &&
a3ddcefd
NTND
360 cat >../status.expect <<EOF &&
361A done/one
362A one
363?? .gitignore
364?? dtwo/
365?? two
366EOF
ce5c61a3 367 test_cmp ../status.expect ../status.iuc &&
a3ddcefd 368 test_cmp ../status.expect ../actual &&
7f9dd879 369 get_relevant_traces ../trace.output ../trace.relevant &&
a3ddcefd 370 cat >../trace.expect <<EOF &&
7f9dd879
EN
371 ....path:
372 ....node-creation:0
373 ....gitignore-invalidation:0
374 ....directory-invalidation:0
375 ....opendir:1
a3ddcefd 376EOF
7f9dd879 377 test_cmp ../trace.expect ../trace.relevant
a3ddcefd
NTND
378'
379
380test_expect_success 'verify untracked cache dump' '
cd780f0b 381 test-tool dump-untracked-cache >../actual &&
a3ddcefd 382 cat >../expect <<EOF &&
866be6ec 383info/exclude $(test_oid exclude)
384core.excludesfile $ZERO_OID
a3ddcefd
NTND
385exclude_per_dir .gitignore
386flags 00000006
866be6ec 387/ $(test_oid root) recurse valid
a3ddcefd
NTND
388.gitignore
389dtwo/
390two
866be6ec 391/done/ $ZERO_OID recurse valid
392/dthree/ $ZERO_OID recurse check_only valid
393/dtwo/ $ZERO_OID recurse check_only valid
a3ddcefd
NTND
394two
395EOF
396 test_cmp ../expect ../actual
397'
398
399test_expect_success 'move two from untracked to tracked' '
400 git add two &&
cd780f0b 401 test-tool dump-untracked-cache >../actual &&
a3ddcefd 402 cat >../expect <<EOF &&
866be6ec 403info/exclude $(test_oid exclude)
404core.excludesfile $ZERO_OID
a3ddcefd
NTND
405exclude_per_dir .gitignore
406flags 00000006
866be6ec 407/ $(test_oid root) recurse
408/done/ $ZERO_OID recurse valid
409/dthree/ $ZERO_OID recurse check_only valid
410/dtwo/ $ZERO_OID recurse check_only valid
a3ddcefd
NTND
411two
412EOF
413 test_cmp ../expect ../actual
414'
415
416test_expect_success 'status after the move' '
7f9dd879
EN
417 : >../trace.output &&
418 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
a3ddcefd 419 git status --porcelain >../actual &&
ce5c61a3 420 iuc status --porcelain >../status.iuc &&
a3ddcefd
NTND
421 cat >../status.expect <<EOF &&
422A done/one
423A one
424A two
425?? .gitignore
426?? dtwo/
427EOF
ce5c61a3 428 test_cmp ../status.expect ../status.iuc &&
a3ddcefd 429 test_cmp ../status.expect ../actual &&
7f9dd879 430 get_relevant_traces ../trace.output ../trace.relevant &&
a3ddcefd 431 cat >../trace.expect <<EOF &&
7f9dd879
EN
432 ....path:
433 ....node-creation:0
434 ....gitignore-invalidation:0
435 ....directory-invalidation:0
436 ....opendir:1
a3ddcefd 437EOF
7f9dd879 438 test_cmp ../trace.expect ../trace.relevant
a3ddcefd
NTND
439'
440
441test_expect_success 'verify untracked cache dump' '
cd780f0b 442 test-tool dump-untracked-cache >../actual &&
a3ddcefd 443 cat >../expect <<EOF &&
866be6ec 444info/exclude $(test_oid exclude)
445core.excludesfile $ZERO_OID
a3ddcefd
NTND
446exclude_per_dir .gitignore
447flags 00000006
866be6ec 448/ $(test_oid root) recurse valid
a3ddcefd
NTND
449.gitignore
450dtwo/
866be6ec 451/done/ $ZERO_OID recurse valid
452/dthree/ $ZERO_OID recurse check_only valid
453/dtwo/ $ZERO_OID recurse check_only valid
a3ddcefd
NTND
454two
455EOF
456 test_cmp ../expect ../actual
457'
458
7687252f
DT
459test_expect_success 'set up for sparse checkout testing' '
460 echo two >done/.gitignore &&
461 echo three >>done/.gitignore &&
462 echo two >done/two &&
463 git add -f done/two done/.gitignore &&
464 git commit -m "first commit"
465'
466
467test_expect_success 'status after commit' '
7f9dd879
EN
468 : >../trace.output &&
469 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
7687252f 470 git status --porcelain >../actual &&
ce5c61a3 471 iuc status --porcelain >../status.iuc &&
7687252f
DT
472 cat >../status.expect <<EOF &&
473?? .gitignore
474?? dtwo/
475EOF
ce5c61a3 476 test_cmp ../status.expect ../status.iuc &&
7687252f 477 test_cmp ../status.expect ../actual &&
7f9dd879 478 get_relevant_traces ../trace.output ../trace.relevant &&
7687252f 479 cat >../trace.expect <<EOF &&
7f9dd879
EN
480 ....path:
481 ....node-creation:0
482 ....gitignore-invalidation:0
483 ....directory-invalidation:0
484 ....opendir:2
7687252f 485EOF
7f9dd879 486 test_cmp ../trace.expect ../trace.relevant
7687252f
DT
487'
488
489test_expect_success 'untracked cache correct after commit' '
cd780f0b 490 test-tool dump-untracked-cache >../actual &&
7687252f 491 cat >../expect <<EOF &&
866be6ec 492info/exclude $(test_oid exclude)
493core.excludesfile $ZERO_OID
7687252f
DT
494exclude_per_dir .gitignore
495flags 00000006
866be6ec 496/ $(test_oid root) recurse valid
7687252f
DT
497.gitignore
498dtwo/
866be6ec 499/done/ $ZERO_OID recurse valid
500/dthree/ $ZERO_OID recurse check_only valid
501/dtwo/ $ZERO_OID recurse check_only valid
7687252f
DT
502two
503EOF
504 test_cmp ../expect ../actual
505'
506
507test_expect_success 'set up sparse checkout' '
508 echo "done/[a-z]*" >.git/info/sparse-checkout &&
509 test_config core.sparsecheckout true &&
01dc8133 510 git checkout main &&
f178136e 511 git update-index --force-untracked-cache &&
7687252f
DT
512 git status --porcelain >/dev/null && # prime the cache
513 test_path_is_missing done/.gitignore &&
514 test_path_is_file done/one
515'
516
2e5910f2
DT
517test_expect_success 'create/modify files, some of which are gitignored' '
518 echo two bis >done/two &&
7687252f
DT
519 echo three >done/three && # three is gitignored
520 echo four >done/four && # four is gitignored at a higher level
9b680fbd 521 echo five >done/five && # five is not gitignored
9ba83ebf
TK
522 test-tool chmtime =-180 done/two done/three done/four done/five done &&
523 # we need to ensure that the root dir is touched (in the past);
524 test-tool chmtime =-180 . &&
6b7728db 525 sync_mtime
7687252f
DT
526'
527
528test_expect_success 'test sparse status with untracked cache' '
7f9dd879 529 : >../trace.output &&
7f9dd879 530 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
7687252f 531 git status --porcelain >../status.actual &&
ce5c61a3 532 iuc status --porcelain >../status.iuc &&
7687252f 533 cat >../status.expect <<EOF &&
2e5910f2 534 M done/two
7687252f
DT
535?? .gitignore
536?? done/five
537?? dtwo/
538EOF
ce5c61a3 539 test_cmp ../status.expect ../status.iuc &&
7687252f 540 test_cmp ../status.expect ../status.actual &&
7f9dd879 541 get_relevant_traces ../trace.output ../trace.relevant &&
7687252f 542 cat >../trace.expect <<EOF &&
7f9dd879
EN
543 ....path:
544 ....node-creation:0
545 ....gitignore-invalidation:1
546 ....directory-invalidation:2
547 ....opendir:2
7687252f 548EOF
7f9dd879 549 test_cmp ../trace.expect ../trace.relevant
7687252f
DT
550'
551
552test_expect_success 'untracked cache correct after status' '
cd780f0b 553 test-tool dump-untracked-cache >../actual &&
7687252f 554 cat >../expect <<EOF &&
866be6ec 555info/exclude $(test_oid exclude)
556core.excludesfile $ZERO_OID
7687252f
DT
557exclude_per_dir .gitignore
558flags 00000006
866be6ec 559/ $(test_oid root) recurse valid
7687252f
DT
560.gitignore
561dtwo/
866be6ec 562/done/ $(test_oid done) recurse valid
7687252f 563five
866be6ec 564/dthree/ $ZERO_OID recurse check_only valid
565/dtwo/ $ZERO_OID recurse check_only valid
7687252f
DT
566two
567EOF
568 test_cmp ../expect ../actual
569'
570
571test_expect_success 'test sparse status again with untracked cache' '
7f9dd879
EN
572 : >../trace.output &&
573 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
7687252f 574 git status --porcelain >../status.actual &&
ce5c61a3 575 iuc status --porcelain >../status.iuc &&
7687252f 576 cat >../status.expect <<EOF &&
2e5910f2 577 M done/two
7687252f
DT
578?? .gitignore
579?? done/five
580?? dtwo/
581EOF
ce5c61a3 582 test_cmp ../status.expect ../status.iuc &&
7687252f 583 test_cmp ../status.expect ../status.actual &&
7f9dd879 584 get_relevant_traces ../trace.output ../trace.relevant &&
7687252f 585 cat >../trace.expect <<EOF &&
7f9dd879
EN
586 ....path:
587 ....node-creation:0
588 ....gitignore-invalidation:0
589 ....directory-invalidation:0
590 ....opendir:0
7687252f 591EOF
7f9dd879 592 test_cmp ../trace.expect ../trace.relevant
7687252f
DT
593'
594
2e5910f2
DT
595test_expect_success 'set up for test of subdir and sparse checkouts' '
596 mkdir done/sub &&
597 mkdir done/sub/sub &&
9ba83ebf
TK
598 echo "sub" > done/sub/sub/file &&
599 test-tool chmtime =-120 done/sub/sub/file done/sub/sub done/sub done
2e5910f2
DT
600'
601
602test_expect_success 'test sparse status with untracked cache and subdir' '
7f9dd879
EN
603 : >../trace.output &&
604 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
2e5910f2 605 git status --porcelain >../status.actual &&
ce5c61a3 606 iuc status --porcelain >../status.iuc &&
2e5910f2
DT
607 cat >../status.expect <<EOF &&
608 M done/two
609?? .gitignore
610?? done/five
611?? done/sub/
612?? dtwo/
613EOF
ce5c61a3 614 test_cmp ../status.expect ../status.iuc &&
2e5910f2 615 test_cmp ../status.expect ../status.actual &&
7f9dd879 616 get_relevant_traces ../trace.output ../trace.relevant &&
2e5910f2 617 cat >../trace.expect <<EOF &&
7f9dd879
EN
618 ....path:
619 ....node-creation:2
620 ....gitignore-invalidation:0
621 ....directory-invalidation:1
622 ....opendir:3
2e5910f2 623EOF
7f9dd879 624 test_cmp ../trace.expect ../trace.relevant
2e5910f2
DT
625'
626
627test_expect_success 'verify untracked cache dump (sparse/subdirs)' '
cd780f0b 628 test-tool dump-untracked-cache >../actual &&
7c121788 629 cat >../expect-from-test-dump <<EOF &&
866be6ec 630info/exclude $(test_oid exclude)
631core.excludesfile $ZERO_OID
2e5910f2
DT
632exclude_per_dir .gitignore
633flags 00000006
866be6ec 634/ $(test_oid root) recurse valid
2e5910f2
DT
635.gitignore
636dtwo/
866be6ec 637/done/ $(test_oid done) recurse valid
2e5910f2
DT
638five
639sub/
866be6ec 640/done/sub/ $ZERO_OID recurse check_only valid
2e5910f2 641sub/
866be6ec 642/done/sub/sub/ $ZERO_OID recurse check_only valid
2e5910f2 643file
866be6ec 644/dthree/ $ZERO_OID recurse check_only valid
645/dtwo/ $ZERO_OID recurse check_only valid
2e5910f2
DT
646two
647EOF
7c121788 648 test_cmp ../expect-from-test-dump ../actual
2e5910f2
DT
649'
650
651test_expect_success 'test sparse status again with untracked cache and subdir' '
7f9dd879
EN
652 : >../trace.output &&
653 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
2e5910f2 654 git status --porcelain >../status.actual &&
ce5c61a3
EN
655 iuc status --porcelain >../status.iuc &&
656 test_cmp ../status.expect ../status.iuc &&
2e5910f2 657 test_cmp ../status.expect ../status.actual &&
7f9dd879 658 get_relevant_traces ../trace.output ../trace.relevant &&
2e5910f2 659 cat >../trace.expect <<EOF &&
7f9dd879
EN
660 ....path:
661 ....node-creation:0
662 ....gitignore-invalidation:0
663 ....directory-invalidation:0
664 ....opendir:0
2e5910f2 665EOF
7f9dd879 666 test_cmp ../trace.expect ../trace.relevant
2e5910f2
DT
667'
668
73f9145f
NTND
669test_expect_success 'move entry in subdir from untracked to cached' '
670 git add dtwo/two &&
671 git status --porcelain >../status.actual &&
ce5c61a3 672 iuc status --porcelain >../status.iuc &&
73f9145f
NTND
673 cat >../status.expect <<EOF &&
674 M done/two
675A dtwo/two
676?? .gitignore
677?? done/five
678?? done/sub/
679EOF
ce5c61a3 680 test_cmp ../status.expect ../status.iuc &&
73f9145f
NTND
681 test_cmp ../status.expect ../status.actual
682'
683
684test_expect_success 'move entry in subdir from cached to untracked' '
685 git rm --cached dtwo/two &&
686 git status --porcelain >../status.actual &&
ce5c61a3 687 iuc status --porcelain >../status.iuc &&
73f9145f
NTND
688 cat >../status.expect <<EOF &&
689 M done/two
690?? .gitignore
691?? done/five
692?? done/sub/
693?? dtwo/
694EOF
ce5c61a3 695 test_cmp ../status.expect ../status.iuc &&
73f9145f
NTND
696 test_cmp ../status.expect ../status.actual
697'
698
7c121788
CC
699test_expect_success '--no-untracked-cache removes the cache' '
700 git update-index --no-untracked-cache &&
cd780f0b 701 test-tool dump-untracked-cache >../actual &&
7c121788
CC
702 echo "no untracked cache" >../expect-no-uc &&
703 test_cmp ../expect-no-uc ../actual
704'
705
706test_expect_success 'git status does not change anything' '
707 git status &&
cd780f0b 708 test-tool dump-untracked-cache >../actual &&
7c121788
CC
709 test_cmp ../expect-no-uc ../actual
710'
711
712test_expect_success 'setting core.untrackedCache to true and using git status creates the cache' '
713 git config core.untrackedCache true &&
cd780f0b 714 test-tool dump-untracked-cache >../actual &&
7c121788
CC
715 test_cmp ../expect-no-uc ../actual &&
716 git status &&
cd780f0b 717 test-tool dump-untracked-cache >../actual &&
7c121788
CC
718 test_cmp ../expect-from-test-dump ../actual
719'
720
721test_expect_success 'using --no-untracked-cache does not fail when core.untrackedCache is true' '
722 git update-index --no-untracked-cache &&
cd780f0b 723 test-tool dump-untracked-cache >../actual &&
7c121788
CC
724 test_cmp ../expect-no-uc ../actual &&
725 git update-index --untracked-cache &&
cd780f0b 726 test-tool dump-untracked-cache >../actual &&
7c121788
CC
727 test_cmp ../expect-empty ../actual
728'
729
730test_expect_success 'setting core.untrackedCache to false and using git status removes the cache' '
731 git config core.untrackedCache false &&
cd780f0b 732 test-tool dump-untracked-cache >../actual &&
7c121788
CC
733 test_cmp ../expect-empty ../actual &&
734 git status &&
cd780f0b 735 test-tool dump-untracked-cache >../actual &&
7c121788
CC
736 test_cmp ../expect-no-uc ../actual
737'
738
739test_expect_success 'using --untracked-cache does not fail when core.untrackedCache is false' '
740 git update-index --untracked-cache &&
cd780f0b 741 test-tool dump-untracked-cache >../actual &&
7c121788
CC
742 test_cmp ../expect-empty ../actual
743'
744
745test_expect_success 'setting core.untrackedCache to keep' '
746 git config core.untrackedCache keep &&
747 git update-index --untracked-cache &&
cd780f0b 748 test-tool dump-untracked-cache >../actual &&
7c121788
CC
749 test_cmp ../expect-empty ../actual &&
750 git status &&
cd780f0b 751 test-tool dump-untracked-cache >../actual &&
7c121788
CC
752 test_cmp ../expect-from-test-dump ../actual &&
753 git update-index --no-untracked-cache &&
cd780f0b 754 test-tool dump-untracked-cache >../actual &&
7c121788
CC
755 test_cmp ../expect-no-uc ../actual &&
756 git update-index --force-untracked-cache &&
cd780f0b 757 test-tool dump-untracked-cache >../actual &&
7c121788
CC
758 test_cmp ../expect-empty ../actual &&
759 git status &&
cd780f0b 760 test-tool dump-untracked-cache >../actual &&
7c121788
CC
761 test_cmp ../expect-from-test-dump ../actual
762'
763
764test_expect_success 'test ident field is working' '
765 mkdir ../other_worktree &&
766 cp -R done dthree dtwo four three ../other_worktree &&
767 GIT_WORK_TREE=../other_worktree git status 2>../err &&
1a07e59c 768 echo "warning: untracked cache is disabled on this system or location" >../expect &&
1108cea7 769 test_cmp ../expect ../err
7c121788
CC
770'
771
edf3b905
DT
772test_expect_success 'untracked cache survives a checkout' '
773 git commit --allow-empty -m empty &&
cd780f0b 774 test-tool dump-untracked-cache >../before &&
01dc8133 775 test_when_finished "git checkout main" &&
edf3b905 776 git checkout -b other_branch &&
cd780f0b 777 test-tool dump-untracked-cache >../after &&
edf3b905
DT
778 test_cmp ../before ../after &&
779 test_commit test &&
cd780f0b 780 test-tool dump-untracked-cache >../before &&
01dc8133 781 git checkout main &&
cd780f0b 782 test-tool dump-untracked-cache >../after &&
edf3b905
DT
783 test_cmp ../before ../after
784'
785
786test_expect_success 'untracked cache survives a commit' '
cd780f0b 787 test-tool dump-untracked-cache >../before &&
edf3b905
DT
788 git add done/two &&
789 git commit -m commit &&
cd780f0b 790 test-tool dump-untracked-cache >../after &&
edf3b905
DT
791 test_cmp ../before ../after
792'
793
ce0330ca
ÆAB
794test_expect_success 'teardown worktree' '
795 cd ..
796'
797
798test_expect_success SYMLINKS 'setup worktree for symlink test' '
799 git init worktree-symlink &&
800 cd worktree-symlink &&
801 git config core.untrackedCache true &&
802 mkdir one two &&
803 touch one/file two/file &&
804 git add one/file two/file &&
805 git commit -m"first commit" &&
806 git rm -rf one &&
807 ln -s two one &&
808 git add one &&
809 git commit -m"second commit"
810'
811
b6403131 812test_expect_success SYMLINKS '"status" after symlink replacement should be clean with UC=true' '
ce0330ca
ÆAB
813 git checkout HEAD~ &&
814 status_is_clean &&
815 status_is_clean &&
01dc8133 816 git checkout main &&
ce0330ca
ÆAB
817 avoid_racy &&
818 status_is_clean &&
819 status_is_clean
820'
821
822test_expect_success SYMLINKS '"status" after symlink replacement should be clean with UC=false' '
823 git config core.untrackedCache false &&
824 git checkout HEAD~ &&
825 status_is_clean &&
826 status_is_clean &&
01dc8133 827 git checkout main &&
ce0330ca
ÆAB
828 avoid_racy &&
829 status_is_clean &&
830 status_is_clean
831'
832
833test_expect_success 'setup worktree for non-symlink test' '
834 git init worktree-non-symlink &&
835 cd worktree-non-symlink &&
836 git config core.untrackedCache true &&
837 mkdir one two &&
838 touch one/file two/file &&
839 git add one/file two/file &&
840 git commit -m"first commit" &&
841 git rm -rf one &&
842 cp two/file one &&
843 git add one &&
844 git commit -m"second commit"
845'
846
b6403131 847test_expect_success '"status" after file replacement should be clean with UC=true' '
ce0330ca
ÆAB
848 git checkout HEAD~ &&
849 status_is_clean &&
850 status_is_clean &&
01dc8133 851 git checkout main &&
ce0330ca
ÆAB
852 avoid_racy &&
853 status_is_clean &&
cd780f0b 854 test-tool dump-untracked-cache >../actual &&
ce0330ca
ÆAB
855 grep -F "recurse valid" ../actual >../actual.grep &&
856 cat >../expect.grep <<EOF &&
866be6ec 857/ $ZERO_OID recurse valid
858/two/ $ZERO_OID recurse valid
ce0330ca
ÆAB
859EOF
860 status_is_clean &&
861 test_cmp ../expect.grep ../actual.grep
862'
863
864test_expect_success '"status" after file replacement should be clean with UC=false' '
865 git config core.untrackedCache false &&
866 git checkout HEAD~ &&
867 status_is_clean &&
868 status_is_clean &&
01dc8133 869 git checkout main &&
ce0330ca
ÆAB
870 avoid_racy &&
871 status_is_clean &&
872 status_is_clean
873'
874
a3ddcefd 875test_done