blob: a682a3d826e9dedcf3a08df7a510f6973a42bb8b [file] [log] [blame]
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +07001#!/bin/sh
2
3test_description='test untracked cache'
4
5. ./test-lib.sh
6
Nguyễn Thái Ngọc Duy6b7728d2016-08-03 19:45:22 +02007# 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
Junio C Hamano026336c2018-02-28 13:21:09 -080017GIT_FORCE_UNTRACKED_CACHE=true
18export GIT_FORCE_UNTRACKED_CACHE
Ben Peartfc9ecbe2018-02-05 14:56:19 -050019
Nguyễn Thái Ngọc Duy6b7728d2016-08-03 19:45:22 +020020sync_mtime () {
Đoàn Trần Công Danhd51dd4c2020-03-25 22:06:19 +070021 find . -type d -exec ls -ld {} + >/dev/null
Nguyễn Thái Ngọc Duy6b7728d2016-08-03 19:45:22 +020022}
23
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +070024avoid_racy() {
25 sleep 1
26}
27
Ævar Arnfjörð Bjarmasonce0330c2018-01-24 16:30:19 +070028status_is_clean() {
Ævar Arnfjörð Bjarmasonce0330c2018-01-24 16:30:19 +070029 git status --porcelain >../status.actual &&
Ævar Arnfjörð Bjarmasond3c67512018-07-27 17:48:11 +000030 test_must_be_empty ../status.actual
Ævar Arnfjörð Bjarmasonce0330c2018-01-24 16:30:19 +070031}
32
Elijah Newrence5c61a2020-04-01 04:17:35 +000033# 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
Jeff Kingfa73a582015-05-27 05:34:58 -040057test_lazy_prereq UNTRACKED_CACHE '
Christian Couder435ec092016-01-27 07:58:05 +010058 { git update-index --test-untracked-cache; ret=$?; } &&
Jeff Kingfa73a582015-05-27 05:34:58 -040059 test $ret -ne 1
60'
61
62if ! test_have_prereq UNTRACKED_CACHE; then
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +070063 skip_all='This system does not support untracked cache'
64 test_done
65fi
66
Christian Couder7c121782016-01-27 07:58:07 +010067test_expect_success 'core.untrackedCache is unset' '
68 test_must_fail git config --get core.untrackedCache
69'
70
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +070071test_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 &&
brian m. carlson866be6e2020-07-29 23:14:00 +000078 git update-index --untracked-cache &&
79 test_oid_cache <<-EOF
80 root sha1:e6fcc8f2ee31bae321d66afd183fcb7237afae6e
81 root sha256:b90c672088c015b9c83876e919da311bad4cd39639fb139f988af6a11493b974
82
83 exclude sha1:13263c0978fb9fad16b2d580fb800b6d811c3ff0
84 exclude sha256:fe4aaa1bbbbce4cb8f73426748a14c5ad6026b26f90505a0bf2494b165a5b76c
85
86 done sha1:1946f0437f90c5005533cbe1736a6451ca301714
87 done sha256:7f079501d79f665b3acc50f5e0e9e94509084d5032ac20113a37dd5029b757cc
88 EOF
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +070089'
90
91test_expect_success 'untracked cache is empty' '
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +020092 test-tool dump-untracked-cache >../actual &&
Christian Couder7c121782016-01-27 07:58:07 +010093 cat >../expect-empty <<EOF &&
brian m. carlson866be6e2020-07-29 23:14:00 +000094info/exclude $ZERO_OID
95core.excludesfile $ZERO_OID
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +070096exclude_per_dir .gitignore
97flags 00000006
98EOF
Christian Couder7c121782016-01-27 07:58:07 +010099 test_cmp ../expect-empty ../actual
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700100'
101
102cat >../status.expect <<EOF &&
103A done/one
104A one
105A two
106?? dthree/
107?? dtwo/
108?? three
109EOF
110
111cat >../dump.expect <<EOF &&
Nguyễn Thái Ngọc Duy378932d2016-07-16 07:06:25 +0200112info/exclude $EMPTY_BLOB
brian m. carlson866be6e2020-07-29 23:14:00 +0000113core.excludesfile $ZERO_OID
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700114exclude_per_dir .gitignore
115flags 00000006
brian m. carlson866be6e2020-07-29 23:14:00 +0000116/ $ZERO_OID recurse valid
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700117dthree/
118dtwo/
119three
brian m. carlson866be6e2020-07-29 23:14:00 +0000120/done/ $ZERO_OID recurse valid
121/dthree/ $ZERO_OID recurse check_only valid
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700122three
brian m. carlson866be6e2020-07-29 23:14:00 +0000123/dtwo/ $ZERO_OID recurse check_only valid
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700124two
125EOF
126
127test_expect_success 'status first time (empty cache)' '
128 avoid_racy &&
129 : >../trace &&
130 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
131 git status --porcelain >../actual &&
Elijah Newrence5c61a2020-04-01 04:17:35 +0000132 iuc status --porcelain >../status.iuc &&
133 test_cmp ../status.expect ../status.iuc &&
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700134 test_cmp ../status.expect ../actual &&
135 cat >../trace.expect <<EOF &&
136node creation: 3
137gitignore invalidation: 1
138directory invalidation: 0
139opendir: 4
140EOF
141 test_cmp ../trace.expect ../trace
142'
143
144test_expect_success 'untracked cache after first status' '
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200145 test-tool dump-untracked-cache >../actual &&
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700146 test_cmp ../dump.expect ../actual
147'
148
149test_expect_success 'status second time (fully populated cache)' '
150 avoid_racy &&
151 : >../trace &&
152 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
153 git status --porcelain >../actual &&
Elijah Newrence5c61a2020-04-01 04:17:35 +0000154 iuc status --porcelain >../status.iuc &&
155 test_cmp ../status.expect ../status.iuc &&
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700156 test_cmp ../status.expect ../actual &&
157 cat >../trace.expect <<EOF &&
158node creation: 0
159gitignore invalidation: 0
160directory invalidation: 0
161opendir: 0
162EOF
163 test_cmp ../trace.expect ../trace
164'
165
166test_expect_success 'untracked cache after second status' '
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200167 test-tool dump-untracked-cache >../actual &&
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700168 test_cmp ../dump.expect ../actual
169'
170
171test_expect_success 'modify in root directory, one dir invalidation' '
172 avoid_racy &&
173 : >four &&
174 : >../trace &&
175 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
176 git status --porcelain >../actual &&
Elijah Newrence5c61a2020-04-01 04:17:35 +0000177 iuc status --porcelain >../status.iuc &&
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700178 cat >../status.expect <<EOF &&
179A done/one
180A one
181A two
182?? dthree/
183?? dtwo/
184?? four
185?? three
186EOF
Elijah Newrence5c61a2020-04-01 04:17:35 +0000187 test_cmp ../status.expect ../status.iuc &&
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700188 test_cmp ../status.expect ../actual &&
189 cat >../trace.expect <<EOF &&
190node creation: 0
191gitignore invalidation: 0
192directory invalidation: 1
193opendir: 1
194EOF
195 test_cmp ../trace.expect ../trace
196
197'
198
199test_expect_success 'verify untracked cache dump' '
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200200 test-tool dump-untracked-cache >../actual &&
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700201 cat >../expect <<EOF &&
Nguyễn Thái Ngọc Duy378932d2016-07-16 07:06:25 +0200202info/exclude $EMPTY_BLOB
brian m. carlson866be6e2020-07-29 23:14:00 +0000203core.excludesfile $ZERO_OID
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700204exclude_per_dir .gitignore
205flags 00000006
brian m. carlson866be6e2020-07-29 23:14:00 +0000206/ $ZERO_OID recurse valid
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700207dthree/
208dtwo/
209four
210three
brian m. carlson866be6e2020-07-29 23:14:00 +0000211/done/ $ZERO_OID recurse valid
212/dthree/ $ZERO_OID recurse check_only valid
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700213three
brian m. carlson866be6e2020-07-29 23:14:00 +0000214/dtwo/ $ZERO_OID recurse check_only valid
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700215two
216EOF
217 test_cmp ../expect ../actual
218'
219
220test_expect_success 'new .gitignore invalidates recursively' '
221 avoid_racy &&
222 echo four >.gitignore &&
223 : >../trace &&
224 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
225 git status --porcelain >../actual &&
Elijah Newrence5c61a2020-04-01 04:17:35 +0000226 iuc status --porcelain >../status.iuc &&
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700227 cat >../status.expect <<EOF &&
228A done/one
229A one
230A two
231?? .gitignore
232?? dthree/
233?? dtwo/
234?? three
235EOF
Elijah Newrence5c61a2020-04-01 04:17:35 +0000236 test_cmp ../status.expect ../status.iuc &&
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700237 test_cmp ../status.expect ../actual &&
238 cat >../trace.expect <<EOF &&
239node creation: 0
240gitignore invalidation: 1
241directory invalidation: 1
242opendir: 4
243EOF
244 test_cmp ../trace.expect ../trace
245
246'
247
248test_expect_success 'verify untracked cache dump' '
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200249 test-tool dump-untracked-cache >../actual &&
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700250 cat >../expect <<EOF &&
Nguyễn Thái Ngọc Duy378932d2016-07-16 07:06:25 +0200251info/exclude $EMPTY_BLOB
brian m. carlson866be6e2020-07-29 23:14:00 +0000252core.excludesfile $ZERO_OID
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700253exclude_per_dir .gitignore
254flags 00000006
brian m. carlson866be6e2020-07-29 23:14:00 +0000255/ $(test_oid root) recurse valid
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700256.gitignore
257dthree/
258dtwo/
259three
brian m. carlson866be6e2020-07-29 23:14:00 +0000260/done/ $ZERO_OID recurse valid
261/dthree/ $ZERO_OID recurse check_only valid
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700262three
brian m. carlson866be6e2020-07-29 23:14:00 +0000263/dtwo/ $ZERO_OID recurse check_only valid
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700264two
265EOF
266 test_cmp ../expect ../actual
267'
268
269test_expect_success 'new info/exclude invalidates everything' '
270 avoid_racy &&
271 echo three >>.git/info/exclude &&
272 : >../trace &&
273 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
274 git status --porcelain >../actual &&
Elijah Newrence5c61a2020-04-01 04:17:35 +0000275 iuc status --porcelain >../status.iuc &&
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700276 cat >../status.expect <<EOF &&
277A done/one
278A one
279A two
280?? .gitignore
281?? dtwo/
282EOF
Elijah Newrence5c61a2020-04-01 04:17:35 +0000283 test_cmp ../status.expect ../status.iuc &&
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700284 test_cmp ../status.expect ../actual &&
285 cat >../trace.expect <<EOF &&
286node creation: 0
287gitignore invalidation: 1
288directory invalidation: 0
289opendir: 4
290EOF
291 test_cmp ../trace.expect ../trace
292'
293
294test_expect_success 'verify untracked cache dump' '
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200295 test-tool dump-untracked-cache >../actual &&
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700296 cat >../expect <<EOF &&
brian m. carlson866be6e2020-07-29 23:14:00 +0000297info/exclude $(test_oid exclude)
298core.excludesfile $ZERO_OID
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700299exclude_per_dir .gitignore
300flags 00000006
brian m. carlson866be6e2020-07-29 23:14:00 +0000301/ $(test_oid root) recurse valid
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700302.gitignore
303dtwo/
brian m. carlson866be6e2020-07-29 23:14:00 +0000304/done/ $ZERO_OID recurse valid
305/dthree/ $ZERO_OID recurse check_only valid
306/dtwo/ $ZERO_OID recurse check_only valid
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700307two
308EOF
309 test_cmp ../expect ../actual
310'
311
312test_expect_success 'move two from tracked to untracked' '
313 git rm --cached two &&
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200314 test-tool dump-untracked-cache >../actual &&
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700315 cat >../expect <<EOF &&
brian m. carlson866be6e2020-07-29 23:14:00 +0000316info/exclude $(test_oid exclude)
317core.excludesfile $ZERO_OID
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700318exclude_per_dir .gitignore
319flags 00000006
brian m. carlson866be6e2020-07-29 23:14:00 +0000320/ $(test_oid root) recurse
321/done/ $ZERO_OID recurse valid
322/dthree/ $ZERO_OID recurse check_only valid
323/dtwo/ $ZERO_OID recurse check_only valid
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700324two
325EOF
326 test_cmp ../expect ../actual
327'
328
329test_expect_success 'status after the move' '
330 : >../trace &&
331 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
332 git status --porcelain >../actual &&
Elijah Newrence5c61a2020-04-01 04:17:35 +0000333 iuc status --porcelain >../status.iuc &&
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700334 cat >../status.expect <<EOF &&
335A done/one
336A one
337?? .gitignore
338?? dtwo/
339?? two
340EOF
Elijah Newrence5c61a2020-04-01 04:17:35 +0000341 test_cmp ../status.expect ../status.iuc &&
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700342 test_cmp ../status.expect ../actual &&
343 cat >../trace.expect <<EOF &&
344node creation: 0
345gitignore invalidation: 0
346directory invalidation: 0
347opendir: 1
348EOF
349 test_cmp ../trace.expect ../trace
350'
351
352test_expect_success 'verify untracked cache dump' '
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200353 test-tool dump-untracked-cache >../actual &&
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700354 cat >../expect <<EOF &&
brian m. carlson866be6e2020-07-29 23:14:00 +0000355info/exclude $(test_oid exclude)
356core.excludesfile $ZERO_OID
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700357exclude_per_dir .gitignore
358flags 00000006
brian m. carlson866be6e2020-07-29 23:14:00 +0000359/ $(test_oid root) recurse valid
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700360.gitignore
361dtwo/
362two
brian m. carlson866be6e2020-07-29 23:14:00 +0000363/done/ $ZERO_OID recurse valid
364/dthree/ $ZERO_OID recurse check_only valid
365/dtwo/ $ZERO_OID recurse check_only valid
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700366two
367EOF
368 test_cmp ../expect ../actual
369'
370
371test_expect_success 'move two from untracked to tracked' '
372 git add two &&
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200373 test-tool dump-untracked-cache >../actual &&
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700374 cat >../expect <<EOF &&
brian m. carlson866be6e2020-07-29 23:14:00 +0000375info/exclude $(test_oid exclude)
376core.excludesfile $ZERO_OID
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700377exclude_per_dir .gitignore
378flags 00000006
brian m. carlson866be6e2020-07-29 23:14:00 +0000379/ $(test_oid root) recurse
380/done/ $ZERO_OID recurse valid
381/dthree/ $ZERO_OID recurse check_only valid
382/dtwo/ $ZERO_OID recurse check_only valid
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700383two
384EOF
385 test_cmp ../expect ../actual
386'
387
388test_expect_success 'status after the move' '
389 : >../trace &&
390 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
391 git status --porcelain >../actual &&
Elijah Newrence5c61a2020-04-01 04:17:35 +0000392 iuc status --porcelain >../status.iuc &&
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700393 cat >../status.expect <<EOF &&
394A done/one
395A one
396A two
397?? .gitignore
398?? dtwo/
399EOF
Elijah Newrence5c61a2020-04-01 04:17:35 +0000400 test_cmp ../status.expect ../status.iuc &&
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700401 test_cmp ../status.expect ../actual &&
402 cat >../trace.expect <<EOF &&
403node creation: 0
404gitignore invalidation: 0
405directory invalidation: 0
406opendir: 1
407EOF
408 test_cmp ../trace.expect ../trace
409'
410
411test_expect_success 'verify untracked cache dump' '
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200412 test-tool dump-untracked-cache >../actual &&
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700413 cat >../expect <<EOF &&
brian m. carlson866be6e2020-07-29 23:14:00 +0000414info/exclude $(test_oid exclude)
415core.excludesfile $ZERO_OID
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700416exclude_per_dir .gitignore
417flags 00000006
brian m. carlson866be6e2020-07-29 23:14:00 +0000418/ $(test_oid root) recurse valid
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700419.gitignore
420dtwo/
brian m. carlson866be6e2020-07-29 23:14:00 +0000421/done/ $ZERO_OID recurse valid
422/dthree/ $ZERO_OID recurse check_only valid
423/dtwo/ $ZERO_OID recurse check_only valid
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700424two
425EOF
426 test_cmp ../expect ../actual
427'
428
David Turner76872522015-07-31 13:35:01 -0400429test_expect_success 'set up for sparse checkout testing' '
430 echo two >done/.gitignore &&
431 echo three >>done/.gitignore &&
432 echo two >done/two &&
433 git add -f done/two done/.gitignore &&
434 git commit -m "first commit"
435'
436
437test_expect_success 'status after commit' '
438 : >../trace &&
439 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
440 git status --porcelain >../actual &&
Elijah Newrence5c61a2020-04-01 04:17:35 +0000441 iuc status --porcelain >../status.iuc &&
David Turner76872522015-07-31 13:35:01 -0400442 cat >../status.expect <<EOF &&
443?? .gitignore
444?? dtwo/
445EOF
Elijah Newrence5c61a2020-04-01 04:17:35 +0000446 test_cmp ../status.expect ../status.iuc &&
David Turner76872522015-07-31 13:35:01 -0400447 test_cmp ../status.expect ../actual &&
448 cat >../trace.expect <<EOF &&
449node creation: 0
450gitignore invalidation: 0
451directory invalidation: 0
Nguyễn Thái Ngọc Duy73f91452015-08-19 20:01:26 +0700452opendir: 2
David Turner76872522015-07-31 13:35:01 -0400453EOF
454 test_cmp ../trace.expect ../trace
455'
456
457test_expect_success 'untracked cache correct after commit' '
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200458 test-tool dump-untracked-cache >../actual &&
David Turner76872522015-07-31 13:35:01 -0400459 cat >../expect <<EOF &&
brian m. carlson866be6e2020-07-29 23:14:00 +0000460info/exclude $(test_oid exclude)
461core.excludesfile $ZERO_OID
David Turner76872522015-07-31 13:35:01 -0400462exclude_per_dir .gitignore
463flags 00000006
brian m. carlson866be6e2020-07-29 23:14:00 +0000464/ $(test_oid root) recurse valid
David Turner76872522015-07-31 13:35:01 -0400465.gitignore
466dtwo/
brian m. carlson866be6e2020-07-29 23:14:00 +0000467/done/ $ZERO_OID recurse valid
468/dthree/ $ZERO_OID recurse check_only valid
469/dtwo/ $ZERO_OID recurse check_only valid
David Turner76872522015-07-31 13:35:01 -0400470two
471EOF
472 test_cmp ../expect ../actual
473'
474
475test_expect_success 'set up sparse checkout' '
476 echo "done/[a-z]*" >.git/info/sparse-checkout &&
477 test_config core.sparsecheckout true &&
478 git checkout master &&
Nguyễn Thái Ngọc Duyf1781362015-08-19 20:01:24 +0700479 git update-index --force-untracked-cache &&
David Turner76872522015-07-31 13:35:01 -0400480 git status --porcelain >/dev/null && # prime the cache
481 test_path_is_missing done/.gitignore &&
482 test_path_is_file done/one
483'
484
David Turner2e5910f2015-08-19 20:01:25 +0700485test_expect_success 'create/modify files, some of which are gitignored' '
486 echo two bis >done/two &&
David Turner76872522015-07-31 13:35:01 -0400487 echo three >done/three && # three is gitignored
488 echo four >done/four && # four is gitignored at a higher level
David Turner9b680fb2015-10-19 15:48:15 -0400489 echo five >done/five && # five is not gitignored
490 echo test >base && #we need to ensure that the root dir is touched
Nguyễn Thái Ngọc Duy6b7728d2016-08-03 19:45:22 +0200491 rm base &&
492 sync_mtime
David Turner76872522015-07-31 13:35:01 -0400493'
494
495test_expect_success 'test sparse status with untracked cache' '
496 : >../trace &&
497 avoid_racy &&
498 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
499 git status --porcelain >../status.actual &&
Elijah Newrence5c61a2020-04-01 04:17:35 +0000500 iuc status --porcelain >../status.iuc &&
David Turner76872522015-07-31 13:35:01 -0400501 cat >../status.expect <<EOF &&
David Turner2e5910f2015-08-19 20:01:25 +0700502 M done/two
David Turner76872522015-07-31 13:35:01 -0400503?? .gitignore
504?? done/five
505?? dtwo/
506EOF
Elijah Newrence5c61a2020-04-01 04:17:35 +0000507 test_cmp ../status.expect ../status.iuc &&
David Turner76872522015-07-31 13:35:01 -0400508 test_cmp ../status.expect ../status.actual &&
509 cat >../trace.expect <<EOF &&
510node creation: 0
511gitignore invalidation: 1
512directory invalidation: 2
513opendir: 2
514EOF
515 test_cmp ../trace.expect ../trace
516'
517
518test_expect_success 'untracked cache correct after status' '
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200519 test-tool dump-untracked-cache >../actual &&
David Turner76872522015-07-31 13:35:01 -0400520 cat >../expect <<EOF &&
brian m. carlson866be6e2020-07-29 23:14:00 +0000521info/exclude $(test_oid exclude)
522core.excludesfile $ZERO_OID
David Turner76872522015-07-31 13:35:01 -0400523exclude_per_dir .gitignore
524flags 00000006
brian m. carlson866be6e2020-07-29 23:14:00 +0000525/ $(test_oid root) recurse valid
David Turner76872522015-07-31 13:35:01 -0400526.gitignore
527dtwo/
brian m. carlson866be6e2020-07-29 23:14:00 +0000528/done/ $(test_oid done) recurse valid
David Turner76872522015-07-31 13:35:01 -0400529five
brian m. carlson866be6e2020-07-29 23:14:00 +0000530/dthree/ $ZERO_OID recurse check_only valid
531/dtwo/ $ZERO_OID recurse check_only valid
David Turner76872522015-07-31 13:35:01 -0400532two
533EOF
534 test_cmp ../expect ../actual
535'
536
537test_expect_success 'test sparse status again with untracked cache' '
538 avoid_racy &&
539 : >../trace &&
540 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
541 git status --porcelain >../status.actual &&
Elijah Newrence5c61a2020-04-01 04:17:35 +0000542 iuc status --porcelain >../status.iuc &&
David Turner76872522015-07-31 13:35:01 -0400543 cat >../status.expect <<EOF &&
David Turner2e5910f2015-08-19 20:01:25 +0700544 M done/two
David Turner76872522015-07-31 13:35:01 -0400545?? .gitignore
546?? done/five
547?? dtwo/
548EOF
Elijah Newrence5c61a2020-04-01 04:17:35 +0000549 test_cmp ../status.expect ../status.iuc &&
David Turner76872522015-07-31 13:35:01 -0400550 test_cmp ../status.expect ../status.actual &&
551 cat >../trace.expect <<EOF &&
552node creation: 0
553gitignore invalidation: 0
554directory invalidation: 0
555opendir: 0
556EOF
557 test_cmp ../trace.expect ../trace
558'
559
David Turner2e5910f2015-08-19 20:01:25 +0700560test_expect_success 'set up for test of subdir and sparse checkouts' '
561 mkdir done/sub &&
562 mkdir done/sub/sub &&
563 echo "sub" > done/sub/sub/file
564'
565
566test_expect_success 'test sparse status with untracked cache and subdir' '
567 avoid_racy &&
568 : >../trace &&
569 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
570 git status --porcelain >../status.actual &&
Elijah Newrence5c61a2020-04-01 04:17:35 +0000571 iuc status --porcelain >../status.iuc &&
David Turner2e5910f2015-08-19 20:01:25 +0700572 cat >../status.expect <<EOF &&
573 M done/two
574?? .gitignore
575?? done/five
576?? done/sub/
577?? dtwo/
578EOF
Elijah Newrence5c61a2020-04-01 04:17:35 +0000579 test_cmp ../status.expect ../status.iuc &&
David Turner2e5910f2015-08-19 20:01:25 +0700580 test_cmp ../status.expect ../status.actual &&
581 cat >../trace.expect <<EOF &&
582node creation: 2
583gitignore invalidation: 0
584directory invalidation: 1
585opendir: 3
586EOF
587 test_cmp ../trace.expect ../trace
588'
589
590test_expect_success 'verify untracked cache dump (sparse/subdirs)' '
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200591 test-tool dump-untracked-cache >../actual &&
Christian Couder7c121782016-01-27 07:58:07 +0100592 cat >../expect-from-test-dump <<EOF &&
brian m. carlson866be6e2020-07-29 23:14:00 +0000593info/exclude $(test_oid exclude)
594core.excludesfile $ZERO_OID
David Turner2e5910f2015-08-19 20:01:25 +0700595exclude_per_dir .gitignore
596flags 00000006
brian m. carlson866be6e2020-07-29 23:14:00 +0000597/ $(test_oid root) recurse valid
David Turner2e5910f2015-08-19 20:01:25 +0700598.gitignore
599dtwo/
brian m. carlson866be6e2020-07-29 23:14:00 +0000600/done/ $(test_oid done) recurse valid
David Turner2e5910f2015-08-19 20:01:25 +0700601five
602sub/
brian m. carlson866be6e2020-07-29 23:14:00 +0000603/done/sub/ $ZERO_OID recurse check_only valid
David Turner2e5910f2015-08-19 20:01:25 +0700604sub/
brian m. carlson866be6e2020-07-29 23:14:00 +0000605/done/sub/sub/ $ZERO_OID recurse check_only valid
David Turner2e5910f2015-08-19 20:01:25 +0700606file
brian m. carlson866be6e2020-07-29 23:14:00 +0000607/dthree/ $ZERO_OID recurse check_only valid
608/dtwo/ $ZERO_OID recurse check_only valid
David Turner2e5910f2015-08-19 20:01:25 +0700609two
610EOF
Christian Couder7c121782016-01-27 07:58:07 +0100611 test_cmp ../expect-from-test-dump ../actual
David Turner2e5910f2015-08-19 20:01:25 +0700612'
613
614test_expect_success 'test sparse status again with untracked cache and subdir' '
615 avoid_racy &&
616 : >../trace &&
617 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
618 git status --porcelain >../status.actual &&
Elijah Newrence5c61a2020-04-01 04:17:35 +0000619 iuc status --porcelain >../status.iuc &&
620 test_cmp ../status.expect ../status.iuc &&
David Turner2e5910f2015-08-19 20:01:25 +0700621 test_cmp ../status.expect ../status.actual &&
622 cat >../trace.expect <<EOF &&
623node creation: 0
624gitignore invalidation: 0
625directory invalidation: 0
626opendir: 0
627EOF
628 test_cmp ../trace.expect ../trace
629'
630
Nguyễn Thái Ngọc Duy73f91452015-08-19 20:01:26 +0700631test_expect_success 'move entry in subdir from untracked to cached' '
632 git add dtwo/two &&
633 git status --porcelain >../status.actual &&
Elijah Newrence5c61a2020-04-01 04:17:35 +0000634 iuc status --porcelain >../status.iuc &&
Nguyễn Thái Ngọc Duy73f91452015-08-19 20:01:26 +0700635 cat >../status.expect <<EOF &&
636 M done/two
637A dtwo/two
638?? .gitignore
639?? done/five
640?? done/sub/
641EOF
Elijah Newrence5c61a2020-04-01 04:17:35 +0000642 test_cmp ../status.expect ../status.iuc &&
Nguyễn Thái Ngọc Duy73f91452015-08-19 20:01:26 +0700643 test_cmp ../status.expect ../status.actual
644'
645
646test_expect_success 'move entry in subdir from cached to untracked' '
647 git rm --cached dtwo/two &&
648 git status --porcelain >../status.actual &&
Elijah Newrence5c61a2020-04-01 04:17:35 +0000649 iuc status --porcelain >../status.iuc &&
Nguyễn Thái Ngọc Duy73f91452015-08-19 20:01:26 +0700650 cat >../status.expect <<EOF &&
651 M done/two
652?? .gitignore
653?? done/five
654?? done/sub/
655?? dtwo/
656EOF
Elijah Newrence5c61a2020-04-01 04:17:35 +0000657 test_cmp ../status.expect ../status.iuc &&
Nguyễn Thái Ngọc Duy73f91452015-08-19 20:01:26 +0700658 test_cmp ../status.expect ../status.actual
659'
660
Christian Couder7c121782016-01-27 07:58:07 +0100661test_expect_success '--no-untracked-cache removes the cache' '
662 git update-index --no-untracked-cache &&
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200663 test-tool dump-untracked-cache >../actual &&
Christian Couder7c121782016-01-27 07:58:07 +0100664 echo "no untracked cache" >../expect-no-uc &&
665 test_cmp ../expect-no-uc ../actual
666'
667
668test_expect_success 'git status does not change anything' '
669 git status &&
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200670 test-tool dump-untracked-cache >../actual &&
Christian Couder7c121782016-01-27 07:58:07 +0100671 test_cmp ../expect-no-uc ../actual
672'
673
674test_expect_success 'setting core.untrackedCache to true and using git status creates the cache' '
675 git config core.untrackedCache true &&
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200676 test-tool dump-untracked-cache >../actual &&
Christian Couder7c121782016-01-27 07:58:07 +0100677 test_cmp ../expect-no-uc ../actual &&
678 git status &&
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200679 test-tool dump-untracked-cache >../actual &&
Christian Couder7c121782016-01-27 07:58:07 +0100680 test_cmp ../expect-from-test-dump ../actual
681'
682
683test_expect_success 'using --no-untracked-cache does not fail when core.untrackedCache is true' '
684 git update-index --no-untracked-cache &&
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200685 test-tool dump-untracked-cache >../actual &&
Christian Couder7c121782016-01-27 07:58:07 +0100686 test_cmp ../expect-no-uc ../actual &&
687 git update-index --untracked-cache &&
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200688 test-tool dump-untracked-cache >../actual &&
Christian Couder7c121782016-01-27 07:58:07 +0100689 test_cmp ../expect-empty ../actual
690'
691
692test_expect_success 'setting core.untrackedCache to false and using git status removes the cache' '
693 git config core.untrackedCache false &&
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200694 test-tool dump-untracked-cache >../actual &&
Christian Couder7c121782016-01-27 07:58:07 +0100695 test_cmp ../expect-empty ../actual &&
696 git status &&
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200697 test-tool dump-untracked-cache >../actual &&
Christian Couder7c121782016-01-27 07:58:07 +0100698 test_cmp ../expect-no-uc ../actual
699'
700
701test_expect_success 'using --untracked-cache does not fail when core.untrackedCache is false' '
702 git update-index --untracked-cache &&
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200703 test-tool dump-untracked-cache >../actual &&
Christian Couder7c121782016-01-27 07:58:07 +0100704 test_cmp ../expect-empty ../actual
705'
706
707test_expect_success 'setting core.untrackedCache to keep' '
708 git config core.untrackedCache keep &&
709 git update-index --untracked-cache &&
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200710 test-tool dump-untracked-cache >../actual &&
Christian Couder7c121782016-01-27 07:58:07 +0100711 test_cmp ../expect-empty ../actual &&
712 git status &&
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200713 test-tool dump-untracked-cache >../actual &&
Christian Couder7c121782016-01-27 07:58:07 +0100714 test_cmp ../expect-from-test-dump ../actual &&
715 git update-index --no-untracked-cache &&
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200716 test-tool dump-untracked-cache >../actual &&
Christian Couder7c121782016-01-27 07:58:07 +0100717 test_cmp ../expect-no-uc ../actual &&
718 git update-index --force-untracked-cache &&
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200719 test-tool dump-untracked-cache >../actual &&
Christian Couder7c121782016-01-27 07:58:07 +0100720 test_cmp ../expect-empty ../actual &&
721 git status &&
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200722 test-tool dump-untracked-cache >../actual &&
Christian Couder7c121782016-01-27 07:58:07 +0100723 test_cmp ../expect-from-test-dump ../actual
724'
725
726test_expect_success 'test ident field is working' '
727 mkdir ../other_worktree &&
728 cp -R done dthree dtwo four three ../other_worktree &&
729 GIT_WORK_TREE=../other_worktree git status 2>../err &&
Nguyễn Thái Ngọc Duy1a07e592018-07-21 09:49:19 +0200730 echo "warning: untracked cache is disabled on this system or location" >../expect &&
Vasco Almeida1edbaac2016-06-17 20:21:07 +0000731 test_i18ncmp ../expect ../err
Christian Couder7c121782016-01-27 07:58:07 +0100732'
733
David Turneredf3b902017-05-08 11:41:42 +0200734test_expect_success 'untracked cache survives a checkout' '
735 git commit --allow-empty -m empty &&
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200736 test-tool dump-untracked-cache >../before &&
David Turneredf3b902017-05-08 11:41:42 +0200737 test_when_finished "git checkout master" &&
738 git checkout -b other_branch &&
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200739 test-tool dump-untracked-cache >../after &&
David Turneredf3b902017-05-08 11:41:42 +0200740 test_cmp ../before ../after &&
741 test_commit test &&
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200742 test-tool dump-untracked-cache >../before &&
David Turneredf3b902017-05-08 11:41:42 +0200743 git checkout master &&
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200744 test-tool dump-untracked-cache >../after &&
David Turneredf3b902017-05-08 11:41:42 +0200745 test_cmp ../before ../after
746'
747
748test_expect_success 'untracked cache survives a commit' '
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200749 test-tool dump-untracked-cache >../before &&
David Turneredf3b902017-05-08 11:41:42 +0200750 git add done/two &&
751 git commit -m commit &&
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200752 test-tool dump-untracked-cache >../after &&
David Turneredf3b902017-05-08 11:41:42 +0200753 test_cmp ../before ../after
754'
755
Ævar Arnfjörð Bjarmasonce0330c2018-01-24 16:30:19 +0700756test_expect_success 'teardown worktree' '
757 cd ..
758'
759
760test_expect_success SYMLINKS 'setup worktree for symlink test' '
761 git init worktree-symlink &&
762 cd worktree-symlink &&
763 git config core.untrackedCache true &&
764 mkdir one two &&
765 touch one/file two/file &&
766 git add one/file two/file &&
767 git commit -m"first commit" &&
768 git rm -rf one &&
769 ln -s two one &&
770 git add one &&
771 git commit -m"second commit"
772'
773
Nguyễn Thái Ngọc Duyb6403132018-01-24 16:30:21 +0700774test_expect_success SYMLINKS '"status" after symlink replacement should be clean with UC=true' '
Ævar Arnfjörð Bjarmasonce0330c2018-01-24 16:30:19 +0700775 git checkout HEAD~ &&
776 status_is_clean &&
777 status_is_clean &&
778 git checkout master &&
779 avoid_racy &&
780 status_is_clean &&
781 status_is_clean
782'
783
784test_expect_success SYMLINKS '"status" after symlink replacement should be clean with UC=false' '
785 git config core.untrackedCache false &&
786 git checkout HEAD~ &&
787 status_is_clean &&
788 status_is_clean &&
789 git checkout master &&
790 avoid_racy &&
791 status_is_clean &&
792 status_is_clean
793'
794
795test_expect_success 'setup worktree for non-symlink test' '
796 git init worktree-non-symlink &&
797 cd worktree-non-symlink &&
798 git config core.untrackedCache true &&
799 mkdir one two &&
800 touch one/file two/file &&
801 git add one/file two/file &&
802 git commit -m"first commit" &&
803 git rm -rf one &&
804 cp two/file one &&
805 git add one &&
806 git commit -m"second commit"
807'
808
Nguyễn Thái Ngọc Duyb6403132018-01-24 16:30:21 +0700809test_expect_success '"status" after file replacement should be clean with UC=true' '
Ævar Arnfjörð Bjarmasonce0330c2018-01-24 16:30:19 +0700810 git checkout HEAD~ &&
811 status_is_clean &&
812 status_is_clean &&
813 git checkout master &&
814 avoid_racy &&
815 status_is_clean &&
Nguyễn Thái Ngọc Duycd780f02018-09-09 19:36:27 +0200816 test-tool dump-untracked-cache >../actual &&
Ævar Arnfjörð Bjarmasonce0330c2018-01-24 16:30:19 +0700817 grep -F "recurse valid" ../actual >../actual.grep &&
818 cat >../expect.grep <<EOF &&
brian m. carlson866be6e2020-07-29 23:14:00 +0000819/ $ZERO_OID recurse valid
820/two/ $ZERO_OID recurse valid
Ævar Arnfjörð Bjarmasonce0330c2018-01-24 16:30:19 +0700821EOF
822 status_is_clean &&
823 test_cmp ../expect.grep ../actual.grep
824'
825
826test_expect_success '"status" after file replacement should be clean with UC=false' '
827 git config core.untrackedCache false &&
828 git checkout HEAD~ &&
829 status_is_clean &&
830 status_is_clean &&
831 git checkout master &&
832 avoid_racy &&
833 status_is_clean &&
834 status_is_clean
835'
836
Nguyễn Thái Ngọc Duya3ddcef2015-03-08 17:12:44 +0700837test_done