-
-
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
Passing a path argument doesn't respect .gitignore #829
Comments
OK, so this issue is really tangled and I'm going to do best untangle it. The core of the problem here is that you've seemed to derive a generic failure from a very specific one, namely, that all ignore rules are overridden for a directory that is specified on the command line. But this is not true, as you noted with the glob rules. But your glob rules and your ignore rules are different, so you haven't accounted for the fact that there may be a bug with the specific pattern in your ignore file that doesn't impact the pattern in your Note though that if you specified
That is, if you give a path to ripgrep, then that path itself is immune to any other ignore rules inherited from the configuration, including those specified explicitly on the command line via the |
Interestingly, Thanks for the bug report! |
Also, if you have suggestions on how to improve the documentation (while maintaining some level of succinctness), I'd be happy to try and fix that too, although it does seem like it might have been this bug that really threw you off. :) |
That makes sense. If I have some time I can try debugging some more. |
@tmccombs Thanks! The kind of debugging to be done here is along the lines of "insert printf statements in strategic places inside the |
I'm not entirely sure why yet, but the problem seems to be that in |
I think this might be the same as #278. Or at least caused by the same thing. if let Some(abs_parent_path) = self.absolute_base() {
let path = abs_parent_path.join(path); What's happening is when Why is path joined to absolute_base rather than the current directory? I don't entirely understand what the purpose of absolute_base is. I'd be happy to help implement a fix for this, but I may need some help understanding what exactly absolute_base is used for and any gotchas I should watch out for. |
This fixes BurntSushi#829, but I'm not sure if it causes other problems.
tmccombs@9a42a12 fixes this problem, but I'm not sure if it introduces another problem, like not handling symlinks properly. |
yeah it breaks current behaviour with symlinks. If you have a layout like this:
And .gitignore contians a rule excluding "/c/blah", then currently |
Fixes BurntSushi#829 and BurntSushi#278. This does change the Ignore struct to depend on the working directory at the time of creation, I _think_ this is fine, since Ignore isn't publicly accessible and the Walk structs already depend on the current working directory implicitly. I tried to make a minimal change to fix the issue. An alternative implementation could be to call `current_dir` in the `matched_ignore` method instead of in `add_parents`, but I'm not sure of the performance implications of doing that. Another possible solution would be to change the places that we call `Ignore::matched` to change the path to be relative to the absolute_base of the `Ignore`.
I am running into the same issue. Our The repo in question is here: https://github.com/getsentry/sentry |
Since VSCode uses ripgrep I have similar issues, it makes the search very slow + return results which are not desirable. I need to manually specify excludes to make it work. |
Thanks for this, it worked. Big impact in monorepo. It's more a misunderstanding than a bug, but it clearly bothered me for month ahah |
FWIW the |
What version of ripgrep are you using?
ripgrep 0.8.1
-SIMD -AVX
What operating system are you using ripgrep on?
Archlinux (4.15.3-2-ARCH), also Ubuntu 16.04
Describe your question, feature request, or bug.
If I am in a git repository and run
rg
with a directory as a PATH argument, then all files under that directory are searched, even if they would normally be ignored because of .gitignore rule. If Icd
into the directory and runrg
without a PATH argument, the files are excluded as I expect. changing into a subdirectory is a workaround but is sometimes less convenient than using a path argument.The man page does say
Which could be interpreted to mean that the if such an argument is specified, the ignore rules are ignored altogether. But that behaviour is unexpected to me, and the wording of the documentation isn't entirely clear on whether it overrides all rules, or only rules that specifically ignore the specified path (but not children of that path).
If overriding all ignore rules is the intended behaviour there should at least be a way to turn the ignore rules back on, but
--ignore-vcs
does nothing when supplied with a PATH argument.Interestingly, if I specify a glob such as
-g "*.c"
, that is respected for files under the path.Steps to reproduce:
.gitignore:
a/b/test.txt:
In root of repository:
rg Sample
produces no outputAdding
--ignore-vcs
produces the same output.In
a
directoryrg Sample
also produces no output.If this is a bug, what is the actual behavior?
rg --debug Sample a
If this is a bug, what is the expected behavior?
Produced no output, since a/b/test.txt is ignored by the .gitignore file.
The text was updated successfully, but these errors were encountered: