How to restrict search to subdirectories via glob, but still respect .gitignore for files? #2173
-
Is there a way to use A representative example of the situation I have:
Now when I do However, when I do I know that on the CLI I can just use |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
There isn't a way, no. The issue is that, conceptually, the The simplest way I can think of to achieve what you want would be something like this:
or something like that. The problem with things like VS Code that only give a limited interface to CLI tools is that you lose the compositional power of the shell. This in turn puts pressure on tools to break with the Unix philosophy and build everything into the tool. I'm not a Unix zealot and there are obviously many things in ripgrep that already break the Unix philosophy, but the answer can't be "build everything into it." With that said, ripgrep's filtering logic breaks down at various rough edges like this. The issue tracker has lots of issues like this. Unfortunately, the whole thing needs a rethink (and I've been saying that for years), but haven't been able to manage to do it yet. |
Beta Was this translation helpful? Give feedback.
There isn't a way, no. The issue is that, conceptually, the
-g/--glob
flags are meant to act like a "gitignore file that overrides everything else, but at CLI invocation time." So if you have a more specific gitignore file, its rules will override rules from a less specific gitignore file. ripgrep treats-g/--glob
as the most specific as possible gitignore file. So when you say something like--glob 'test/**'
as something you want to include, ripgrep matches that againsttest/foo.glob
and whitelists it. While a more specific ignore file can override a whitelist match, there isn't anything more specific than-g/--glob
. So ripgrep includes it in the search.The simplest way I can think of t…