watchexec / watchexec

Executes commands in response to file modifications

Home Page:https://watchexec.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for ~/.gitignore

behnam opened this issue · comments

Moving over from watchexec/cargo-watch#67

When respecting gitignore files to not watch, the current implementation only looks at the local .gitignore file, but not other ones that git itself recognizes, specially ~/.gitignore.

The best and common practice to gitignore editor temp files is to put the patters in ~/.gitignore, as they are something user-dependent and not project-dependent (and its hard for projects to stay inclusive to all types of editors and their settings).

Because of this, right now, when using cargo watch, I get a new execution whenever I open/close my editors (VIM), which is very often, because of the .*.swp files being created and dropped.

Yeah, technically, it's not ~/.gitignore, but the value of core.excludesFile in ~/.gitconfig, or some fallbacks.

From https://git-scm.com/docs/gitignore#_description:

Patterns which a user wants Git to ignore in all situations (e.g., backup or temporary files generated by the user’s editor of choice) generally go into a file specified by core.excludesFile in the user’s ~/.gitconfig. Its default value is $XDG_CONFIG_HOME/git/ignore. If $XDG_CONFIG_HOME is either not set or empty, $HOME/.config/git/ignore is used instead.

And, GitHub guides new users to create ~/.gitignore_global.

https://help.github.com/articles/ignoring-files/

This is one of the TODOs in the code right now :) https://github.com/mattgreen/watchexec/blob/e3105c0abb63281b84e4f1048aab8f1b5be007e3/src/gitignore.rs#L85-L111

I think all we need to do is load all the user files from the appropriate spots, and append them to applicable_files . If you know Rust and would like to jump in on this, feel free! Otherwise I'll look to take a stab at this in the near future.

The thing to do here is to use ripgrep's ignore sub-crate without actually using the Walker type. It has some very decent file-types pre-defined, and one can use gitignore and overrides.

That would mean getting rid of gitignore.rs and notification_filters.rs, setting up ignore from cli and asking ignore if a file event should be ignored.

@lukaslueg FWIW, I'd say about half the complexity of the ignore crate is in the various walkers. The semantics are quite tricky to get right. The lower level types will help you, but the battle is far from over if you start there. :-) Take a look at this, for example: https://github.com/BurntSushi/ripgrep/blob/master/ignore/src/dir.rs

@BurntSushi , I'm aware of that. watchexec can't use the walkers though, as it reacts on io notifications which can refer to any file, especially those that were not present at t=0. Life could be easier downstream from ignore if some of it's lower-level types would go public.

@lukaslueg Right, I was just clarifying.

Life could be easier downstream from ignore if some of it's lower-level types would go public.

I initially started with this idea, but the API is IMO too complex. Most of the context has fallen out of my head, but there are too many invariants that the caller needs to uphold to use it correctly. So I unexported everything and only exposed what I was comfortable with.

If someone wants to put in the API design work to expose something, I'd be happy to try and mentor that, but it will be hard.

Bundling support for other git ignore files in this issue, e.g. .git/info/exclude.

That's done. We also support other places for the global gitignore (such as for Windows), as well as other global ignore files as appropriate (for other VCSs than Git), and a global ignore file just for Watchexec. See the release notes for 1.18.0.

@passcod The documentation at crates.io says: ".git/info/exclude and the global $HOME/.gitignore and similar ignore files are not supported yet". Looks like this support has been added.

Should I submit a PR that removes this line from the documentation?

Yes please!