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

glob matching doesn't seem to work consistenly for plain directory match #1442

Closed
w08r opened this issue Dec 6, 2019 · 3 comments
Closed
Labels
doc An issue with or an improvement to documentation. rollup A PR that has been merged with many others in a rollup.

Comments

@w08r
Copy link

w08r commented Dec 6, 2019

What version of ripgrep are you using?

▶ rg --version                                                                                                                                                                    
ripgrep 11.0.1
-SIMD -AVX (compiled)
+SIMD +AVX (runtime)

How did you install ripgrep?

Compiled from source

What operating system are you using ripgrep on?

MacOS (Catalina)

Describe your question, feature request, or bug.

I think that passing a plain directory as argument to -g should match files in that directory. Moreover, prefixing a match string with ! should negate the results. This seems to the behaviour most of the time.

If this is a bug, what are the steps to reproduce the behavior?

## from temp, empty directory
mkdir a b
echo hello > a/test.txt
cp a/test.txt b
rg -g a hello ## return nothing
rg -g '!b' hello ## returns match from file in 'a'

If this is a bug, what is the actual behavior?

Above script yields following (showing output of negated search only)

▶ sh /tmp/run.sh                                                                                                                                                                  
a/test.txt
1:hello

If this is a bug, what is the expected behavior?

Should have yielded results for either both or neither (preferably both) the invocations in the reproduction steps.

@w08r
Copy link
Author

w08r commented Dec 6, 2019

I am very new to rust, but if this is an issue you would like mending, I would be happy to have a stab at a PR.

@BurntSushi
Copy link
Owner

This is correct behavior. The -g/--glob flag applies to every file path searched. So the -g a behavior will cause ripgrep to descend into your a directory but not your b directory. However, a doesn't match any file inside your a directory. You can confirm this behavior by adding a a/a file:

$ echo hello > a/a
$ rg -g a hello
a/a
1:hello

If you do want to search everything in a, then you need to use a glob pattern that both matches the directory and the the files inside of it:

$ rg -g 'a/**' hello
a/a
1:hello

a/test.txt
1:hello

Your negation pattern works as you expect because it avoids descending into the b directory completely.

With all of this said, while the behavior is correct, the docs for the --glob flag could really be improved, so we can use this ticket to track that.

@BurntSushi BurntSushi added the doc An issue with or an improvement to documentation. label Dec 6, 2019
@w08r
Copy link
Author

w08r commented Dec 6, 2019

Thanks for the quick response, sir, and for the awesome tool!

@BurntSushi BurntSushi added the rollup A PR that has been merged with many others in a rollup. label Mar 15, 2020
BurntSushi added a commit that referenced this issue Mar 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc An issue with or an improvement to documentation. rollup A PR that has been merged with many others in a rollup.
Projects
None yet
Development

No branches or pull requests

2 participants