]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh | |
2 | ||
3 | test_description='test untracked cache' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
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 | ||
17 | GIT_FORCE_UNTRACKED_CACHE=true | |
18 | export GIT_FORCE_UNTRACKED_CACHE | |
19 | ||
20 | sync_mtime () { | |
21 | find . -type d -exec ls -ld {} + >/dev/null | |
22 | } | |
23 | ||
24 | avoid_racy() { | |
25 | sleep 1 | |
26 | } | |
27 | ||
28 | status_is_clean() { | |
29 | git status --porcelain >../status.actual && | |
30 | test_must_be_empty ../status.actual | |
31 | } | |
32 | ||
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 | |
38 | iuc () { | |
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 | ||
57 | test_lazy_prereq UNTRACKED_CACHE ' | |
58 | { git update-index --test-untracked-cache; ret=$?; } && | |
59 | test $ret -ne 1 | |
60 | ' | |
61 | ||
62 | if ! test_have_prereq UNTRACKED_CACHE; then | |
63 | skip_all='This system does not support untracked cache' | |
64 | test_done | |
65 | fi | |
66 | ||
67 | test_expect_success 'core.untrackedCache is unset' ' | |
68 | test_must_fail git config --get core.untrackedCache | |
69 | ' | |
70 | ||
71 | test_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 | ||
81 | test_expect_success 'untracked cache is empty' ' | |
82 | test-tool dump-untracked-cache >../actual && | |
83 | cat >../expect-empty <<EOF && | |
84 | info/exclude 0000000000000000000000000000000000000000 | |
85 | core.excludesfile 0000000000000000000000000000000000000000 | |
86 | exclude_per_dir .gitignore | |
87 | flags 00000006 | |
88 | EOF | |
89 | test_cmp ../expect-empty ../actual | |
90 | ' | |
91 | ||
92 | cat >../status.expect <<EOF && | |
93 | A done/one | |
94 | A one | |
95 | A two | |
96 | ?? dthree/ | |
97 | ?? dtwo/ | |
98 | ?? three | |
99 | EOF | |
100 | ||
101 | cat >../dump.expect <<EOF && | |
102 | info/exclude $EMPTY_BLOB | |
103 | core.excludesfile 0000000000000000000000000000000000000000 | |
104 | exclude_per_dir .gitignore | |
105 | flags 00000006 | |
106 | / 0000000000000000000000000000000000000000 recurse valid | |
107 | dthree/ | |
108 | dtwo/ | |
109 | three | |
110 | /done/ 0000000000000000000000000000000000000000 recurse valid | |
111 | /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid | |
112 | three | |
113 | /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid | |
114 | two | |
115 | EOF | |
116 | ||
117 | test_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 && | |
122 | iuc status --porcelain >../status.iuc && | |
123 | test_cmp ../status.expect ../status.iuc && | |
124 | test_cmp ../status.expect ../actual && | |
125 | cat >../trace.expect <<EOF && | |
126 | node creation: 3 | |
127 | gitignore invalidation: 1 | |
128 | directory invalidation: 0 | |
129 | opendir: 4 | |
130 | EOF | |
131 | test_cmp ../trace.expect ../trace | |
132 | ' | |
133 | ||
134 | test_expect_success 'untracked cache after first status' ' | |
135 | test-tool dump-untracked-cache >../actual && | |
136 | test_cmp ../dump.expect ../actual | |
137 | ' | |
138 | ||
139 | test_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 && | |
144 | iuc status --porcelain >../status.iuc && | |
145 | test_cmp ../status.expect ../status.iuc && | |
146 | test_cmp ../status.expect ../actual && | |
147 | cat >../trace.expect <<EOF && | |
148 | node creation: 0 | |
149 | gitignore invalidation: 0 | |
150 | directory invalidation: 0 | |
151 | opendir: 0 | |
152 | EOF | |
153 | test_cmp ../trace.expect ../trace | |
154 | ' | |
155 | ||
156 | test_expect_success 'untracked cache after second status' ' | |
157 | test-tool dump-untracked-cache >../actual && | |
158 | test_cmp ../dump.expect ../actual | |
159 | ' | |
160 | ||
161 | test_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 && | |
167 | iuc status --porcelain >../status.iuc && | |
168 | cat >../status.expect <<EOF && | |
169 | A done/one | |
170 | A one | |
171 | A two | |
172 | ?? dthree/ | |
173 | ?? dtwo/ | |
174 | ?? four | |
175 | ?? three | |
176 | EOF | |
177 | test_cmp ../status.expect ../status.iuc && | |
178 | test_cmp ../status.expect ../actual && | |
179 | cat >../trace.expect <<EOF && | |
180 | node creation: 0 | |
181 | gitignore invalidation: 0 | |
182 | directory invalidation: 1 | |
183 | opendir: 1 | |
184 | EOF | |
185 | test_cmp ../trace.expect ../trace | |
186 | ||
187 | ' | |
188 | ||
189 | test_expect_success 'verify untracked cache dump' ' | |
190 | test-tool dump-untracked-cache >../actual && | |
191 | cat >../expect <<EOF && | |
192 | info/exclude $EMPTY_BLOB | |
193 | core.excludesfile 0000000000000000000000000000000000000000 | |
194 | exclude_per_dir .gitignore | |
195 | flags 00000006 | |
196 | / 0000000000000000000000000000000000000000 recurse valid | |
197 | dthree/ | |
198 | dtwo/ | |
199 | four | |
200 | three | |
201 | /done/ 0000000000000000000000000000000000000000 recurse valid | |
202 | /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid | |
203 | three | |
204 | /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid | |
205 | two | |
206 | EOF | |
207 | test_cmp ../expect ../actual | |
208 | ' | |
209 | ||
210 | test_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 && | |
216 | iuc status --porcelain >../status.iuc && | |
217 | cat >../status.expect <<EOF && | |
218 | A done/one | |
219 | A one | |
220 | A two | |
221 | ?? .gitignore | |
222 | ?? dthree/ | |
223 | ?? dtwo/ | |
224 | ?? three | |
225 | EOF | |
226 | test_cmp ../status.expect ../status.iuc && | |
227 | test_cmp ../status.expect ../actual && | |
228 | cat >../trace.expect <<EOF && | |
229 | node creation: 0 | |
230 | gitignore invalidation: 1 | |
231 | directory invalidation: 1 | |
232 | opendir: 4 | |
233 | EOF | |
234 | test_cmp ../trace.expect ../trace | |
235 | ||
236 | ' | |
237 | ||
238 | test_expect_success 'verify untracked cache dump' ' | |
239 | test-tool dump-untracked-cache >../actual && | |
240 | cat >../expect <<EOF && | |
241 | info/exclude $EMPTY_BLOB | |
242 | core.excludesfile 0000000000000000000000000000000000000000 | |
243 | exclude_per_dir .gitignore | |
244 | flags 00000006 | |
245 | / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid | |
246 | .gitignore | |
247 | dthree/ | |
248 | dtwo/ | |
249 | three | |
250 | /done/ 0000000000000000000000000000000000000000 recurse valid | |
251 | /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid | |
252 | three | |
253 | /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid | |
254 | two | |
255 | EOF | |
256 | test_cmp ../expect ../actual | |
257 | ' | |
258 | ||
259 | test_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 && | |
265 | iuc status --porcelain >../status.iuc && | |
266 | cat >../status.expect <<EOF && | |
267 | A done/one | |
268 | A one | |
269 | A two | |
270 | ?? .gitignore | |
271 | ?? dtwo/ | |
272 | EOF | |
273 | test_cmp ../status.expect ../status.iuc && | |
274 | test_cmp ../status.expect ../actual && | |
275 | cat >../trace.expect <<EOF && | |
276 | node creation: 0 | |
277 | gitignore invalidation: 1 | |
278 | directory invalidation: 0 | |
279 | opendir: 4 | |
280 | EOF | |
281 | test_cmp ../trace.expect ../trace | |
282 | ' | |
283 | ||
284 | test_expect_success 'verify untracked cache dump' ' | |
285 | test-tool dump-untracked-cache >../actual && | |
286 | cat >../expect <<EOF && | |
287 | info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0 | |
288 | core.excludesfile 0000000000000000000000000000000000000000 | |
289 | exclude_per_dir .gitignore | |
290 | flags 00000006 | |
291 | / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid | |
292 | .gitignore | |
293 | dtwo/ | |
294 | /done/ 0000000000000000000000000000000000000000 recurse valid | |
295 | /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid | |
296 | /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid | |
297 | two | |
298 | EOF | |
299 | test_cmp ../expect ../actual | |
300 | ' | |
301 | ||
302 | test_expect_success 'move two from tracked to untracked' ' | |
303 | git rm --cached two && | |
304 | test-tool dump-untracked-cache >../actual && | |
305 | cat >../expect <<EOF && | |
306 | info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0 | |
307 | core.excludesfile 0000000000000000000000000000000000000000 | |
308 | exclude_per_dir .gitignore | |
309 | flags 00000006 | |
310 | / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse | |
311 | /done/ 0000000000000000000000000000000000000000 recurse valid | |
312 | /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid | |
313 | /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid | |
314 | two | |
315 | EOF | |
316 | test_cmp ../expect ../actual | |
317 | ' | |
318 | ||
319 | test_expect_success 'status after the move' ' | |
320 | : >../trace && | |
321 | GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \ | |
322 | git status --porcelain >../actual && | |
323 | iuc status --porcelain >../status.iuc && | |
324 | cat >../status.expect <<EOF && | |
325 | A done/one | |
326 | A one | |
327 | ?? .gitignore | |
328 | ?? dtwo/ | |
329 | ?? two | |
330 | EOF | |
331 | test_cmp ../status.expect ../status.iuc && | |
332 | test_cmp ../status.expect ../actual && | |
333 | cat >../trace.expect <<EOF && | |
334 | node creation: 0 | |
335 | gitignore invalidation: 0 | |
336 | directory invalidation: 0 | |
337 | opendir: 1 | |
338 | EOF | |
339 | test_cmp ../trace.expect ../trace | |
340 | ' | |
341 | ||
342 | test_expect_success 'verify untracked cache dump' ' | |
343 | test-tool dump-untracked-cache >../actual && | |
344 | cat >../expect <<EOF && | |
345 | info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0 | |
346 | core.excludesfile 0000000000000000000000000000000000000000 | |
347 | exclude_per_dir .gitignore | |
348 | flags 00000006 | |
349 | / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid | |
350 | .gitignore | |
351 | dtwo/ | |
352 | two | |
353 | /done/ 0000000000000000000000000000000000000000 recurse valid | |
354 | /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid | |
355 | /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid | |
356 | two | |
357 | EOF | |
358 | test_cmp ../expect ../actual | |
359 | ' | |
360 | ||
361 | test_expect_success 'move two from untracked to tracked' ' | |
362 | git add two && | |
363 | test-tool dump-untracked-cache >../actual && | |
364 | cat >../expect <<EOF && | |
365 | info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0 | |
366 | core.excludesfile 0000000000000000000000000000000000000000 | |
367 | exclude_per_dir .gitignore | |
368 | flags 00000006 | |
369 | / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse | |
370 | /done/ 0000000000000000000000000000000000000000 recurse valid | |
371 | /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid | |
372 | /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid | |
373 | two | |
374 | EOF | |
375 | test_cmp ../expect ../actual | |
376 | ' | |
377 | ||
378 | test_expect_success 'status after the move' ' | |
379 | : >../trace && | |
380 | GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \ | |
381 | git status --porcelain >../actual && | |
382 | iuc status --porcelain >../status.iuc && | |
383 | cat >../status.expect <<EOF && | |
384 | A done/one | |
385 | A one | |
386 | A two | |
387 | ?? .gitignore | |
388 | ?? dtwo/ | |
389 | EOF | |
390 | test_cmp ../status.expect ../status.iuc && | |
391 | test_cmp ../status.expect ../actual && | |
392 | cat >../trace.expect <<EOF && | |
393 | node creation: 0 | |
394 | gitignore invalidation: 0 | |
395 | directory invalidation: 0 | |
396 | opendir: 1 | |
397 | EOF | |
398 | test_cmp ../trace.expect ../trace | |
399 | ' | |
400 | ||
401 | test_expect_success 'verify untracked cache dump' ' | |
402 | test-tool dump-untracked-cache >../actual && | |
403 | cat >../expect <<EOF && | |
404 | info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0 | |
405 | core.excludesfile 0000000000000000000000000000000000000000 | |
406 | exclude_per_dir .gitignore | |
407 | flags 00000006 | |
408 | / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid | |
409 | .gitignore | |
410 | dtwo/ | |
411 | /done/ 0000000000000000000000000000000000000000 recurse valid | |
412 | /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid | |
413 | /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid | |
414 | two | |
415 | EOF | |
416 | test_cmp ../expect ../actual | |
417 | ' | |
418 | ||
419 | test_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 | ||
427 | test_expect_success 'status after commit' ' | |
428 | : >../trace && | |
429 | GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \ | |
430 | git status --porcelain >../actual && | |
431 | iuc status --porcelain >../status.iuc && | |
432 | cat >../status.expect <<EOF && | |
433 | ?? .gitignore | |
434 | ?? dtwo/ | |
435 | EOF | |
436 | test_cmp ../status.expect ../status.iuc && | |
437 | test_cmp ../status.expect ../actual && | |
438 | cat >../trace.expect <<EOF && | |
439 | node creation: 0 | |
440 | gitignore invalidation: 0 | |
441 | directory invalidation: 0 | |
442 | opendir: 2 | |
443 | EOF | |
444 | test_cmp ../trace.expect ../trace | |
445 | ' | |
446 | ||
447 | test_expect_success 'untracked cache correct after commit' ' | |
448 | test-tool dump-untracked-cache >../actual && | |
449 | cat >../expect <<EOF && | |
450 | info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0 | |
451 | core.excludesfile 0000000000000000000000000000000000000000 | |
452 | exclude_per_dir .gitignore | |
453 | flags 00000006 | |
454 | / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid | |
455 | .gitignore | |
456 | dtwo/ | |
457 | /done/ 0000000000000000000000000000000000000000 recurse valid | |
458 | /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid | |
459 | /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid | |
460 | two | |
461 | EOF | |
462 | test_cmp ../expect ../actual | |
463 | ' | |
464 | ||
465 | test_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 && | |
469 | git update-index --force-untracked-cache && | |
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 | ||
475 | test_expect_success 'create/modify files, some of which are gitignored' ' | |
476 | echo two bis >done/two && | |
477 | echo three >done/three && # three is gitignored | |
478 | echo four >done/four && # four is gitignored at a higher level | |
479 | echo five >done/five && # five is not gitignored | |
480 | echo test >base && #we need to ensure that the root dir is touched | |
481 | rm base && | |
482 | sync_mtime | |
483 | ' | |
484 | ||
485 | test_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 && | |
490 | iuc status --porcelain >../status.iuc && | |
491 | cat >../status.expect <<EOF && | |
492 | M done/two | |
493 | ?? .gitignore | |
494 | ?? done/five | |
495 | ?? dtwo/ | |
496 | EOF | |
497 | test_cmp ../status.expect ../status.iuc && | |
498 | test_cmp ../status.expect ../status.actual && | |
499 | cat >../trace.expect <<EOF && | |
500 | node creation: 0 | |
501 | gitignore invalidation: 1 | |
502 | directory invalidation: 2 | |
503 | opendir: 2 | |
504 | EOF | |
505 | test_cmp ../trace.expect ../trace | |
506 | ' | |
507 | ||
508 | test_expect_success 'untracked cache correct after status' ' | |
509 | test-tool dump-untracked-cache >../actual && | |
510 | cat >../expect <<EOF && | |
511 | info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0 | |
512 | core.excludesfile 0000000000000000000000000000000000000000 | |
513 | exclude_per_dir .gitignore | |
514 | flags 00000006 | |
515 | / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid | |
516 | .gitignore | |
517 | dtwo/ | |
518 | /done/ 1946f0437f90c5005533cbe1736a6451ca301714 recurse valid | |
519 | five | |
520 | /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid | |
521 | /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid | |
522 | two | |
523 | EOF | |
524 | test_cmp ../expect ../actual | |
525 | ' | |
526 | ||
527 | test_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 && | |
532 | iuc status --porcelain >../status.iuc && | |
533 | cat >../status.expect <<EOF && | |
534 | M done/two | |
535 | ?? .gitignore | |
536 | ?? done/five | |
537 | ?? dtwo/ | |
538 | EOF | |
539 | test_cmp ../status.expect ../status.iuc && | |
540 | test_cmp ../status.expect ../status.actual && | |
541 | cat >../trace.expect <<EOF && | |
542 | node creation: 0 | |
543 | gitignore invalidation: 0 | |
544 | directory invalidation: 0 | |
545 | opendir: 0 | |
546 | EOF | |
547 | test_cmp ../trace.expect ../trace | |
548 | ' | |
549 | ||
550 | test_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 | ||
556 | test_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 && | |
561 | iuc status --porcelain >../status.iuc && | |
562 | cat >../status.expect <<EOF && | |
563 | M done/two | |
564 | ?? .gitignore | |
565 | ?? done/five | |
566 | ?? done/sub/ | |
567 | ?? dtwo/ | |
568 | EOF | |
569 | test_cmp ../status.expect ../status.iuc && | |
570 | test_cmp ../status.expect ../status.actual && | |
571 | cat >../trace.expect <<EOF && | |
572 | node creation: 2 | |
573 | gitignore invalidation: 0 | |
574 | directory invalidation: 1 | |
575 | opendir: 3 | |
576 | EOF | |
577 | test_cmp ../trace.expect ../trace | |
578 | ' | |
579 | ||
580 | test_expect_success 'verify untracked cache dump (sparse/subdirs)' ' | |
581 | test-tool dump-untracked-cache >../actual && | |
582 | cat >../expect-from-test-dump <<EOF && | |
583 | info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0 | |
584 | core.excludesfile 0000000000000000000000000000000000000000 | |
585 | exclude_per_dir .gitignore | |
586 | flags 00000006 | |
587 | / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid | |
588 | .gitignore | |
589 | dtwo/ | |
590 | /done/ 1946f0437f90c5005533cbe1736a6451ca301714 recurse valid | |
591 | five | |
592 | sub/ | |
593 | /done/sub/ 0000000000000000000000000000000000000000 recurse check_only valid | |
594 | sub/ | |
595 | /done/sub/sub/ 0000000000000000000000000000000000000000 recurse check_only valid | |
596 | file | |
597 | /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid | |
598 | /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid | |
599 | two | |
600 | EOF | |
601 | test_cmp ../expect-from-test-dump ../actual | |
602 | ' | |
603 | ||
604 | test_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 && | |
609 | iuc status --porcelain >../status.iuc && | |
610 | test_cmp ../status.expect ../status.iuc && | |
611 | test_cmp ../status.expect ../status.actual && | |
612 | cat >../trace.expect <<EOF && | |
613 | node creation: 0 | |
614 | gitignore invalidation: 0 | |
615 | directory invalidation: 0 | |
616 | opendir: 0 | |
617 | EOF | |
618 | test_cmp ../trace.expect ../trace | |
619 | ' | |
620 | ||
621 | test_expect_success 'move entry in subdir from untracked to cached' ' | |
622 | git add dtwo/two && | |
623 | git status --porcelain >../status.actual && | |
624 | iuc status --porcelain >../status.iuc && | |
625 | cat >../status.expect <<EOF && | |
626 | M done/two | |
627 | A dtwo/two | |
628 | ?? .gitignore | |
629 | ?? done/five | |
630 | ?? done/sub/ | |
631 | EOF | |
632 | test_cmp ../status.expect ../status.iuc && | |
633 | test_cmp ../status.expect ../status.actual | |
634 | ' | |
635 | ||
636 | test_expect_success 'move entry in subdir from cached to untracked' ' | |
637 | git rm --cached dtwo/two && | |
638 | git status --porcelain >../status.actual && | |
639 | iuc status --porcelain >../status.iuc && | |
640 | cat >../status.expect <<EOF && | |
641 | M done/two | |
642 | ?? .gitignore | |
643 | ?? done/five | |
644 | ?? done/sub/ | |
645 | ?? dtwo/ | |
646 | EOF | |
647 | test_cmp ../status.expect ../status.iuc && | |
648 | test_cmp ../status.expect ../status.actual | |
649 | ' | |
650 | ||
651 | test_expect_success '--no-untracked-cache removes the cache' ' | |
652 | git update-index --no-untracked-cache && | |
653 | test-tool dump-untracked-cache >../actual && | |
654 | echo "no untracked cache" >../expect-no-uc && | |
655 | test_cmp ../expect-no-uc ../actual | |
656 | ' | |
657 | ||
658 | test_expect_success 'git status does not change anything' ' | |
659 | git status && | |
660 | test-tool dump-untracked-cache >../actual && | |
661 | test_cmp ../expect-no-uc ../actual | |
662 | ' | |
663 | ||
664 | test_expect_success 'setting core.untrackedCache to true and using git status creates the cache' ' | |
665 | git config core.untrackedCache true && | |
666 | test-tool dump-untracked-cache >../actual && | |
667 | test_cmp ../expect-no-uc ../actual && | |
668 | git status && | |
669 | test-tool dump-untracked-cache >../actual && | |
670 | test_cmp ../expect-from-test-dump ../actual | |
671 | ' | |
672 | ||
673 | test_expect_success 'using --no-untracked-cache does not fail when core.untrackedCache is true' ' | |
674 | git update-index --no-untracked-cache && | |
675 | test-tool dump-untracked-cache >../actual && | |
676 | test_cmp ../expect-no-uc ../actual && | |
677 | git update-index --untracked-cache && | |
678 | test-tool dump-untracked-cache >../actual && | |
679 | test_cmp ../expect-empty ../actual | |
680 | ' | |
681 | ||
682 | test_expect_success 'setting core.untrackedCache to false and using git status removes the cache' ' | |
683 | git config core.untrackedCache false && | |
684 | test-tool dump-untracked-cache >../actual && | |
685 | test_cmp ../expect-empty ../actual && | |
686 | git status && | |
687 | test-tool dump-untracked-cache >../actual && | |
688 | test_cmp ../expect-no-uc ../actual | |
689 | ' | |
690 | ||
691 | test_expect_success 'using --untracked-cache does not fail when core.untrackedCache is false' ' | |
692 | git update-index --untracked-cache && | |
693 | test-tool dump-untracked-cache >../actual && | |
694 | test_cmp ../expect-empty ../actual | |
695 | ' | |
696 | ||
697 | test_expect_success 'setting core.untrackedCache to keep' ' | |
698 | git config core.untrackedCache keep && | |
699 | git update-index --untracked-cache && | |
700 | test-tool dump-untracked-cache >../actual && | |
701 | test_cmp ../expect-empty ../actual && | |
702 | git status && | |
703 | test-tool dump-untracked-cache >../actual && | |
704 | test_cmp ../expect-from-test-dump ../actual && | |
705 | git update-index --no-untracked-cache && | |
706 | test-tool dump-untracked-cache >../actual && | |
707 | test_cmp ../expect-no-uc ../actual && | |
708 | git update-index --force-untracked-cache && | |
709 | test-tool dump-untracked-cache >../actual && | |
710 | test_cmp ../expect-empty ../actual && | |
711 | git status && | |
712 | test-tool dump-untracked-cache >../actual && | |
713 | test_cmp ../expect-from-test-dump ../actual | |
714 | ' | |
715 | ||
716 | test_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 && | |
720 | echo "warning: untracked cache is disabled on this system or location" >../expect && | |
721 | test_i18ncmp ../expect ../err | |
722 | ' | |
723 | ||
724 | test_expect_success 'untracked cache survives a checkout' ' | |
725 | git commit --allow-empty -m empty && | |
726 | test-tool dump-untracked-cache >../before && | |
727 | test_when_finished "git checkout master" && | |
728 | git checkout -b other_branch && | |
729 | test-tool dump-untracked-cache >../after && | |
730 | test_cmp ../before ../after && | |
731 | test_commit test && | |
732 | test-tool dump-untracked-cache >../before && | |
733 | git checkout master && | |
734 | test-tool dump-untracked-cache >../after && | |
735 | test_cmp ../before ../after | |
736 | ' | |
737 | ||
738 | test_expect_success 'untracked cache survives a commit' ' | |
739 | test-tool dump-untracked-cache >../before && | |
740 | git add done/two && | |
741 | git commit -m commit && | |
742 | test-tool dump-untracked-cache >../after && | |
743 | test_cmp ../before ../after | |
744 | ' | |
745 | ||
746 | test_expect_success 'teardown worktree' ' | |
747 | cd .. | |
748 | ' | |
749 | ||
750 | test_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 | ||
764 | test_expect_success SYMLINKS '"status" after symlink replacement should be clean with UC=true' ' | |
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 | ||
774 | test_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 | ||
785 | test_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 | ||
799 | test_expect_success '"status" after file replacement should be clean with UC=true' ' | |
800 | git checkout HEAD~ && | |
801 | status_is_clean && | |
802 | status_is_clean && | |
803 | git checkout master && | |
804 | avoid_racy && | |
805 | status_is_clean && | |
806 | test-tool dump-untracked-cache >../actual && | |
807 | grep -F "recurse valid" ../actual >../actual.grep && | |
808 | cat >../expect.grep <<EOF && | |
809 | / 0000000000000000000000000000000000000000 recurse valid | |
810 | /two/ 0000000000000000000000000000000000000000 recurse valid | |
811 | EOF | |
812 | status_is_clean && | |
813 | test_cmp ../expect.grep ../actual.grep | |
814 | ' | |
815 | ||
816 | test_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 | ||
827 | test_done |