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 git update-index --fsmonitor &&
110 git update-index --fsmonitor-valid dir1/modified &&
111 git update-index --fsmonitor-valid dir2/modified &&
112 git update-index --fsmonitor-valid modified &&
113 git ls-files -f >actual &&
114 test_cmp expect actual
126 # test that "update-index --no-fsmonitor-valid" clears the fsmonitor valid bit
127 test_expect_success 'update-index --no-fsmonitor-valid" clears the fsmonitor valid bit' '
128 git update-index --no-fsmonitor-valid dir1/modified &&
129 git update-index --no-fsmonitor-valid dir2/modified &&
130 git update-index --no-fsmonitor-valid modified &&
131 git ls-files -f >actual &&
132 test_cmp expect actual
144 # test that all files returned by the script get flagged as invalid
145 test_expect_success 'all files returned by integration script get flagged as invalid' '
146 write_integration_script &&
148 git update-index --fsmonitor &&
149 git ls-files -f >actual &&
150 test_cmp expect actual
165 # test that newly added files are marked valid
166 test_expect_success 'newly added files are marked valid' '
170 git ls-files -f >actual &&
171 test_cmp expect actual
186 # test that all unmodified files get marked valid
187 test_expect_success 'all unmodified files get marked valid' '
188 # modified files result in update-index returning 1
189 test_must_fail git update-index --refresh --force-write-index &&
190 git ls-files -f >actual &&
191 test_cmp expect actual
203 # test that *only* files returned by the integration script get flagged as invalid
204 test_expect_success '*only* files returned by the integration script get flagged as invalid' '
205 write_script .git/hooks/fsmonitor-test<<-\EOF &&
206 printf "dir1/modified\0"
209 git update-index --refresh --force-write-index &&
211 echo 2 >dir1/modified &&
212 echo 3 >dir2/modified &&
213 test_must_fail git update-index --refresh --force-write-index &&
214 git ls-files -f >actual &&
215 test_cmp expect actual
218 # Ensure commands that call refresh_index() to move the index back in time
219 # properly invalidate the fsmonitor cache
220 test_expect_success 'refresh_index() invalidates fsmonitor cache' '
221 write_script .git/hooks/fsmonitor-test<<-\EOF &&
226 git commit -m "to reset" &&
228 git status >actual &&
229 git -c core.fsmonitor= status >expect &&
230 test_i18ncmp expect actual
233 # test fsmonitor with and without preloadIndex
234 preload_values="false true"
235 for preload_val in $preload_values
237 test_expect_success "setup preloadIndex to $preload_val" '
238 git config core.preloadIndex $preload_val &&
239 if test $preload_val = true
241 GIT_TEST_PRELOAD_INDEX=$preload_val; export GIT_TEST_PRELOAD_INDEX
243 sane_unset GIT_TEST_PRELOAD_INDEX
247 # test fsmonitor with and without the untracked cache (if available)
249 test_have_prereq UNTRACKED_CACHE && uc_values="false true"
250 for uc_val in $uc_values
252 test_expect_success "setup untracked cache to $uc_val" '
253 git config core.untrackedcache $uc_val
256 # Status is well tested elsewhere so we'll just ensure that the results are
257 # the same when using core.fsmonitor.
258 test_expect_success 'compare status with and without fsmonitor' '
259 write_integration_script &&
265 git status >actual &&
266 git -c core.fsmonitor= status >expect &&
267 test_i18ncmp expect actual
270 # Make sure it's actually skipping the check for modified and untracked
271 # (if enabled) files unless it is told about them.
272 test_expect_success "status doesn't detect unreported modifications" '
273 write_script .git/hooks/fsmonitor-test<<-\EOF &&
278 test_path_is_file marker &&
281 git status >actual &&
282 test_path_is_file marker &&
283 test_i18ngrep ! "Changes not staged for commit:" actual &&
284 if test $uc_val = true
286 test_i18ngrep ! "Untracked files:" actual
288 if test $uc_val = false
290 test_i18ngrep "Untracked files:" actual
297 # test that splitting the index dosn't interfere
298 test_expect_success 'splitting the index results in the same state' '
299 write_integration_script &&
301 git update-index --fsmonitor &&
302 git ls-files -f >expect &&
303 test-tool dump-fsmonitor >&2 && echo &&
304 git update-index --fsmonitor --split-index &&
305 test-tool dump-fsmonitor >&2 && echo &&
306 git ls-files -f >actual &&
307 test_cmp expect actual
310 test_expect_success UNTRACKED_CACHE 'ignore .git changes when invalidating UNTR' '
311 test_create_repo dot-git &&
314 mkdir -p .git/hooks &&
323 write_integration_script &&
324 git config core.fsmonitor .git/hooks/fsmonitor-test &&
325 git update-index --untracked-cache &&
326 git update-index --fsmonitor &&
327 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace-before" \
329 test-tool dump-untracked-cache >../before
331 cat >>dot-git/.git/hooks/fsmonitor-test <<-\EOF &&
333 printf ".git/index\0"
335 printf "dir1/.git/index\0"
339 GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace-after" \
341 test-tool dump-untracked-cache >../after
343 grep "directory invalidation" trace-before >>before &&
344 grep "directory invalidation" trace-after >>after &&
345 # UNTR extension unchanged, dir invalidation count unchanged
346 test_cmp before after
349 test_expect_success 'discard_index() also discards fsmonitor info' '
350 test_config core.fsmonitor "$TEST_DIRECTORY/t7519/fsmonitor-all" &&
351 test_might_fail git update-index --refresh &&
352 test-tool read-cache --print-and-refresh=tracked 2 >actual &&
353 printf "tracked is%s up to date\n" "" " not" >expect &&
354 test_cmp expect actual