Skip to content

How to restrict search to subdirectories via glob, but still respect .gitignore for files? #2173

Answered by BurntSushi
RalfJung asked this question in Q&A
Discussion options

You must be logged in to vote

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 against test/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…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@RalfJung
Comment options

@BurntSushi
Comment options

Answer selected by BurntSushi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants