]>
Commit | Line | Data |
---|---|---|
a3ddcefd NTND |
1 | #!/bin/sh |
2 | ||
3 | test_description='test untracked cache' | |
4 | ||
01dc8133 | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export 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 |
20 | GIT_FORCE_UNTRACKED_CACHE=true |
21 | export GIT_FORCE_UNTRACKED_CACHE | |
fc9ecbeb | 22 | |
6b7728db | 23 | sync_mtime () { |
d51dd4ca | 24 | find . -type d -exec ls -ld {} + >/dev/null |
6b7728db NTND |
25 | } |
26 | ||
a3ddcefd NTND |
27 | avoid_racy() { |
28 | sleep 1 | |
29 | } | |
30 | ||
ce0330ca | 31 | status_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 | |
41 | iuc () { | |
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 |
60 | get_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 | 74 | test_lazy_prereq UNTRACKED_CACHE ' |
435ec090 | 75 | { git update-index --test-untracked-cache; ret=$?; } && |
fa73a582 JK |
76 | test $ret -ne 1 |
77 | ' | |
78 | ||
79 | if ! test_have_prereq UNTRACKED_CACHE; then | |
a3ddcefd NTND |
80 | skip_all='This system does not support untracked cache' |
81 | test_done | |
82 | fi | |
83 | ||
7c121788 CC |
84 | test_expect_success 'core.untrackedCache is unset' ' |
85 | test_must_fail git config --get core.untrackedCache | |
86 | ' | |
87 | ||
a3ddcefd NTND |
88 | test_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 | ||
111 | test_expect_success 'untracked cache is empty' ' | |
cd780f0b | 112 | test-tool dump-untracked-cache >../actual && |
7c121788 | 113 | cat >../expect-empty <<EOF && |
866be6ec | 114 | info/exclude $ZERO_OID |
115 | core.excludesfile $ZERO_OID | |
a3ddcefd NTND |
116 | exclude_per_dir .gitignore |
117 | flags 00000006 | |
118 | EOF | |
7c121788 | 119 | test_cmp ../expect-empty ../actual |
a3ddcefd NTND |
120 | ' |
121 | ||
122 | cat >../status.expect <<EOF && | |
123 | A done/one | |
124 | A one | |
125 | A two | |
126 | ?? dthree/ | |
127 | ?? dtwo/ | |
128 | ?? three | |
129 | EOF | |
130 | ||
131 | cat >../dump.expect <<EOF && | |
378932d3 | 132 | info/exclude $EMPTY_BLOB |
866be6ec | 133 | core.excludesfile $ZERO_OID |
a3ddcefd NTND |
134 | exclude_per_dir .gitignore |
135 | flags 00000006 | |
866be6ec | 136 | / $ZERO_OID recurse valid |
a3ddcefd NTND |
137 | dthree/ |
138 | dtwo/ | |
139 | three | |
866be6ec | 140 | /done/ $ZERO_OID recurse valid |
141 | /dthree/ $ZERO_OID recurse check_only valid | |
a3ddcefd | 142 | three |
866be6ec | 143 | /dtwo/ $ZERO_OID recurse check_only valid |
a3ddcefd NTND |
144 | two |
145 | EOF | |
146 | ||
147 | test_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 | 161 | EOF |
7f9dd879 | 162 | test_cmp ../trace.expect ../trace.relevant |
a3ddcefd NTND |
163 | ' |
164 | ||
165 | test_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 | ||
170 | test_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 | 184 | EOF |
7f9dd879 | 185 | test_cmp ../trace.expect ../trace.relevant |
a3ddcefd NTND |
186 | ' |
187 | ||
188 | test_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 | ||
193 | test_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 && |
201 | A done/one | |
202 | A one | |
203 | A two | |
204 | ?? dthree/ | |
205 | ?? dtwo/ | |
206 | ?? four | |
207 | ?? three | |
208 | EOF | |
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 | 218 | EOF |
7f9dd879 | 219 | test_cmp ../trace.expect ../trace.relevant |
a3ddcefd NTND |
220 | |
221 | ' | |
222 | ||
223 | test_expect_success 'verify untracked cache dump' ' | |
cd780f0b | 224 | test-tool dump-untracked-cache >../actual && |
a3ddcefd | 225 | cat >../expect <<EOF && |
378932d3 | 226 | info/exclude $EMPTY_BLOB |
866be6ec | 227 | core.excludesfile $ZERO_OID |
a3ddcefd NTND |
228 | exclude_per_dir .gitignore |
229 | flags 00000006 | |
866be6ec | 230 | / $ZERO_OID recurse valid |
a3ddcefd NTND |
231 | dthree/ |
232 | dtwo/ | |
233 | four | |
234 | three | |
866be6ec | 235 | /done/ $ZERO_OID recurse valid |
236 | /dthree/ $ZERO_OID recurse check_only valid | |
a3ddcefd | 237 | three |
866be6ec | 238 | /dtwo/ $ZERO_OID recurse check_only valid |
a3ddcefd NTND |
239 | two |
240 | EOF | |
241 | test_cmp ../expect ../actual | |
242 | ' | |
243 | ||
244 | test_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 && |
251 | A done/one | |
252 | A one | |
253 | A two | |
254 | ?? .gitignore | |
255 | ?? dthree/ | |
256 | ?? dtwo/ | |
257 | ?? three | |
258 | EOF | |
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 | 268 | EOF |
7f9dd879 | 269 | test_cmp ../trace.expect ../trace.relevant |
a3ddcefd NTND |
270 | |
271 | ' | |
272 | ||
273 | test_expect_success 'verify untracked cache dump' ' | |
cd780f0b | 274 | test-tool dump-untracked-cache >../actual && |
a3ddcefd | 275 | cat >../expect <<EOF && |
378932d3 | 276 | info/exclude $EMPTY_BLOB |
866be6ec | 277 | core.excludesfile $ZERO_OID |
a3ddcefd NTND |
278 | exclude_per_dir .gitignore |
279 | flags 00000006 | |
866be6ec | 280 | / $(test_oid root) recurse valid |
a3ddcefd NTND |
281 | .gitignore |
282 | dthree/ | |
283 | dtwo/ | |
284 | three | |
866be6ec | 285 | /done/ $ZERO_OID recurse valid |
286 | /dthree/ $ZERO_OID recurse check_only valid | |
a3ddcefd | 287 | three |
866be6ec | 288 | /dtwo/ $ZERO_OID recurse check_only valid |
a3ddcefd NTND |
289 | two |
290 | EOF | |
291 | test_cmp ../expect ../actual | |
292 | ' | |
293 | ||
294 | test_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 && |
301 | A done/one | |
302 | A one | |
303 | A two | |
304 | ?? .gitignore | |
305 | ?? dtwo/ | |
306 | EOF | |
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 | 316 | EOF |
7f9dd879 | 317 | test_cmp ../trace.expect ../trace.relevant |
a3ddcefd NTND |
318 | ' |
319 | ||
320 | test_expect_success 'verify untracked cache dump' ' | |
cd780f0b | 321 | test-tool dump-untracked-cache >../actual && |
a3ddcefd | 322 | cat >../expect <<EOF && |
866be6ec | 323 | info/exclude $(test_oid exclude) |
324 | core.excludesfile $ZERO_OID | |
a3ddcefd NTND |
325 | exclude_per_dir .gitignore |
326 | flags 00000006 | |
866be6ec | 327 | / $(test_oid root) recurse valid |
a3ddcefd NTND |
328 | .gitignore |
329 | dtwo/ | |
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 |
333 | two |
334 | EOF | |
335 | test_cmp ../expect ../actual | |
336 | ' | |
337 | ||
338 | test_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 | 342 | info/exclude $(test_oid exclude) |
343 | core.excludesfile $ZERO_OID | |
a3ddcefd NTND |
344 | exclude_per_dir .gitignore |
345 | flags 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 |
350 | two |
351 | EOF | |
352 | test_cmp ../expect ../actual | |
353 | ' | |
354 | ||
355 | test_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 && |
361 | A done/one | |
362 | A one | |
363 | ?? .gitignore | |
364 | ?? dtwo/ | |
365 | ?? two | |
366 | EOF | |
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 | 376 | EOF |
7f9dd879 | 377 | test_cmp ../trace.expect ../trace.relevant |
a3ddcefd NTND |
378 | ' |
379 | ||
380 | test_expect_success 'verify untracked cache dump' ' | |
cd780f0b | 381 | test-tool dump-untracked-cache >../actual && |
a3ddcefd | 382 | cat >../expect <<EOF && |
866be6ec | 383 | info/exclude $(test_oid exclude) |
384 | core.excludesfile $ZERO_OID | |
a3ddcefd NTND |
385 | exclude_per_dir .gitignore |
386 | flags 00000006 | |
866be6ec | 387 | / $(test_oid root) recurse valid |
a3ddcefd NTND |
388 | .gitignore |
389 | dtwo/ | |
390 | two | |
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 |
394 | two |
395 | EOF | |
396 | test_cmp ../expect ../actual | |
397 | ' | |
398 | ||
399 | test_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 | 403 | info/exclude $(test_oid exclude) |
404 | core.excludesfile $ZERO_OID | |
a3ddcefd NTND |
405 | exclude_per_dir .gitignore |
406 | flags 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 |
411 | two |
412 | EOF | |
413 | test_cmp ../expect ../actual | |
414 | ' | |
415 | ||
416 | test_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 && |
422 | A done/one | |
423 | A one | |
424 | A two | |
425 | ?? .gitignore | |
426 | ?? dtwo/ | |
427 | EOF | |
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 | 437 | EOF |
7f9dd879 | 438 | test_cmp ../trace.expect ../trace.relevant |
a3ddcefd NTND |
439 | ' |
440 | ||
441 | test_expect_success 'verify untracked cache dump' ' | |
cd780f0b | 442 | test-tool dump-untracked-cache >../actual && |
a3ddcefd | 443 | cat >../expect <<EOF && |
866be6ec | 444 | info/exclude $(test_oid exclude) |
445 | core.excludesfile $ZERO_OID | |
a3ddcefd NTND |
446 | exclude_per_dir .gitignore |
447 | flags 00000006 | |
866be6ec | 448 | / $(test_oid root) recurse valid |
a3ddcefd NTND |
449 | .gitignore |
450 | dtwo/ | |
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 |
454 | two |
455 | EOF | |
456 | test_cmp ../expect ../actual | |
457 | ' | |
458 | ||
7687252f DT |
459 | test_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 | ||
467 | test_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/ | |
475 | EOF | |
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 | 485 | EOF |
7f9dd879 | 486 | test_cmp ../trace.expect ../trace.relevant |
7687252f DT |
487 | ' |
488 | ||
489 | test_expect_success 'untracked cache correct after commit' ' | |
cd780f0b | 490 | test-tool dump-untracked-cache >../actual && |
7687252f | 491 | cat >../expect <<EOF && |
866be6ec | 492 | info/exclude $(test_oid exclude) |
493 | core.excludesfile $ZERO_OID | |
7687252f DT |
494 | exclude_per_dir .gitignore |
495 | flags 00000006 | |
866be6ec | 496 | / $(test_oid root) recurse valid |
7687252f DT |
497 | .gitignore |
498 | dtwo/ | |
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 |
502 | two |
503 | EOF | |
504 | test_cmp ../expect ../actual | |
505 | ' | |
506 | ||
507 | test_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 |
517 | test_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 | ||
528 | test_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/ | |
538 | EOF | |
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 | 548 | EOF |
7f9dd879 | 549 | test_cmp ../trace.expect ../trace.relevant |
7687252f DT |
550 | ' |
551 | ||
552 | test_expect_success 'untracked cache correct after status' ' | |
cd780f0b | 553 | test-tool dump-untracked-cache >../actual && |
7687252f | 554 | cat >../expect <<EOF && |
866be6ec | 555 | info/exclude $(test_oid exclude) |
556 | core.excludesfile $ZERO_OID | |
7687252f DT |
557 | exclude_per_dir .gitignore |
558 | flags 00000006 | |
866be6ec | 559 | / $(test_oid root) recurse valid |
7687252f DT |
560 | .gitignore |
561 | dtwo/ | |
866be6ec | 562 | /done/ $(test_oid done) recurse valid |
7687252f | 563 | five |
866be6ec | 564 | /dthree/ $ZERO_OID recurse check_only valid |
565 | /dtwo/ $ZERO_OID recurse check_only valid | |
7687252f DT |
566 | two |
567 | EOF | |
568 | test_cmp ../expect ../actual | |
569 | ' | |
570 | ||
571 | test_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/ | |
581 | EOF | |
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 | 591 | EOF |
7f9dd879 | 592 | test_cmp ../trace.expect ../trace.relevant |
7687252f DT |
593 | ' |
594 | ||
2e5910f2 DT |
595 | test_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 | ||
602 | test_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/ | |
613 | EOF | |
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 | 623 | EOF |
7f9dd879 | 624 | test_cmp ../trace.expect ../trace.relevant |
2e5910f2 DT |
625 | ' |
626 | ||
627 | test_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 | 630 | info/exclude $(test_oid exclude) |
631 | core.excludesfile $ZERO_OID | |
2e5910f2 DT |
632 | exclude_per_dir .gitignore |
633 | flags 00000006 | |
866be6ec | 634 | / $(test_oid root) recurse valid |
2e5910f2 DT |
635 | .gitignore |
636 | dtwo/ | |
866be6ec | 637 | /done/ $(test_oid done) recurse valid |
2e5910f2 DT |
638 | five |
639 | sub/ | |
866be6ec | 640 | /done/sub/ $ZERO_OID recurse check_only valid |
2e5910f2 | 641 | sub/ |
866be6ec | 642 | /done/sub/sub/ $ZERO_OID recurse check_only valid |
2e5910f2 | 643 | file |
866be6ec | 644 | /dthree/ $ZERO_OID recurse check_only valid |
645 | /dtwo/ $ZERO_OID recurse check_only valid | |
2e5910f2 DT |
646 | two |
647 | EOF | |
7c121788 | 648 | test_cmp ../expect-from-test-dump ../actual |
2e5910f2 DT |
649 | ' |
650 | ||
651 | test_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 | 665 | EOF |
7f9dd879 | 666 | test_cmp ../trace.expect ../trace.relevant |
2e5910f2 DT |
667 | ' |
668 | ||
73f9145f NTND |
669 | test_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 | |
675 | A dtwo/two | |
676 | ?? .gitignore | |
677 | ?? done/five | |
678 | ?? done/sub/ | |
679 | EOF | |
ce5c61a3 | 680 | test_cmp ../status.expect ../status.iuc && |
73f9145f NTND |
681 | test_cmp ../status.expect ../status.actual |
682 | ' | |
683 | ||
684 | test_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/ | |
694 | EOF | |
ce5c61a3 | 695 | test_cmp ../status.expect ../status.iuc && |
73f9145f NTND |
696 | test_cmp ../status.expect ../status.actual |
697 | ' | |
698 | ||
7c121788 CC |
699 | test_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 | ||
706 | test_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 | ||
712 | test_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 | ||
721 | test_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 | ||
730 | test_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 | ||
739 | test_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 | ||
745 | test_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 | ||
764 | test_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 |
772 | test_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 | ||
786 | test_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 |
794 | test_expect_success 'teardown worktree' ' |
795 | cd .. | |
796 | ' | |
797 | ||
798 | test_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 | 812 | test_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 | ||
822 | test_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 | ||
833 | test_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 | 847 | test_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 |
859 | EOF |
860 | status_is_clean && | |
861 | test_cmp ../expect.grep ../actual.grep | |
862 | ' | |
863 | ||
864 | test_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 | 875 | test_done |