-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add switch to pay attention to .gitignore files when not in a git repo #1414
Comments
What about adding an empty file called You could also symlink I'm really not too inclined to add even more flags specifically for changing when
What is the standard way to detect a Perforce repo? If Perforce specifically recognizes gitignore files, then we could add the Perforce check in addition to the |
An empty .git directory or empty .git file does cause git based tools to fail. Both external tools and internal tools. For example, "touch .git; git status" yields "fatal: Invalid gitfile format: .git". In Perforce, you set in their config P4IGNORE to .gitignore. You can also place P4IGNORE in the environment. Thus, detecting a Perforce repo is going to require something else. You could look for the existence of a .perforce file, but even this isn't required. We have a large repo with many hundreds of .gitignore files and developed on multiple platforms. Symlink'ing won't work because of Windows. Adding rules to generate .ignore from .gitignore files is challenging because of the variety of different build systems we use. I assume you do the .git check once, could you update it check for another file, e.g. .ripgrep-force-gitignore? |
Out of curiosity, why does ripgrep require a .git directory to pay attention to the .gitignore files? In a quick scan of the code and doc, I couldn't find a reason. |
I guess it seems like there isn't much of a choice here other than to add a flag. It's just pretty unfortunate and I'd really rather that ripgrep not grow an unbounded number of flags for every weird case. In this case, it really seems like |
Thanks - I will look into adding a switch and create a PR assuming it can be done cleanly. |
Hi @BurntSushi, Firstly, thank you for ripgrep! It's an awesome tool and I'm a long time fan/user. I'm working with @JohnC32 on an implementation of this. It was pretty trivial to add a switch to force reading gitignores outside a git repo (basically just an option for the Ignore class). However, I stumbled across a cleaner (IMHO) way of doing it. I noticed you have a "custom ignore" functionality baked in, which, if I understand correctly, is being used to read patterns from Would you be open to adding a switch which allows arbitrary files to be read as ignores (basically just passing them to Thank you for your time and help! I have a prototype of the Thanks, |
@akarle That is an interesting approach, but it's not quite the same. In particular, |
@BurntSushi thank you for the fast response and for the clarification! Hmm I was aware that it was a higher priority, but hadn't considered the impact of not allowing I had originally assumed that I now see that I'll look back into the original "pay attention to .gitignore files outside git repos" switch :) Thanks again, |
As mentioned in BurntSushi#1414, ripgrep by default does not use gitignore patterns when outside a git repository. This is a good default, as it prevents filtering files from non-repositories (like /tmp). However, there are several use cases for respecting gitignore patterns outside of a proper git repository. For example, if a git repository is copied without the .git directory (i.e. downloaded from GitHub as a zip file), or in SCM systems such as Perforce where ignore patterns can be used (and .gitignore can be the name of the ignore files). This commit introduces a "--ignore-outside-git" flag which enables parsing gitignore files outside of proper git repositories.
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
I try to compile rg and found it will test failure in no_require_git. Is it related to
|
And Although I have installed |
Could you add a switch e.g. --force-gitignore which would force usage of .gitignore files even when there's no .git directory?
Give a large repo, it's often convenient to archive versions of it and not save the .git directory. Currently ripgrep 11.0.2 does not pay attention to .gitignore files if there's no .git directory. This makes it impossible to use rg on such repo's. Another use case is when using Perforce. Perforce pays attention to .gitignore files and does not have a .git directory. A work around is to create an empty .git directory, but in our environment this causes problems because git based tools fail when there's an empty .git directory.
Thanks for ripgrep - it's really powerful!
The text was updated successfully, but these errors were encountered: