emcrisostomo / fswatch

A cross-platform file change monitor with multiple backends: Apple OS X File System Events, *BSD kqueue, Solaris/Illumos File Events Notification, Linux inotify, Microsoft Windows and a stat()-based backend.
https://emcrisostomo.github.io/fswatch/
GNU General Public License v3.0
4.96k stars 327 forks source link

Strange interaction with .git/ #262

Closed cfiske closed 3 years ago

cfiske commented 3 years ago

MacOS Catalina 10.15.7 fswatch 1.15.0 (installed via Homebrew) zsh 5.7.1

Sorry if this is long, but it's a complex and confusing issue to me and I want to be specific.

TL;DR: using --exclude=.git/ results in no file changes being reported at all anywhere in the specified path

So I'm trying to use fswatch to automatically kick off tests whenever a file changes in my source code folder (which is a git repo). I use ohmyzsh which executes git_prompt_info as part of displaying the prompt, to indicate any git status changes. When it runs it creates/removes .git/index.lock and that is (correctly) reported by fswatch.

Obviously I don't want to run a test every time a prompt is displayed, and really I don't care about anything in the git repo anyway, just my source files.

If I do this:

➜  blah git:(master) ✗ fswatch -r -x -v .

I get events every time there is a prompt:

notify_events: Notifying events #: 1.
/Users/clay/git/blah/.git/index.lock Created Removed IsFile
notify_events: Notifying events #: 1.
/Users/clay/git/blah/.git/index.lock Created Removed IsFile

If I exclude .git/index.lock I get the expected behavior, which is that real changes are reported and prompts are not. However if I exclude all of .git/ I get nothing at all, no matter what I do to any other files outside of .git/. Most bizarrely of all, even if I start a bare /bin/sh shell without git_prompt_info running I still get nothing at all if I have excluded .git/. I have tried all sorts of combinations of options, and it is specifically this that causes the issue.

Is there some special fswatch interaction with .git/ which is obstructed by excluding it?

emcrisostomo commented 3 years ago

It's not fswatch's interaction, it's actually your shell, because of how you set up your prompt. You're interacting with git to get the information that's shown in the prompt, such as branch name and status.

cfiske commented 3 years ago

I get why the .git/ events show up. The problem is that --exclude is not working correctly, because when I exclude that one path it stops working for everything else outside that path too. Even using another shell which does not have the prompt/git interaction it still does not work.