-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ignore: respect local .git/config excludes #2396
Conversation
Currently, ripgrep respects $HOME/.gitconfig and $XDG_CONFIG_HOME/git/config, but not .git/config (the "local" or "project" config). Git makes it such that .git/config overrides the other two options, while still respecting the ./.gitignore. This commit brings this functionality to ripgrep (while also cleaning a few repetitive segments of code). Fixes BurntSushi#2392
Ping @BurntSushi. Had any time to review this? |
After a quick look I don't think this is right? It appears to assume that |
Whoops, you're right. $ mkdir subdir && cd subdir
$ touch subfile subfile.customexclude subfile.globalignore subfile.pwdignore
$ # only subfile and subfile.globalignore should be seen
$ rg --files
subfile
subfile.customexclude
$ rg-patched --files
subfile
subfile.customexclude I'm not too familiar with the code but it would appear that in dirs.rs there's going to have to be a matcher specifically made for Is this somewhere in the general right direction (at least with the way the code is now)? I've been working a bit on an approach like what I just described, might be able to make another commit in a bit. (This admittedly isn't that elegant since anything to do with the git dir, git config and excludesfile is done in gitignore.rs, with the apparent exception of .git/info/exclude logic which is handled in dir.rs) There's still a lot of cases I haven't explored (would global ignore be used if ~/.gitconfig exists with an excludes file, etc.), so I'll mark this PR as a draft. I'll try to see how git behaves in all cases this weekend and document it here, that way if this PR doesn't land at the very least it might help whoever ends up implementing this. |
…able global_match if .git/config excludesfile found
The above commit removes the incorrect CWD parsing and moves the Haven't tested this that thoroughly, still a WIP, but so far it does work in subdirectories since it correctly identifies the git path. $ # all the setup stuff
$ mkdir subdir && cd subdir
$ touch subfile subfile.customexclude subfile.globalignore subfile.pwdignore
$ git add -A
$ git ls-files
subfile
subfile.globalignore
$ rg --files
subfile
subfile.customexclude
$ rg-patched --files
subfile
subfile.globalignore |
Decided to use a global git ignore so I could reuse on other tools (namely rg), for that to work rg looks for the core.excludesFiles on the following files: `$HOME/.gitconfig` and `$XDG_CONFIG_HOME/git/config`. Refernces: BurntSushi/ripgrep#2396 BurntSushi/ripgrep#2392
Thanks for the work on this, but I'm going to close it. The I've opened #2553 to track this particular use case so that it's factored into the overhaul. |
Currently, ripgrep respects
$HOME/.gitconfig
and$XDG_CONFIG_HOME/git/config
, but not.git/config
(the "local" or "project" config). Git makes it such that.git/config
overrides the other two options, while still respecting the./.gitignore
. This commit brings this functionality to ripgrep (while also cleaning a few repetitive segments of code).To demonstrate with a reproducible example (of course, be careful with overriding any files):
Note that the global ignore file is intended to be ignored when a
.git/config
exists (as demonstrated by the output of git).Fixes #2392