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