3 test_description='git status with file system watcher'
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.
12 git reset --hard HEAD &&
21 echo 2 >dir1/modified &&
22 echo 3 >dir2/modified &&
28 write_integration_script () {
29 write_script .git/hooks/fsmonitor-test<<-\EOF
32 echo "$0: exactly 2 arguments expected"
37 echo "Unsupported core.fsmonitor hook version." >&2
41 printf "dir1/untracked\0"
42 printf "dir2/untracked\0"
44 printf "dir1/modified\0"
45 printf "dir2/modified\0"
52 test_lazy_prereq UNTRACKED_CACHE '
53 { git update-index --test-untracked-cache; ret=$?; } &&
57 test_expect_success 'setup' '
58 mkdir -p .git/hooks &&
67 git -c core.fsmonitor= add . &&
68 git -c core.fsmonitor= commit -m initial &&
69 git config core.fsmonitor .git/hooks/fsmonitor-test &&
70 cat >.gitignore <<-\EOF
78 # test that the fsmonitor extension is off by default
79 test_expect_success 'fsmonitor extension is off by default' '
80 test-tool dump-fsmonitor >actual &&
81 grep "^no fsmonitor" actual
84 # test that "update-index --fsmonitor" adds the fsmonitor extension
85 test_expect_success 'update-index --fsmonitor" adds the fsmonitor extension' '
86 git update-index --fsmonitor &&
87 test-tool dump-fsmonitor >actual &&
88 grep "^fsmonitor last update" actual
91 # test that "update-index --no-fsmonitor" removes the fsmonitor extension
92 test_expect_success 'update-index --no-fsmonitor" removes the fsmonitor extension' '
93 git update-index --no-fsmonitor &&
94 test-tool dump-fsmonitor >actual &&
95 grep "^no fsmonitor" actual
107 # test that "update-index --fsmonitor-valid" sets the fsmonitor valid bit
108 test_expect_success 'update-index --fsmonitor-valid" sets the fsmonitor valid bit' '
109 write_script .git/hooks/fsmonitor-test<<-\EOF &&
111 git update-index --fsmonitor &&
112 git update-index --fsmonitor-valid dir1/modified &&
113 git update-index --fsmonitor-valid dir2/modified &&
114 git update-index --fsmonitor-valid modified &&
115 git ls-files -f >actual &&
116 test_cmp expect actual
128 # test that "update-index --no-fsmonitor-valid" clears the fsmonitor valid bit
129 test_expect_success 'update-index --no-fsmonitor-valid" clears the fsmonitor valid bit' '
130 git update-index --no-fsmonitor-valid dir1/modified &&
131 git update-index --no-fsmonitor-valid dir2/modified &&
132 git update-index --no-fsmonitor-valid modified &&
133 git ls-files -f >actual &&
134 test_cmp expect actual
146 # test that all files returned by the script get flagged as invalid
147 test_expect_success 'all files returned by integration script get flagged as invalid' '
148 write_integration_script &&
150 git update-index --fsmonitor &&
151 git ls-files -f >actual &&
152 test_cmp expect actual
167 # test that newly added files are marked valid
168 test_expect_success 'newly added files are marked valid' '
169 write_script .git/hooks/fsmonitor-test<<-\EOF &&
174 git ls-files -f >actual &&
175 test_cmp expect actual
190 # test that all unmodified files get marked valid
191 test_expect_success 'all unmodified files get marked valid' '
192 # modified files result in update-index returning 1
193 test_must_fail git update-index --refresh --force-write-index &&
194 git ls-files -f >actual &&
195 test_cmp expect actual
207 # test that *only* files returned by the integration script get flagged as invalid
208 test_expect_success '*only* files returned by the integration script get flagged as invalid' '
209 write_script .git/hooks/fsmonitor-test<<-\EOF &&
210 printf "dir1/modified\0"
213 git update-index --refresh --force-write-index &&
215 echo 2 >dir1/modified &&
216 echo 3 >dir2/modified &&
217 test_must_fail git update-index --refresh --force-write-index &&
218 git ls-files -f >actual &&
219 test_cmp expect actual
222 # Ensure commands that call refresh_index() to move the index back in time
223 # properly invalidate the fsmonitor cache
224 test_expect_success 'refresh_index() invalidates fsmonitor cache' '
227 write_integration_script &&
229 write_script .git/hooks/fsmonitor-test<<-\EOF &&
231 git commit -m "to reset" &&
233 git status >actual &&
234 git -c core.fsmonitor= status >expect &&
235 test_i18ncmp expect actual
238 # test fsmonitor with and without preloadIndex
239 preload_values="false true"
240 for preload_val in $preload_values
242 test_expect_success "setup preloadIndex to $preload_val" '
243 git config core.preloadIndex $preload_val &&
244 if test $preload_val = true
246 GIT_TEST_PRELOAD_INDEX=$preload_val; export GIT_TEST_PRELOAD_INDEX
248 sane_unset GIT_TEST_PRELOAD_INDEX
252 # test fsmonitor with and without the untracked cache (if available)
254 test_have_prereq UNTRACKED_CACHE && uc_values="false true"
255 for uc_val in $uc_values
257 test_expect_success "setup untracked cache to $uc_val" '
258 git config core.untrackedcache $uc_val
261 # Status is well tested elsewhere so we'll just ensure that the results are
262 # the same when using core.fsmonitor.
263 test_expect_success 'compare status with and without fsmonitor' '
264 write_integration_script &&
270 git status >actual &&
271 git -c core.fsmonitor= status >expect &&
272 test_i18ncmp expect actual
275 # Make sure it's actually skipping the check for modified and untracked
276 # (if enabled) files unless it is told about them.
277 test_expect_success "status doesn't detect unreported modifications" '
278 write_script .git/hooks/fsmonitor-test<<-\EOF &&
283 test_path_is_file marker &&
286 git status >actual &&
287 test_path_is_file marker &&
288 test_i18ngrep ! "Changes not staged for commit:" actual &&
289 if test $uc_val = true
291 test_i18ngrep ! "Untracked files:" actual
293 if test $uc_val = false
295 test_i18ngrep "Untracked files:" actual
302 # test that splitting the index doesn't interfere
303 test_expect_success 'splitting the index results in the same state' '
304 write_integration_script &&
306 git update-index --fsmonitor &&
307 git ls-files -f >expect &&
308 test-tool dump-fsmonitor >&2 && echo &&
309 git update-index --fsmonitor --split-index &&
310 test-tool dump-fsmonitor >&2 && echo &&
311 git ls-files -f >actual &&
312 test_cmp expect actual
315 test_expect_success UNTRACKED_CACHE 'ignore .git changes when invalidating UNTR' '
316 test_create_repo dot-git &&
319 mkdir -p .git/hooks &&
328 write_integration_script &&
329 git config core.fsmonitor .git/hooks/fsmonitor-test &&
330 git update-index --untracked-cache &&
331 git update-index --fsmonitor &&
332 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace-before" \
334 test-tool dump-untracked-cache >../before
336 cat >>dot-git/.git/hooks/fsmonitor-test <<-\EOF &&
338 printf ".git/index\0"
340 printf "dir1/.git/index\0"
344 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace-after" \
346 test-tool dump-untracked-cache >../after
348 grep "directory invalidation" trace-before >>before &&
349 grep "directory invalidation" trace-after >>after &&
350 # UNTR extension unchanged, dir invalidation count unchanged
351 test_cmp before after
354 test_expect_success 'discard_index() also discards fsmonitor info' '
355 test_config core.fsmonitor "$TEST_DIRECTORY/t7519/fsmonitor-all" &&
356 test_might_fail git update-index --refresh &&
357 test-tool read-cache --print-and-refresh=tracked 2 >actual &&
358 printf "tracked is%s up to date\n" "" " not" >expect &&
359 test_cmp expect actual
362 # Test unstaging entries that:
363 # - Are not flagged with CE_FSMONITOR_VALID
364 # - Have a position in the index >= the number of entries present in the index
366 test_expect_success 'status succeeds after staging/unstaging' '
367 test_create_repo fsmonitor-stage-unstage &&
369 cd fsmonitor-stage-unstage &&
370 test_commit initial &&
371 git update-index --fsmonitor &&
372 removed=$(test_seq 1 100 | sed "s/^/z/") &&
375 git config core.fsmonitor "$TEST_DIRECTORY/t7519/fsmonitor-env" &&
376 FSMONITOR_LIST="$removed" git restore -S $removed &&
377 FSMONITOR_LIST="$removed" git status