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
40 printf "last_update_token\0"
42 printf "dir1/untracked\0"
43 printf "dir2/untracked\0"
45 printf "dir1/modified\0"
46 printf "dir2/modified\0"
53 test_lazy_prereq UNTRACKED_CACHE '
54 { git update-index --test-untracked-cache; ret=$?; } &&
58 test_expect_success 'setup' '
59 mkdir -p .git/hooks &&
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
79 # test that the fsmonitor extension is off by default
80 test_expect_success 'fsmonitor extension is off by default' '
81 test-tool dump-fsmonitor >actual &&
82 grep "^no fsmonitor" actual
85 # test that "update-index --fsmonitor" adds the fsmonitor extension
86 test_expect_success 'update-index --fsmonitor" adds the fsmonitor extension' '
87 git update-index --fsmonitor &&
88 test-tool dump-fsmonitor >actual &&
89 grep "^fsmonitor last update" actual
92 # test that "update-index --no-fsmonitor" removes the fsmonitor extension
93 test_expect_success 'update-index --no-fsmonitor" removes the fsmonitor extension' '
94 git update-index --no-fsmonitor &&
95 test-tool dump-fsmonitor >actual &&
96 grep "^no fsmonitor" actual
108 # test that "update-index --fsmonitor-valid" sets the fsmonitor valid bit
109 test_expect_success 'update-index --fsmonitor-valid" sets the fsmonitor valid bit' '
110 write_script .git/hooks/fsmonitor-test<<-\EOF &&
111 printf "last_update_token\0"
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
130 # test that "update-index --no-fsmonitor-valid" clears the fsmonitor valid bit
131 test_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
148 # test that all files returned by the script get flagged as invalid
149 test_expect_success 'all files returned by integration script get flagged as invalid' '
150 write_integration_script &&
152 git update-index --fsmonitor &&
153 git ls-files -f >actual &&
154 test_cmp expect actual
169 # test that newly added files are marked valid
170 test_expect_success 'newly added files are marked valid' '
171 write_script .git/hooks/fsmonitor-test<<-\EOF &&
172 printf "last_update_token\0"
177 git ls-files -f >actual &&
178 test_cmp expect actual
193 # test that all unmodified files get marked valid
194 test_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
210 # test that *only* files returned by the integration script get flagged as invalid
211 test_expect_success '*only* files returned by the integration script get flagged as invalid' '
212 write_script .git/hooks/fsmonitor-test<<-\EOF &&
213 printf "last_update_token\0"
214 printf "dir1/modified\0"
217 git update-index --refresh --force-write-index &&
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
226 # Ensure commands that call refresh_index() to move the index back in time
227 # properly invalidate the fsmonitor cache
228 test_expect_success 'refresh_index() invalidates fsmonitor cache' '
231 write_integration_script &&
233 write_script .git/hooks/fsmonitor-test<<-\EOF &&
235 git commit -m "to reset" &&
237 git status >actual &&
238 git -c core.fsmonitor= status >expect &&
239 test_i18ncmp expect actual
242 # test fsmonitor with and without preloadIndex
243 preload_values="false true"
244 for preload_val in $preload_values
246 test_expect_success "setup preloadIndex to $preload_val" '
247 git config core.preloadIndex $preload_val &&
248 if test $preload_val = true
250 GIT_TEST_PRELOAD_INDEX=$preload_val; export GIT_TEST_PRELOAD_INDEX
252 sane_unset GIT_TEST_PRELOAD_INDEX
256 # test fsmonitor with and without the untracked cache (if available)
258 test_have_prereq UNTRACKED_CACHE && uc_values="false true"
259 for uc_val in $uc_values
261 test_expect_success "setup untracked cache to $uc_val" '
262 git config core.untrackedcache $uc_val
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 &&
274 git status >actual &&
275 git -c core.fsmonitor= status >expect &&
276 test_i18ncmp expect actual
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 &&
283 printf "last_update_token\0"
288 test_path_is_file 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
296 test_i18ngrep ! "Untracked files:" actual
298 if test $uc_val = false
300 test_i18ngrep "Untracked files:" actual
307 # test that splitting the index doesn't interfere
308 test_expect_success 'splitting the index results in the same state' '
309 write_integration_script &&
311 git update-index --fsmonitor &&
312 git ls-files -f >expect &&
313 test-tool dump-fsmonitor >&2 && echo &&
314 git update-index --fsmonitor --split-index &&
315 test-tool dump-fsmonitor >&2 && echo &&
316 git ls-files -f >actual &&
317 test_cmp expect actual
320 test_expect_success UNTRACKED_CACHE 'ignore .git changes when invalidating UNTR' '
321 test_create_repo dot-git &&
324 mkdir -p .git/hooks &&
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" \
339 test-tool dump-untracked-cache >../before
341 cat >>dot-git/.git/hooks/fsmonitor-test <<-\EOF &&
343 printf ".git/index\0"
345 printf "dir1/.git/index\0"
349 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace-after" \
351 test-tool dump-untracked-cache >../after
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
359 test_expect_success 'discard_index() also discards fsmonitor info' '
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
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
371 test_expect_success 'status succeeds after staging/unstaging' '
372 test_create_repo fsmonitor-stage-unstage &&
374 cd fsmonitor-stage-unstage &&
375 test_commit initial &&
376 git update-index --fsmonitor &&
377 removed=$(test_seq 1 100 | sed "s/^/z/") &&
380 git config core.fsmonitor "$TEST_DIRECTORY/t7519/fsmonitor-env" &&
381 FSMONITOR_LIST="$removed" git restore -S $removed &&
382 FSMONITOR_LIST="$removed" git status