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

Change in behavior of double star in glob #1271

Closed
danadam opened this issue Apr 26, 2019 · 1 comment
Closed

Change in behavior of double star in glob #1271

danadam opened this issue Apr 26, 2019 · 1 comment
Labels
question An issue that is lacking clarity on one or more points.

Comments

@danadam
Copy link

danadam commented Apr 26, 2019

Up until rg 0.7.1, with the following file structure:

mkdir -p foo/test/bar foo/prod/bar
echo "hello" > foo/test/bar/hello.txt
cp foo/test/bar/hello.txt foo/prod/bar/

If I wanted to match (or exclude) specific dir anywhere in the file path I did:

]$ rg -g'test/**' hello
foo/test/bar/hello.txt
1:hello

]$ rg -g'!test/**' hello
foo/prod/bar/hello.txt
1:hello

Using double star at the front worked only with negation:

$ rg -g'**/test/' hello
No files were searched, which means ripgrep probably applied a filter you didn't expect. Try running again with --debug.

]$ rg -g'!**/test/' hello
foo/prod/bar/hello.txt
1:hello

In rg 0.8.1 this changed. Double star at the end doesn't work:

]$ rg -g'test/**' hello
No files were searched, which means ripgrep probably applied a filter you didn't expect. Try running again with --debug.

]$ rg -g'!test/**' hello
foo/test/bar/hello.txt
1:hello

foo/prod/bar/hello.txt
1:hello

Behavior of double star at the front didn't change.

Using double star on both sides, i.e., **/test/** works as expected in both versions.

Is that a bug? Or is **/test/** really the minimal correct pattern that can be simply negated with ! and work as expected?

@BurntSushi
Copy link
Owner

Yup, this is indeed correct. I'm not going to dig around for the specific change that caused this, but test/** should match test/foo but not bar/test/foo. It might make sense to add --include-dir or --exclude-dir flags as part of #809, but that isn't much shorter.

Or is **/test/** really the minimal correct pattern that can be simply negated with ! and work as expected?

I'm less sure about this. My thinking is that -g '*test*' should also work in this case, but it doesn't. However, this matches strictly more things than **/test/**. (*test* should match foo/atestb/bar where as **/test/** shouldn't.)

@BurntSushi BurntSushi added the question An issue that is lacking clarity on one or more points. label Apr 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question An issue that is lacking clarity on one or more points.
Projects
None yet
Development

No branches or pull requests

2 participants