]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7063-status-untracked-cache.sh
Merge branch 'ab/detox-gettext-tests'
[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
fa73a582 60test_lazy_prereq UNTRACKED_CACHE '
435ec090 61 { git update-index --test-untracked-cache; ret=$?; } &&
fa73a582
JK
62 test $ret -ne 1
63'
64
65if ! test_have_prereq UNTRACKED_CACHE; then
a3ddcefd
NTND
66 skip_all='This system does not support untracked cache'
67 test_done
68fi
69
7c121788
CC
70test_expect_success 'core.untrackedCache is unset' '
71 test_must_fail git config --get core.untrackedCache
72'
73
a3ddcefd
NTND
74test_expect_success 'setup' '
75 git init worktree &&
76 cd worktree &&
77 mkdir done dtwo dthree &&
78 touch one two three done/one dtwo/two dthree/three &&
79 git add one two done/one &&
80 : >.git/info/exclude &&
866be6ec 81 git update-index --untracked-cache &&
82 test_oid_cache <<-EOF
83 root sha1:e6fcc8f2ee31bae321d66afd183fcb7237afae6e
84 root sha256:b90c672088c015b9c83876e919da311bad4cd39639fb139f988af6a11493b974
85
86 exclude sha1:13263c0978fb9fad16b2d580fb800b6d811c3ff0
87 exclude sha256:fe4aaa1bbbbce4cb8f73426748a14c5ad6026b26f90505a0bf2494b165a5b76c
88
89 done sha1:1946f0437f90c5005533cbe1736a6451ca301714
90 done sha256:7f079501d79f665b3acc50f5e0e9e94509084d5032ac20113a37dd5029b757cc
91 EOF
a3ddcefd
NTND
92'
93
94test_expect_success 'untracked cache is empty' '
cd780f0b 95 test-tool dump-untracked-cache >../actual &&
7c121788 96 cat >../expect-empty <<EOF &&
866be6ec 97info/exclude $ZERO_OID
98core.excludesfile $ZERO_OID
a3ddcefd
NTND
99exclude_per_dir .gitignore
100flags 00000006
101EOF
7c121788 102 test_cmp ../expect-empty ../actual
a3ddcefd
NTND
103'
104
105cat >../status.expect <<EOF &&
106A done/one
107A one
108A two
109?? dthree/
110?? dtwo/
111?? three
112EOF
113
114cat >../dump.expect <<EOF &&
378932d3 115info/exclude $EMPTY_BLOB
866be6ec 116core.excludesfile $ZERO_OID
a3ddcefd
NTND
117exclude_per_dir .gitignore
118flags 00000006
866be6ec 119/ $ZERO_OID recurse valid
a3ddcefd
NTND
120dthree/
121dtwo/
122three
866be6ec 123/done/ $ZERO_OID recurse valid
124/dthree/ $ZERO_OID recurse check_only valid
a3ddcefd 125three
866be6ec 126/dtwo/ $ZERO_OID recurse check_only valid
a3ddcefd
NTND
127two
128EOF
129
130test_expect_success 'status first time (empty cache)' '
131 avoid_racy &&
132 : >../trace &&
133 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
134 git status --porcelain >../actual &&
ce5c61a3
EN
135 iuc status --porcelain >../status.iuc &&
136 test_cmp ../status.expect ../status.iuc &&
a3ddcefd
NTND
137 test_cmp ../status.expect ../actual &&
138 cat >../trace.expect <<EOF &&
139node creation: 3
140gitignore invalidation: 1
141directory invalidation: 0
142opendir: 4
143EOF
144 test_cmp ../trace.expect ../trace
145'
146
147test_expect_success 'untracked cache after first status' '
cd780f0b 148 test-tool dump-untracked-cache >../actual &&
a3ddcefd
NTND
149 test_cmp ../dump.expect ../actual
150'
151
152test_expect_success 'status second time (fully populated cache)' '
153 avoid_racy &&
154 : >../trace &&
155 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
156 git status --porcelain >../actual &&
ce5c61a3
EN
157 iuc status --porcelain >../status.iuc &&
158 test_cmp ../status.expect ../status.iuc &&
a3ddcefd
NTND
159 test_cmp ../status.expect ../actual &&
160 cat >../trace.expect <<EOF &&
161node creation: 0
162gitignore invalidation: 0
163directory invalidation: 0
164opendir: 0
165EOF
166 test_cmp ../trace.expect ../trace
167'
168
169test_expect_success 'untracked cache after second status' '
cd780f0b 170 test-tool dump-untracked-cache >../actual &&
a3ddcefd
NTND
171 test_cmp ../dump.expect ../actual
172'
173
174test_expect_success 'modify in root directory, one dir invalidation' '
175 avoid_racy &&
176 : >four &&
177 : >../trace &&
178 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
179 git status --porcelain >../actual &&
ce5c61a3 180 iuc status --porcelain >../status.iuc &&
a3ddcefd
NTND
181 cat >../status.expect <<EOF &&
182A done/one
183A one
184A two
185?? dthree/
186?? dtwo/
187?? four
188?? three
189EOF
ce5c61a3 190 test_cmp ../status.expect ../status.iuc &&
a3ddcefd
NTND
191 test_cmp ../status.expect ../actual &&
192 cat >../trace.expect <<EOF &&
193node creation: 0
194gitignore invalidation: 0
195directory invalidation: 1
196opendir: 1
197EOF
198 test_cmp ../trace.expect ../trace
199
200'
201
202test_expect_success 'verify untracked cache dump' '
cd780f0b 203 test-tool dump-untracked-cache >../actual &&
a3ddcefd 204 cat >../expect <<EOF &&
378932d3 205info/exclude $EMPTY_BLOB
866be6ec 206core.excludesfile $ZERO_OID
a3ddcefd
NTND
207exclude_per_dir .gitignore
208flags 00000006
866be6ec 209/ $ZERO_OID recurse valid
a3ddcefd
NTND
210dthree/
211dtwo/
212four
213three
866be6ec 214/done/ $ZERO_OID recurse valid
215/dthree/ $ZERO_OID recurse check_only valid
a3ddcefd 216three
866be6ec 217/dtwo/ $ZERO_OID recurse check_only valid
a3ddcefd
NTND
218two
219EOF
220 test_cmp ../expect ../actual
221'
222
223test_expect_success 'new .gitignore invalidates recursively' '
224 avoid_racy &&
225 echo four >.gitignore &&
226 : >../trace &&
227 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
228 git status --porcelain >../actual &&
ce5c61a3 229 iuc status --porcelain >../status.iuc &&
a3ddcefd
NTND
230 cat >../status.expect <<EOF &&
231A done/one
232A one
233A two
234?? .gitignore
235?? dthree/
236?? dtwo/
237?? three
238EOF
ce5c61a3 239 test_cmp ../status.expect ../status.iuc &&
a3ddcefd
NTND
240 test_cmp ../status.expect ../actual &&
241 cat >../trace.expect <<EOF &&
242node creation: 0
243gitignore invalidation: 1
244directory invalidation: 1
245opendir: 4
246EOF
247 test_cmp ../trace.expect ../trace
248
249'
250
251test_expect_success 'verify untracked cache dump' '
cd780f0b 252 test-tool dump-untracked-cache >../actual &&
a3ddcefd 253 cat >../expect <<EOF &&
378932d3 254info/exclude $EMPTY_BLOB
866be6ec 255core.excludesfile $ZERO_OID
a3ddcefd
NTND
256exclude_per_dir .gitignore
257flags 00000006
866be6ec 258/ $(test_oid root) recurse valid
a3ddcefd
NTND
259.gitignore
260dthree/
261dtwo/
262three
866be6ec 263/done/ $ZERO_OID recurse valid
264/dthree/ $ZERO_OID recurse check_only valid
a3ddcefd 265three
866be6ec 266/dtwo/ $ZERO_OID recurse check_only valid
a3ddcefd
NTND
267two
268EOF
269 test_cmp ../expect ../actual
270'
271
272test_expect_success 'new info/exclude invalidates everything' '
273 avoid_racy &&
274 echo three >>.git/info/exclude &&
275 : >../trace &&
276 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
277 git status --porcelain >../actual &&
ce5c61a3 278 iuc status --porcelain >../status.iuc &&
a3ddcefd
NTND
279 cat >../status.expect <<EOF &&
280A done/one
281A one
282A two
283?? .gitignore
284?? dtwo/
285EOF
ce5c61a3 286 test_cmp ../status.expect ../status.iuc &&
a3ddcefd
NTND
287 test_cmp ../status.expect ../actual &&
288 cat >../trace.expect <<EOF &&
289node creation: 0
290gitignore invalidation: 1
291directory invalidation: 0
292opendir: 4
293EOF
294 test_cmp ../trace.expect ../trace
295'
296
297test_expect_success 'verify untracked cache dump' '
cd780f0b 298 test-tool dump-untracked-cache >../actual &&
a3ddcefd 299 cat >../expect <<EOF &&
866be6ec 300info/exclude $(test_oid exclude)
301core.excludesfile $ZERO_OID
a3ddcefd
NTND
302exclude_per_dir .gitignore
303flags 00000006
866be6ec 304/ $(test_oid root) recurse valid
a3ddcefd
NTND
305.gitignore
306dtwo/
866be6ec 307/done/ $ZERO_OID recurse valid
308/dthree/ $ZERO_OID recurse check_only valid
309/dtwo/ $ZERO_OID recurse check_only valid
a3ddcefd
NTND
310two
311EOF
312 test_cmp ../expect ../actual
313'
314
315test_expect_success 'move two from tracked to untracked' '
316 git rm --cached two &&
cd780f0b 317 test-tool dump-untracked-cache >../actual &&
a3ddcefd 318 cat >../expect <<EOF &&
866be6ec 319info/exclude $(test_oid exclude)
320core.excludesfile $ZERO_OID
a3ddcefd
NTND
321exclude_per_dir .gitignore
322flags 00000006
866be6ec 323/ $(test_oid root) recurse
324/done/ $ZERO_OID recurse valid
325/dthree/ $ZERO_OID recurse check_only valid
326/dtwo/ $ZERO_OID recurse check_only valid
a3ddcefd
NTND
327two
328EOF
329 test_cmp ../expect ../actual
330'
331
332test_expect_success 'status after the move' '
333 : >../trace &&
334 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
335 git status --porcelain >../actual &&
ce5c61a3 336 iuc status --porcelain >../status.iuc &&
a3ddcefd
NTND
337 cat >../status.expect <<EOF &&
338A done/one
339A one
340?? .gitignore
341?? dtwo/
342?? two
343EOF
ce5c61a3 344 test_cmp ../status.expect ../status.iuc &&
a3ddcefd
NTND
345 test_cmp ../status.expect ../actual &&
346 cat >../trace.expect <<EOF &&
347node creation: 0
348gitignore invalidation: 0
349directory invalidation: 0
350opendir: 1
351EOF
352 test_cmp ../trace.expect ../trace
353'
354
355test_expect_success 'verify untracked cache dump' '
cd780f0b 356 test-tool dump-untracked-cache >../actual &&
a3ddcefd 357 cat >../expect <<EOF &&
866be6ec 358info/exclude $(test_oid exclude)
359core.excludesfile $ZERO_OID
a3ddcefd
NTND
360exclude_per_dir .gitignore
361flags 00000006
866be6ec 362/ $(test_oid root) recurse valid
a3ddcefd
NTND
363.gitignore
364dtwo/
365two
866be6ec 366/done/ $ZERO_OID recurse valid
367/dthree/ $ZERO_OID recurse check_only valid
368/dtwo/ $ZERO_OID recurse check_only valid
a3ddcefd
NTND
369two
370EOF
371 test_cmp ../expect ../actual
372'
373
374test_expect_success 'move two from untracked to tracked' '
375 git add two &&
cd780f0b 376 test-tool dump-untracked-cache >../actual &&
a3ddcefd 377 cat >../expect <<EOF &&
866be6ec 378info/exclude $(test_oid exclude)
379core.excludesfile $ZERO_OID
a3ddcefd
NTND
380exclude_per_dir .gitignore
381flags 00000006
866be6ec 382/ $(test_oid root) recurse
383/done/ $ZERO_OID recurse valid
384/dthree/ $ZERO_OID recurse check_only valid
385/dtwo/ $ZERO_OID recurse check_only valid
a3ddcefd
NTND
386two
387EOF
388 test_cmp ../expect ../actual
389'
390
391test_expect_success 'status after the move' '
392 : >../trace &&
393 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
394 git status --porcelain >../actual &&
ce5c61a3 395 iuc status --porcelain >../status.iuc &&
a3ddcefd
NTND
396 cat >../status.expect <<EOF &&
397A done/one
398A one
399A two
400?? .gitignore
401?? dtwo/
402EOF
ce5c61a3 403 test_cmp ../status.expect ../status.iuc &&
a3ddcefd
NTND
404 test_cmp ../status.expect ../actual &&
405 cat >../trace.expect <<EOF &&
406node creation: 0
407gitignore invalidation: 0
408directory invalidation: 0
409opendir: 1
410EOF
411 test_cmp ../trace.expect ../trace
412'
413
414test_expect_success 'verify untracked cache dump' '
cd780f0b 415 test-tool dump-untracked-cache >../actual &&
a3ddcefd 416 cat >../expect <<EOF &&
866be6ec 417info/exclude $(test_oid exclude)
418core.excludesfile $ZERO_OID
a3ddcefd
NTND
419exclude_per_dir .gitignore
420flags 00000006
866be6ec 421/ $(test_oid root) recurse valid
a3ddcefd
NTND
422.gitignore
423dtwo/
866be6ec 424/done/ $ZERO_OID recurse valid
425/dthree/ $ZERO_OID recurse check_only valid
426/dtwo/ $ZERO_OID recurse check_only valid
a3ddcefd
NTND
427two
428EOF
429 test_cmp ../expect ../actual
430'
431
7687252f
DT
432test_expect_success 'set up for sparse checkout testing' '
433 echo two >done/.gitignore &&
434 echo three >>done/.gitignore &&
435 echo two >done/two &&
436 git add -f done/two done/.gitignore &&
437 git commit -m "first commit"
438'
439
440test_expect_success 'status after commit' '
441 : >../trace &&
442 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
443 git status --porcelain >../actual &&
ce5c61a3 444 iuc status --porcelain >../status.iuc &&
7687252f
DT
445 cat >../status.expect <<EOF &&
446?? .gitignore
447?? dtwo/
448EOF
ce5c61a3 449 test_cmp ../status.expect ../status.iuc &&
7687252f
DT
450 test_cmp ../status.expect ../actual &&
451 cat >../trace.expect <<EOF &&
452node creation: 0
453gitignore invalidation: 0
454directory invalidation: 0
73f9145f 455opendir: 2
7687252f
DT
456EOF
457 test_cmp ../trace.expect ../trace
458'
459
460test_expect_success 'untracked cache correct after commit' '
cd780f0b 461 test-tool dump-untracked-cache >../actual &&
7687252f 462 cat >../expect <<EOF &&
866be6ec 463info/exclude $(test_oid exclude)
464core.excludesfile $ZERO_OID
7687252f
DT
465exclude_per_dir .gitignore
466flags 00000006
866be6ec 467/ $(test_oid root) recurse valid
7687252f
DT
468.gitignore
469dtwo/
866be6ec 470/done/ $ZERO_OID recurse valid
471/dthree/ $ZERO_OID recurse check_only valid
472/dtwo/ $ZERO_OID recurse check_only valid
7687252f
DT
473two
474EOF
475 test_cmp ../expect ../actual
476'
477
478test_expect_success 'set up sparse checkout' '
479 echo "done/[a-z]*" >.git/info/sparse-checkout &&
480 test_config core.sparsecheckout true &&
01dc8133 481 git checkout main &&
f178136e 482 git update-index --force-untracked-cache &&
7687252f
DT
483 git status --porcelain >/dev/null && # prime the cache
484 test_path_is_missing done/.gitignore &&
485 test_path_is_file done/one
486'
487
2e5910f2
DT
488test_expect_success 'create/modify files, some of which are gitignored' '
489 echo two bis >done/two &&
7687252f
DT
490 echo three >done/three && # three is gitignored
491 echo four >done/four && # four is gitignored at a higher level
9b680fbd
DT
492 echo five >done/five && # five is not gitignored
493 echo test >base && #we need to ensure that the root dir is touched
6b7728db
NTND
494 rm base &&
495 sync_mtime
7687252f
DT
496'
497
498test_expect_success 'test sparse status with untracked cache' '
499 : >../trace &&
500 avoid_racy &&
501 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
502 git status --porcelain >../status.actual &&
ce5c61a3 503 iuc status --porcelain >../status.iuc &&
7687252f 504 cat >../status.expect <<EOF &&
2e5910f2 505 M done/two
7687252f
DT
506?? .gitignore
507?? done/five
508?? dtwo/
509EOF
ce5c61a3 510 test_cmp ../status.expect ../status.iuc &&
7687252f
DT
511 test_cmp ../status.expect ../status.actual &&
512 cat >../trace.expect <<EOF &&
513node creation: 0
514gitignore invalidation: 1
515directory invalidation: 2
516opendir: 2
517EOF
518 test_cmp ../trace.expect ../trace
519'
520
521test_expect_success 'untracked cache correct after status' '
cd780f0b 522 test-tool dump-untracked-cache >../actual &&
7687252f 523 cat >../expect <<EOF &&
866be6ec 524info/exclude $(test_oid exclude)
525core.excludesfile $ZERO_OID
7687252f
DT
526exclude_per_dir .gitignore
527flags 00000006
866be6ec 528/ $(test_oid root) recurse valid
7687252f
DT
529.gitignore
530dtwo/
866be6ec 531/done/ $(test_oid done) recurse valid
7687252f 532five
866be6ec 533/dthree/ $ZERO_OID recurse check_only valid
534/dtwo/ $ZERO_OID recurse check_only valid
7687252f
DT
535two
536EOF
537 test_cmp ../expect ../actual
538'
539
540test_expect_success 'test sparse status again with untracked cache' '
541 avoid_racy &&
542 : >../trace &&
543 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
544 git status --porcelain >../status.actual &&
ce5c61a3 545 iuc status --porcelain >../status.iuc &&
7687252f 546 cat >../status.expect <<EOF &&
2e5910f2 547 M done/two
7687252f
DT
548?? .gitignore
549?? done/five
550?? dtwo/
551EOF
ce5c61a3 552 test_cmp ../status.expect ../status.iuc &&
7687252f
DT
553 test_cmp ../status.expect ../status.actual &&
554 cat >../trace.expect <<EOF &&
555node creation: 0
556gitignore invalidation: 0
557directory invalidation: 0
558opendir: 0
559EOF
560 test_cmp ../trace.expect ../trace
561'
562
2e5910f2
DT
563test_expect_success 'set up for test of subdir and sparse checkouts' '
564 mkdir done/sub &&
565 mkdir done/sub/sub &&
566 echo "sub" > done/sub/sub/file
567'
568
569test_expect_success 'test sparse status with untracked cache and subdir' '
570 avoid_racy &&
571 : >../trace &&
572 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
573 git status --porcelain >../status.actual &&
ce5c61a3 574 iuc status --porcelain >../status.iuc &&
2e5910f2
DT
575 cat >../status.expect <<EOF &&
576 M done/two
577?? .gitignore
578?? done/five
579?? done/sub/
580?? dtwo/
581EOF
ce5c61a3 582 test_cmp ../status.expect ../status.iuc &&
2e5910f2
DT
583 test_cmp ../status.expect ../status.actual &&
584 cat >../trace.expect <<EOF &&
585node creation: 2
586gitignore invalidation: 0
587directory invalidation: 1
588opendir: 3
589EOF
590 test_cmp ../trace.expect ../trace
591'
592
593test_expect_success 'verify untracked cache dump (sparse/subdirs)' '
cd780f0b 594 test-tool dump-untracked-cache >../actual &&
7c121788 595 cat >../expect-from-test-dump <<EOF &&
866be6ec 596info/exclude $(test_oid exclude)
597core.excludesfile $ZERO_OID
2e5910f2
DT
598exclude_per_dir .gitignore
599flags 00000006
866be6ec 600/ $(test_oid root) recurse valid
2e5910f2
DT
601.gitignore
602dtwo/
866be6ec 603/done/ $(test_oid done) recurse valid
2e5910f2
DT
604five
605sub/
866be6ec 606/done/sub/ $ZERO_OID recurse check_only valid
2e5910f2 607sub/
866be6ec 608/done/sub/sub/ $ZERO_OID recurse check_only valid
2e5910f2 609file
866be6ec 610/dthree/ $ZERO_OID recurse check_only valid
611/dtwo/ $ZERO_OID recurse check_only valid
2e5910f2
DT
612two
613EOF
7c121788 614 test_cmp ../expect-from-test-dump ../actual
2e5910f2
DT
615'
616
617test_expect_success 'test sparse status again with untracked cache and subdir' '
618 avoid_racy &&
619 : >../trace &&
620 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
621 git status --porcelain >../status.actual &&
ce5c61a3
EN
622 iuc status --porcelain >../status.iuc &&
623 test_cmp ../status.expect ../status.iuc &&
2e5910f2
DT
624 test_cmp ../status.expect ../status.actual &&
625 cat >../trace.expect <<EOF &&
626node creation: 0
627gitignore invalidation: 0
628directory invalidation: 0
629opendir: 0
630EOF
631 test_cmp ../trace.expect ../trace
632'
633
73f9145f
NTND
634test_expect_success 'move entry in subdir from untracked to cached' '
635 git add dtwo/two &&
636 git status --porcelain >../status.actual &&
ce5c61a3 637 iuc status --porcelain >../status.iuc &&
73f9145f
NTND
638 cat >../status.expect <<EOF &&
639 M done/two
640A dtwo/two
641?? .gitignore
642?? done/five
643?? done/sub/
644EOF
ce5c61a3 645 test_cmp ../status.expect ../status.iuc &&
73f9145f
NTND
646 test_cmp ../status.expect ../status.actual
647'
648
649test_expect_success 'move entry in subdir from cached to untracked' '
650 git rm --cached dtwo/two &&
651 git status --porcelain >../status.actual &&
ce5c61a3 652 iuc status --porcelain >../status.iuc &&
73f9145f
NTND
653 cat >../status.expect <<EOF &&
654 M done/two
655?? .gitignore
656?? done/five
657?? done/sub/
658?? dtwo/
659EOF
ce5c61a3 660 test_cmp ../status.expect ../status.iuc &&
73f9145f
NTND
661 test_cmp ../status.expect ../status.actual
662'
663
7c121788
CC
664test_expect_success '--no-untracked-cache removes the cache' '
665 git update-index --no-untracked-cache &&
cd780f0b 666 test-tool dump-untracked-cache >../actual &&
7c121788
CC
667 echo "no untracked cache" >../expect-no-uc &&
668 test_cmp ../expect-no-uc ../actual
669'
670
671test_expect_success 'git status does not change anything' '
672 git status &&
cd780f0b 673 test-tool dump-untracked-cache >../actual &&
7c121788
CC
674 test_cmp ../expect-no-uc ../actual
675'
676
677test_expect_success 'setting core.untrackedCache to true and using git status creates the cache' '
678 git config core.untrackedCache true &&
cd780f0b 679 test-tool dump-untracked-cache >../actual &&
7c121788
CC
680 test_cmp ../expect-no-uc ../actual &&
681 git status &&
cd780f0b 682 test-tool dump-untracked-cache >../actual &&
7c121788
CC
683 test_cmp ../expect-from-test-dump ../actual
684'
685
686test_expect_success 'using --no-untracked-cache does not fail when core.untrackedCache is true' '
687 git update-index --no-untracked-cache &&
cd780f0b 688 test-tool dump-untracked-cache >../actual &&
7c121788
CC
689 test_cmp ../expect-no-uc ../actual &&
690 git update-index --untracked-cache &&
cd780f0b 691 test-tool dump-untracked-cache >../actual &&
7c121788
CC
692 test_cmp ../expect-empty ../actual
693'
694
695test_expect_success 'setting core.untrackedCache to false and using git status removes the cache' '
696 git config core.untrackedCache false &&
cd780f0b 697 test-tool dump-untracked-cache >../actual &&
7c121788
CC
698 test_cmp ../expect-empty ../actual &&
699 git status &&
cd780f0b 700 test-tool dump-untracked-cache >../actual &&
7c121788
CC
701 test_cmp ../expect-no-uc ../actual
702'
703
704test_expect_success 'using --untracked-cache does not fail when core.untrackedCache is false' '
705 git update-index --untracked-cache &&
cd780f0b 706 test-tool dump-untracked-cache >../actual &&
7c121788
CC
707 test_cmp ../expect-empty ../actual
708'
709
710test_expect_success 'setting core.untrackedCache to keep' '
711 git config core.untrackedCache keep &&
712 git update-index --untracked-cache &&
cd780f0b 713 test-tool dump-untracked-cache >../actual &&
7c121788
CC
714 test_cmp ../expect-empty ../actual &&
715 git status &&
cd780f0b 716 test-tool dump-untracked-cache >../actual &&
7c121788
CC
717 test_cmp ../expect-from-test-dump ../actual &&
718 git update-index --no-untracked-cache &&
cd780f0b 719 test-tool dump-untracked-cache >../actual &&
7c121788
CC
720 test_cmp ../expect-no-uc ../actual &&
721 git update-index --force-untracked-cache &&
cd780f0b 722 test-tool dump-untracked-cache >../actual &&
7c121788
CC
723 test_cmp ../expect-empty ../actual &&
724 git status &&
cd780f0b 725 test-tool dump-untracked-cache >../actual &&
7c121788
CC
726 test_cmp ../expect-from-test-dump ../actual
727'
728
729test_expect_success 'test ident field is working' '
730 mkdir ../other_worktree &&
731 cp -R done dthree dtwo four three ../other_worktree &&
732 GIT_WORK_TREE=../other_worktree git status 2>../err &&
1a07e59c 733 echo "warning: untracked cache is disabled on this system or location" >../expect &&
1108cea7 734 test_cmp ../expect ../err
7c121788
CC
735'
736
edf3b905
DT
737test_expect_success 'untracked cache survives a checkout' '
738 git commit --allow-empty -m empty &&
cd780f0b 739 test-tool dump-untracked-cache >../before &&
01dc8133 740 test_when_finished "git checkout main" &&
edf3b905 741 git checkout -b other_branch &&
cd780f0b 742 test-tool dump-untracked-cache >../after &&
edf3b905
DT
743 test_cmp ../before ../after &&
744 test_commit test &&
cd780f0b 745 test-tool dump-untracked-cache >../before &&
01dc8133 746 git checkout main &&
cd780f0b 747 test-tool dump-untracked-cache >../after &&
edf3b905
DT
748 test_cmp ../before ../after
749'
750
751test_expect_success 'untracked cache survives a commit' '
cd780f0b 752 test-tool dump-untracked-cache >../before &&
edf3b905
DT
753 git add done/two &&
754 git commit -m commit &&
cd780f0b 755 test-tool dump-untracked-cache >../after &&
edf3b905
DT
756 test_cmp ../before ../after
757'
758
ce0330ca
ÆAB
759test_expect_success 'teardown worktree' '
760 cd ..
761'
762
763test_expect_success SYMLINKS 'setup worktree for symlink test' '
764 git init worktree-symlink &&
765 cd worktree-symlink &&
766 git config core.untrackedCache true &&
767 mkdir one two &&
768 touch one/file two/file &&
769 git add one/file two/file &&
770 git commit -m"first commit" &&
771 git rm -rf one &&
772 ln -s two one &&
773 git add one &&
774 git commit -m"second commit"
775'
776
b6403131 777test_expect_success SYMLINKS '"status" after symlink replacement should be clean with UC=true' '
ce0330ca
ÆAB
778 git checkout HEAD~ &&
779 status_is_clean &&
780 status_is_clean &&
01dc8133 781 git checkout main &&
ce0330ca
ÆAB
782 avoid_racy &&
783 status_is_clean &&
784 status_is_clean
785'
786
787test_expect_success SYMLINKS '"status" after symlink replacement should be clean with UC=false' '
788 git config core.untrackedCache false &&
789 git checkout HEAD~ &&
790 status_is_clean &&
791 status_is_clean &&
01dc8133 792 git checkout main &&
ce0330ca
ÆAB
793 avoid_racy &&
794 status_is_clean &&
795 status_is_clean
796'
797
798test_expect_success 'setup worktree for non-symlink test' '
799 git init worktree-non-symlink &&
800 cd worktree-non-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 cp two/file one &&
808 git add one &&
809 git commit -m"second commit"
810'
811
b6403131 812test_expect_success '"status" after file 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 &&
cd780f0b 819 test-tool dump-untracked-cache >../actual &&
ce0330ca
ÆAB
820 grep -F "recurse valid" ../actual >../actual.grep &&
821 cat >../expect.grep <<EOF &&
866be6ec 822/ $ZERO_OID recurse valid
823/two/ $ZERO_OID recurse valid
ce0330ca
ÆAB
824EOF
825 status_is_clean &&
826 test_cmp ../expect.grep ../actual.grep
827'
828
829test_expect_success '"status" after file replacement should be clean with UC=false' '
830 git config core.untrackedCache false &&
831 git checkout HEAD~ &&
832 status_is_clean &&
833 status_is_clean &&
01dc8133 834 git checkout main &&
ce0330ca
ÆAB
835 avoid_racy &&
836 status_is_clean &&
837 status_is_clean
838'
839
a3ddcefd 840test_done