]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7519-status-fsmonitor.sh
Merge branch 'ab/detox-gettext-tests'
[thirdparty/git.git] / t / t7519-status-fsmonitor.sh
CommitLineData
5c8cdcfd
BP
1#!/bin/sh
2
3test_description='git status with file system watcher'
4
5. ./test-lib.sh
6
5c8cdcfd
BP
7# Note, after "git reset --hard HEAD" no extensions exist other than 'TREE'
8# "git update-index --fsmonitor" can be used to get the extension written
9# before testing the results.
10
11clean_repo () {
12 git reset --hard HEAD &&
13 git clean -fd
14}
15
16dirty_repo () {
17 : >untracked &&
18 : >dir1/untracked &&
19 : >dir2/untracked &&
20 echo 1 >modified &&
21 echo 2 >dir1/modified &&
22 echo 3 >dir2/modified &&
23 echo 4 >new &&
24 echo 5 >dir1/new &&
25 echo 6 >dir2/new
26}
27
28write_integration_script () {
29 write_script .git/hooks/fsmonitor-test<<-\EOF
30 if test "$#" -ne 2
31 then
32 echo "$0: exactly 2 arguments expected"
33 exit 2
34 fi
8da2c576 35 if test "$1" != 2
5c8cdcfd
BP
36 then
37 echo "Unsupported core.fsmonitor hook version." >&2
38 exit 1
39 fi
8da2c576 40 printf "last_update_token\0"
5c8cdcfd
BP
41 printf "untracked\0"
42 printf "dir1/untracked\0"
43 printf "dir2/untracked\0"
44 printf "modified\0"
45 printf "dir1/modified\0"
46 printf "dir2/modified\0"
47 printf "new\0"
48 printf "dir1/new\0"
49 printf "dir2/new\0"
50 EOF
51}
52
53test_lazy_prereq UNTRACKED_CACHE '
54 { git update-index --test-untracked-cache; ret=$?; } &&
55 test $ret -ne 1
56'
57
58test_expect_success 'setup' '
59 mkdir -p .git/hooks &&
60 : >tracked &&
61 : >modified &&
62 mkdir dir1 &&
63 : >dir1/tracked &&
64 : >dir1/modified &&
65 mkdir dir2 &&
66 : >dir2/tracked &&
67 : >dir2/modified &&
68 git -c core.fsmonitor= add . &&
69 git -c core.fsmonitor= commit -m initial &&
70 git config core.fsmonitor .git/hooks/fsmonitor-test &&
71 cat >.gitignore <<-\EOF
72 .gitignore
73 expect*
74 actual*
75 marker*
76 EOF
77'
78
79# test that the fsmonitor extension is off by default
80test_expect_success 'fsmonitor extension is off by default' '
f1ef0b02 81 test-tool dump-fsmonitor >actual &&
5c8cdcfd
BP
82 grep "^no fsmonitor" actual
83'
84
85# test that "update-index --fsmonitor" adds the fsmonitor extension
86test_expect_success 'update-index --fsmonitor" adds the fsmonitor extension' '
87 git update-index --fsmonitor &&
f1ef0b02 88 test-tool dump-fsmonitor >actual &&
5c8cdcfd
BP
89 grep "^fsmonitor last update" actual
90'
91
92# test that "update-index --no-fsmonitor" removes the fsmonitor extension
93test_expect_success 'update-index --no-fsmonitor" removes the fsmonitor extension' '
94 git update-index --no-fsmonitor &&
f1ef0b02 95 test-tool dump-fsmonitor >actual &&
5c8cdcfd
BP
96 grep "^no fsmonitor" actual
97'
98
99cat >expect <<EOF &&
100h dir1/modified
101H dir1/tracked
102h dir2/modified
103H dir2/tracked
104h modified
105H tracked
106EOF
107
108# test that "update-index --fsmonitor-valid" sets the fsmonitor valid bit
109test_expect_success 'update-index --fsmonitor-valid" sets the fsmonitor valid bit' '
679f2f9f 110 write_script .git/hooks/fsmonitor-test<<-\EOF &&
8da2c576 111 printf "last_update_token\0"
679f2f9f 112 EOF
5c8cdcfd
BP
113 git update-index --fsmonitor &&
114 git update-index --fsmonitor-valid dir1/modified &&
115 git update-index --fsmonitor-valid dir2/modified &&
116 git update-index --fsmonitor-valid modified &&
117 git ls-files -f >actual &&
118 test_cmp expect actual
119'
120
121cat >expect <<EOF &&
122H dir1/modified
123H dir1/tracked
124H dir2/modified
125H dir2/tracked
126H modified
127H tracked
128EOF
129
130# test that "update-index --no-fsmonitor-valid" clears the fsmonitor valid bit
131test_expect_success 'update-index --no-fsmonitor-valid" clears the fsmonitor valid bit' '
132 git update-index --no-fsmonitor-valid dir1/modified &&
133 git update-index --no-fsmonitor-valid dir2/modified &&
134 git update-index --no-fsmonitor-valid modified &&
135 git ls-files -f >actual &&
136 test_cmp expect actual
137'
138
139cat >expect <<EOF &&
140H dir1/modified
141H dir1/tracked
142H dir2/modified
143H dir2/tracked
144H modified
145H tracked
146EOF
147
148# test that all files returned by the script get flagged as invalid
149test_expect_success 'all files returned by integration script get flagged as invalid' '
150 write_integration_script &&
151 dirty_repo &&
152 git update-index --fsmonitor &&
153 git ls-files -f >actual &&
154 test_cmp expect actual
155'
156
157cat >expect <<EOF &&
158H dir1/modified
159h dir1/new
160H dir1/tracked
161H dir2/modified
162h dir2/new
163H dir2/tracked
164H modified
165h new
166H tracked
167EOF
168
169# test that newly added files are marked valid
170test_expect_success 'newly added files are marked valid' '
679f2f9f 171 write_script .git/hooks/fsmonitor-test<<-\EOF &&
8da2c576 172 printf "last_update_token\0"
679f2f9f 173 EOF
5c8cdcfd
BP
174 git add new &&
175 git add dir1/new &&
176 git add dir2/new &&
177 git ls-files -f >actual &&
178 test_cmp expect actual
179'
180
181cat >expect <<EOF &&
182H dir1/modified
183h dir1/new
184h dir1/tracked
185H dir2/modified
186h dir2/new
187h dir2/tracked
188H modified
189h new
190h tracked
191EOF
192
193# test that all unmodified files get marked valid
194test_expect_success 'all unmodified files get marked valid' '
195 # modified files result in update-index returning 1
196 test_must_fail git update-index --refresh --force-write-index &&
197 git ls-files -f >actual &&
198 test_cmp expect actual
199'
200
201cat >expect <<EOF &&
202H dir1/modified
203h dir1/tracked
204h dir2/modified
205h dir2/tracked
206h modified
207h tracked
208EOF
209
210# test that *only* files returned by the integration script get flagged as invalid
211test_expect_success '*only* files returned by the integration script get flagged as invalid' '
212 write_script .git/hooks/fsmonitor-test<<-\EOF &&
8da2c576 213 printf "last_update_token\0"
5c8cdcfd
BP
214 printf "dir1/modified\0"
215 EOF
216 clean_repo &&
217 git update-index --refresh --force-write-index &&
218 echo 1 >modified &&
219 echo 2 >dir1/modified &&
220 echo 3 >dir2/modified &&
221 test_must_fail git update-index --refresh --force-write-index &&
222 git ls-files -f >actual &&
223 test_cmp expect actual
224'
225
226# Ensure commands that call refresh_index() to move the index back in time
227# properly invalidate the fsmonitor cache
228test_expect_success 'refresh_index() invalidates fsmonitor cache' '
5c8cdcfd
BP
229 clean_repo &&
230 dirty_repo &&
679f2f9f 231 write_integration_script &&
5c8cdcfd 232 git add . &&
679f2f9f
US
233 write_script .git/hooks/fsmonitor-test<<-\EOF &&
234 EOF
5c8cdcfd
BP
235 git commit -m "to reset" &&
236 git reset HEAD~1 &&
237 git status >actual &&
238 git -c core.fsmonitor= status >expect &&
1108cea7 239 test_cmp expect actual
5c8cdcfd
BP
240'
241
242# test fsmonitor with and without preloadIndex
243preload_values="false true"
244for preload_val in $preload_values
245do
246 test_expect_success "setup preloadIndex to $preload_val" '
247 git config core.preloadIndex $preload_val &&
248 if test $preload_val = true
249 then
5765d97b 250 GIT_TEST_PRELOAD_INDEX=$preload_val; export GIT_TEST_PRELOAD_INDEX
5c8cdcfd 251 else
5765d97b 252 sane_unset GIT_TEST_PRELOAD_INDEX
5c8cdcfd
BP
253 fi
254 '
255
256 # test fsmonitor with and without the untracked cache (if available)
257 uc_values="false"
258 test_have_prereq UNTRACKED_CACHE && uc_values="false true"
259 for uc_val in $uc_values
260 do
261 test_expect_success "setup untracked cache to $uc_val" '
262 git config core.untrackedcache $uc_val
263 '
264
265 # Status is well tested elsewhere so we'll just ensure that the results are
266 # the same when using core.fsmonitor.
267 test_expect_success 'compare status with and without fsmonitor' '
268 write_integration_script &&
269 clean_repo &&
270 dirty_repo &&
271 git add new &&
272 git add dir1/new &&
273 git add dir2/new &&
274 git status >actual &&
275 git -c core.fsmonitor= status >expect &&
1108cea7 276 test_cmp expect actual
5c8cdcfd
BP
277 '
278
279 # Make sure it's actually skipping the check for modified and untracked
280 # (if enabled) files unless it is told about them.
281 test_expect_success "status doesn't detect unreported modifications" '
282 write_script .git/hooks/fsmonitor-test<<-\EOF &&
8da2c576 283 printf "last_update_token\0"
5c8cdcfd
BP
284 :>marker
285 EOF
286 clean_repo &&
287 git status &&
288 test_path_is_file marker &&
289 dirty_repo &&
290 rm -f marker &&
291 git status >actual &&
292 test_path_is_file marker &&
293 test_i18ngrep ! "Changes not staged for commit:" actual &&
294 if test $uc_val = true
295 then
296 test_i18ngrep ! "Untracked files:" actual
297 fi &&
298 if test $uc_val = false
299 then
300 test_i18ngrep "Untracked files:" actual
301 fi &&
302 rm -f marker
303 '
304 done
305done
306
7a40cf15 307# test that splitting the index doesn't interfere
3bd28eb2
AV
308test_expect_success 'splitting the index results in the same state' '
309 write_integration_script &&
310 dirty_repo &&
311 git update-index --fsmonitor &&
312 git ls-files -f >expect &&
f1ef0b02 313 test-tool dump-fsmonitor >&2 && echo &&
3bd28eb2 314 git update-index --fsmonitor --split-index &&
f1ef0b02 315 test-tool dump-fsmonitor >&2 && echo &&
3bd28eb2
AV
316 git ls-files -f >actual &&
317 test_cmp expect actual
318'
319
0cacebf0
NTND
320test_expect_success UNTRACKED_CACHE 'ignore .git changes when invalidating UNTR' '
321 test_create_repo dot-git &&
322 (
323 cd dot-git &&
324 mkdir -p .git/hooks &&
325 : >tracked &&
326 : >modified &&
327 mkdir dir1 &&
328 : >dir1/tracked &&
329 : >dir1/modified &&
330 mkdir dir2 &&
331 : >dir2/tracked &&
332 : >dir2/modified &&
333 write_integration_script &&
334 git config core.fsmonitor .git/hooks/fsmonitor-test &&
335 git update-index --untracked-cache &&
336 git update-index --fsmonitor &&
337 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace-before" \
338 git status &&
cd780f0b 339 test-tool dump-untracked-cache >../before
0cacebf0
NTND
340 ) &&
341 cat >>dot-git/.git/hooks/fsmonitor-test <<-\EOF &&
342 printf ".git\0"
343 printf ".git/index\0"
344 printf "dir1/.git\0"
345 printf "dir1/.git/index\0"
346 EOF
347 (
348 cd dot-git &&
349 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace-after" \
350 git status &&
cd780f0b 351 test-tool dump-untracked-cache >../after
0cacebf0
NTND
352 ) &&
353 grep "directory invalidation" trace-before >>before &&
354 grep "directory invalidation" trace-after >>after &&
355 # UNTR extension unchanged, dir invalidation count unchanged
356 test_cmp before after
357'
358
398a3b08 359test_expect_success 'discard_index() also discards fsmonitor info' '
dc76852d
JS
360 test_config core.fsmonitor "$TEST_DIRECTORY/t7519/fsmonitor-all" &&
361 test_might_fail git update-index --refresh &&
362 test-tool read-cache --print-and-refresh=tracked 2 >actual &&
363 printf "tracked is%s up to date\n" "" " not" >expect &&
364 test_cmp expect actual
365'
366
460782b7
WB
367# Test unstaging entries that:
368# - Are not flagged with CE_FSMONITOR_VALID
369# - Have a position in the index >= the number of entries present in the index
370# after unstaging.
371test_expect_success 'status succeeds after staging/unstaging' '
3444ec2e
WB
372 test_create_repo fsmonitor-stage-unstage &&
373 (
374 cd fsmonitor-stage-unstage &&
375 test_commit initial &&
376 git update-index --fsmonitor &&
377 removed=$(test_seq 1 100 | sed "s/^/z/") &&
378 touch $removed &&
379 git add $removed &&
380 git config core.fsmonitor "$TEST_DIRECTORY/t7519/fsmonitor-env" &&
381 FSMONITOR_LIST="$removed" git restore -S $removed &&
382 FSMONITOR_LIST="$removed" git status
383 )
384'
385
5c8cdcfd 386test_done