yuanchuan / node-watch

A wrapper and enhancements for fs.watch
https://npm.im/node-watch
MIT License
341 stars 44 forks source link

fs.watch() not detecting changes to file from git operation #126

Closed tumblingG closed 1 year ago

tumblingG commented 1 year ago

can we fix this problem?

https://github.com/nodejs/node/issues/5039

yuanchuan commented 1 year ago

After some modifications to a local git repo, it outputs:

❯ ./watch .
update .git/.gitstatus.N0Qvnh
update .git/.gitstatus.N0Qvnh/a
update .git/.gitstatus.N0Qvnh/b
remove .git/.gitstatus.N0Qvnh/b/1
remove .git/.gitstatus.N0Qvnh/a/1
remove .git/.gitstatus.N0Qvnh/b
remove .git/.gitstatus.N0Qvnh/a
remove .git/.gitstatus.N0Qvnh
update s
remove s

So It works properly on my machine (macOS).

Could you please provide more infomation and a sample test code?

tumblingG commented 1 year ago

image

As shown in the figure above, when I switch branches, sometimes files and folders change together, sometimes only folders change. I tried to write a similar demo, but failed. My environment is window

yuanchuan commented 1 year ago

sometimes only folders change

This is an expected behavior of fs.watch when a folder is being deleted. We can't fix that unless the initial scan is implemented. Related issue: https://github.com/yuanchuan/node-watch/issues/58