Skip to content
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

[RFC] ripgrep: expose custom ignore files via --ignore-file-name #1416

Closed
wants to merge 2 commits into from

Conversation

akarle
Copy link

@akarle akarle commented Oct 31, 2019

The ignore crate has the concept of "custom ignore" files. These files
take precedence over all others and can be used to declare arbitrary
file names as files which should be parsed for ignore patterns.

This commit adds the --ignore-file-name switch to ripgrep, exposing this
functionality to the user. For instance, if a user wanted to put their
ignores in many files called .my_ignore they could:

rg --ignore-file-name .my_ignore

This can also be used as a hack to honor .gitignore files outside .git
repositories (#1414), which can be useful if a git repo has been copied
somewhere without the .git directory (i.e. downloaded as a zip from
GitHub) or for SCM systems like Perforce which allow .gitignore files
but are not valid git repositories. Note, however, that this tactic
gives .gitignore precedence over .ignore and .rgignore, so consider
using multiple flags:

rg --ignore-file-name .ignore --ignore-file-name .gitignore

Aside: this is discussed in #1414 .

@BurntSushi : I have another branch on my fork, ignore_outside, that implements the other possible way we discussed of solving this (via a --force-gitignore flag, which I called --ignore-outside-git, but am happy to change to whatever we find appropriate).

I also came up with a third solution that would work for our use-case: creating a --alt-git-root-file switch which specifies a token that is determined to indicate the root of a git repo. This is the most intrusive implementation though (getting into the guts of the ignore crate), and I found my knowledge of asynchronous rust didn't cut it :)

I'm proposing we merge the --ignore-file-name switch, even though it is the most hacky solution to #1414 , because it is the least change to the code, and could have other benefits / be considered a feature. However, I'm happy to go with either the --ignore-outside-git or --alt-git-repo-files solutions if you deem them more appropriate for the project.

Rust is not my strongest language, so I appreciate any and all pointers / tips / corrections!

Thanks for your time and help!
Alex

Alex Karle added 2 commits October 31, 2019 13:55
The ignore crate has the concept of "custom ignore" files. These files
take precedence over all others and can be used to declare arbitrary
file names as files which should be parsed for ignore patterns.

This commit adds the --ignore-file-name switch to ripgrep, exposing this
functionality to the user. For instance, if a user wanted to put their
ignores in many files called ".my_ignore" they could:

    rg --ignore-file-name .my_ignore

This can also be used as a hack to honor .gitignore files outside .git
repositories, which can be useful if a git repo has been copied
somewhere without the .git directory (i.e. downloaded as a zip from
GitHub) or for SCM systems like Perforce which allow .gitignore files
but are not valid git repositories. Note, however, that this tactic
gives .gitignore precedence over .ignore and .rgignore, so consider
using multiple flags:

    rg --ignore-file-name .ignore --ignore-file-name .gitignore
@BurntSushi
Copy link
Owner

Thanks for this PR! The idea was interesting, but I think a more explicit --no-require-git flag is probably better. I've added this flag in #1486, which will be in the next release.

@BurntSushi BurntSushi added the rollup A PR that has been merged with many others in a rollup. label Feb 17, 2020
BurntSushi added a commit that referenced this pull request Feb 17, 2020
This flag prevents ripgrep from requiring one to search a git repository
in order to respect git-related ignore rules (global, .gitignore and
local excludes). This actually corresponds to behavior ripgrep had long
ago, but #934 changed that. It turns out that users were relying on this
buggy behavior. In most cases, fixing it as simple as converting one's
rules to .ignore or .rgignore files. Unfortunately, there are other use
cases---like Perforce automatically respecting .gitignore files---that
make a strong case for ripgrep to at least support this.

The UX of a flag like this is absolutely atrocious. It's so obscure that
it's really not worth explicitly calling it out anywhere. Moreover, the
error cases that occur when this flag isn't used (but its behavior is
desirable) will not be intuitive, do not seem easily detectable and will
not guide users to this flag. Nevertheless, the motivation for this is
just barely strong enough for me to begrudgingly accept this.

Fixes #1414, Closes #1416
@akarle
Copy link
Author

akarle commented Feb 17, 2020

@BurntSushi -- thank you so much for taking the time to revisit this!

I agree, the --no-require-git flag is more explicit (and less likely to cause confusion). Thank you for implementing it! Looking forward to using it in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rollup A PR that has been merged with many others in a rollup.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants