3 test_description='git status with file system watcher'
8 # To run the entire git test suite using fsmonitor:
10 # copy t/t7519/fsmonitor-all to a location in your path and then set
11 # GIT_FSMONITOR_TEST=fsmonitor-all and run your tests.
14 # Note, after "git reset --hard HEAD" no extensions exist other than 'TREE'
15 # "git update-index --fsmonitor" can be used to get the extension written
16 # before testing the results.
19 git reset --hard HEAD &&
28 echo 2 >dir1/modified &&
29 echo 3 >dir2/modified &&
35 write_integration_script () {
36 write_script .git/hooks/fsmonitor-test<<-\EOF
39 echo "$0: exactly 2 arguments expected"
44 echo "Unsupported core.fsmonitor hook version." >&2
48 printf "dir1/untracked\0"
49 printf "dir2/untracked\0"
51 printf "dir1/modified\0"
52 printf "dir2/modified\0"
59 test_lazy_prereq UNTRACKED_CACHE '
60 { git update-index --test-untracked-cache; ret=$?; } &&
64 test_expect_success 'setup' '
65 mkdir -p .git/hooks &&
74 git -c core.fsmonitor= add . &&
75 git -c core.fsmonitor= commit -m initial &&
76 git config core.fsmonitor .git/hooks/fsmonitor-test &&
77 cat >.gitignore <<-\EOF
85 # test that the fsmonitor extension is off by default
86 test_expect_success 'fsmonitor extension is off by default' '
87 test-dump-fsmonitor >actual &&
88 grep "^no fsmonitor" actual
91 # test that "update-index --fsmonitor" adds the fsmonitor extension
92 test_expect_success 'update-index --fsmonitor" adds the fsmonitor extension' '
93 git update-index --fsmonitor &&
94 test-dump-fsmonitor >actual &&
95 grep "^fsmonitor last update" actual
98 # test that "update-index --no-fsmonitor" removes the fsmonitor extension
99 test_expect_success 'update-index --no-fsmonitor" removes the fsmonitor extension' '
100 git update-index --no-fsmonitor &&
101 test-dump-fsmonitor >actual &&
102 grep "^no fsmonitor" actual
114 # test that "update-index --fsmonitor-valid" sets the fsmonitor valid bit
115 test_expect_success 'update-index --fsmonitor-valid" sets the fsmonitor valid bit' '
116 git update-index --fsmonitor &&
117 git update-index --fsmonitor-valid dir1/modified &&
118 git update-index --fsmonitor-valid dir2/modified &&
119 git update-index --fsmonitor-valid modified &&
120 git ls-files -f >actual &&
121 test_cmp expect actual
133 # test that "update-index --no-fsmonitor-valid" clears the fsmonitor valid bit
134 test_expect_success 'update-index --no-fsmonitor-valid" clears the fsmonitor valid bit' '
135 git update-index --no-fsmonitor-valid dir1/modified &&
136 git update-index --no-fsmonitor-valid dir2/modified &&
137 git update-index --no-fsmonitor-valid modified &&
138 git ls-files -f >actual &&
139 test_cmp expect actual
151 # test that all files returned by the script get flagged as invalid
152 test_expect_success 'all files returned by integration script get flagged as invalid' '
153 write_integration_script &&
155 git update-index --fsmonitor &&
156 git ls-files -f >actual &&
157 test_cmp expect actual
172 # test that newly added files are marked valid
173 test_expect_success 'newly added files are marked valid' '
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 "dir1/modified\0"
216 git update-index --refresh --force-write-index &&
218 echo 2 >dir1/modified &&
219 echo 3 >dir2/modified &&
220 test_must_fail git update-index --refresh --force-write-index &&
221 git ls-files -f >actual &&
222 test_cmp expect actual
225 # Ensure commands that call refresh_index() to move the index back in time
226 # properly invalidate the fsmonitor cache
227 test_expect_success 'refresh_index() invalidates fsmonitor cache' '
228 write_script .git/hooks/fsmonitor-test<<-\EOF &&
233 git commit -m "to reset" &&
235 git status >actual &&
236 git -c core.fsmonitor= status >expect &&
237 test_i18ncmp expect actual
240 # test fsmonitor with and without preloadIndex
241 preload_values="false true"
242 for preload_val in $preload_values
244 test_expect_success "setup preloadIndex to $preload_val" '
245 git config core.preloadIndex $preload_val &&
246 if test $preload_val = true
248 GIT_FORCE_PRELOAD_TEST=$preload_val; export GIT_FORCE_PRELOAD_TEST
250 unset GIT_FORCE_PRELOAD_TEST
254 # test fsmonitor with and without the untracked cache (if available)
256 test_have_prereq UNTRACKED_CACHE && uc_values="false true"
257 for uc_val in $uc_values
259 test_expect_success "setup untracked cache to $uc_val" '
260 git config core.untrackedcache $uc_val
263 # Status is well tested elsewhere so we'll just ensure that the results are
264 # the same when using core.fsmonitor.
265 test_expect_success 'compare status with and without fsmonitor' '
266 write_integration_script &&
272 git status >actual &&
273 git -c core.fsmonitor= status >expect &&
274 test_i18ncmp expect actual
277 # Make sure it's actually skipping the check for modified and untracked
278 # (if enabled) files unless it is told about them.
279 test_expect_success "status doesn't detect unreported modifications" '
280 write_script .git/hooks/fsmonitor-test<<-\EOF &&
285 test_path_is_file marker &&
288 git status >actual &&
289 test_path_is_file marker &&
290 test_i18ngrep ! "Changes not staged for commit:" actual &&
291 if test $uc_val = true
293 test_i18ngrep ! "Untracked files:" actual
295 if test $uc_val = false
297 test_i18ngrep "Untracked files:" actual
304 # test that splitting the index dosn't interfere
305 test_expect_success 'splitting the index results in the same state' '
306 write_integration_script &&
308 git update-index --fsmonitor &&
309 git ls-files -f >expect &&
310 test-dump-fsmonitor >&2 && echo &&
311 git update-index --fsmonitor --split-index &&
312 test-dump-fsmonitor >&2 && echo &&
313 git ls-files -f >actual &&
314 test_cmp expect actual