Ripgrep: Ripgrep does not use parent-directory, same-repo .gitignore files

Created on 4 Nov 2016  ·  7Comments  ·  Source: BurntSushi/ripgrep

Consider the following Git repo:

.gitignore
foo/
foo/message  # contains "hey"
foo/bar/
foo/bar/message  # contains "hey"

where .gitignore contains:

/foo/bar/

The issue is that when I run rg hey while in the foo directory, it returns 2 files (both foo/message and foo/bar/message). This is a bug because foo/bar/message is ignored by git, yet it's returned by rg, and the whole point of using rg over grep (imo) is that it doesn't include files that are ignored by Git.

Reproduction steps

Run these commands:

mkdir -p rg-test rg-test/foo rg-test/foo/bar
echo "hey" > rg-test/foo/message
echo "hey" > rg-test/foo/bar/message
echo "/foo/bar/" > rg-test/.gitignore
cd rg-test/foo
rg hey

Ex:

λ /tmp/ mkdir -p rg-test rg-test/foo rg-test/foo/bar
λ /tmp/ echo "hey" > rg-test/foo/message
λ /tmp/ echo "hey" > rg-test/foo/bar/message
λ /tmp/ echo "/foo/bar/" > rg-test/.gitignore
λ /tmp/ cd rg-test
λ /tmp/rg-test/ cd foo
λ /tmp/rg-test/foo/ rg hey
bar/message
1:hey

message
1:hey
λ /tmp/rg-test/foo/ 

Expected output (from the rg command):

1:hey

Actual output:

bar/message
1:hey

message
1:hey

Screenshot

screen shot 2016-11-03 at 11 21 04 pm

Most helpful comment

@lyuha Thanks! ^_^

All 7 comments

What version of ripgrep are you using?

On Nov 3, 2016 11:28 PM, "Shane Creighton-Young" [email protected]
wrote:

Consider the following Git repo:

.gitignore
foo/
foo/message # contains "hey"
foo/bar/
foo/bar/message # contains "hey"

where .gitignore contains:

/foo/bar/

The issue is that when I run rg hey while in the foo directory, it
returns 2 files (both foo/message and foo/bar/message). This is a bug
because foo/bar/message is ignored by git, yet it's returned by rg, and
the whole point of using rg over grep (imo) is that it doesn't include
files that are ignored by Git.
Reproduction steps

Run these commands:

mkdir -p rg-test rg-test/foo rg-test/foo/bar
echo "hey" > rg-test/foo/message
echo "hey" > rg-test/foo/bar/message
echo "/foo/bar/" > rg-test/.gitignore
cd rg-test/foo
rg hey

Ex:

λ /tmp/ mkdir -p rg-test rg-test/foo rg-test/foo/bar
λ /tmp/ echo "hey" > rg-test/foo/message
λ /tmp/ echo "hey" > rg-test/foo/bar/message
λ /tmp/ echo "/foo/bar/" > rg-test/.gitignore
λ /tmp/ cd rg-test
λ /tmp/rg-test/ cd foo
λ /tmp/rg-test/foo/ rg hey
bar/message
1:hey

message
1:hey
λ /tmp/rg-test/foo/

Expected output (from the rg command):

message
1:hey

Actual output:

bar/message
1:hey

message
1:hey

Screenshot [image: screen shot 2016-11-03 at 11 21 04 pm]
https://cloud.githubusercontent.com/assets/2747249/19993466/5128b6c4-a21c-11e6-84f2-b5dafe2853d9.png


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/BurntSushi/ripgrep/issues/221, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAb34j9d89ypaOvjyI5MVhOelD05qYzEks5q6qZYgaJpZM4KpKHp
.

λ ~/ rg --version
0.2.3
λ ~/

Installed via brew install ripgrep earlier today.

Ah okay. 0.2.6 is out, but not on brew yet (there is a binary download here
on github though). I'm on mobile, but I'll check this out on the latest
version tomorrow. Thanks for the detailed report!

On Nov 3, 2016 11:43 PM, "Shane Creighton-Young" [email protected]
wrote:

λ ~/ rg --version
0.2.3
λ ~/

Installed via brew install ripgrep earlier today.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/BurntSushi/ripgrep/issues/221#issuecomment-258338373,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAb34gQyZBWtL8ctDdEdKhkFKVXoKvRvks5q6qntgaJpZM4KpKHp
.

Yay, looks like this has already been fixed. :-)

[andrew@Cheetah ripgrep] mkdir 221
[andrew@Cheetah ripgrep] cd 221/
[andrew@Cheetah 221] mkdir -p foo/bar
[andrew@Cheetah 221] echo "hey" > foo/message
[andrew@Cheetah 221] echo "hey" > foo/bar/message
[andrew@Cheetah 221] echo /foo/bar/ > .gitignore
[andrew@Cheetah 221] rg hey
foo/message
1:hey
[andrew@Cheetah 221] cd foo/
[andrew@Cheetah foo] rg hey
message
1:hey

The gitignore logic recently went through a major overhaul, and I may have accidentally fixed a few bugs along the way.

I'll see about submitting a PR to homebrew to update.

I submitted PR to https://github.com/Homebrew/homebrew-core/pull/6590, and accepted. So, latest rg is 0.2.6 at homebrew.

@lyuha Thanks! ^_^

Thanks everyone. :smile:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bastienbc picture bastienbc  ·  3Comments

chopfitzroy picture chopfitzroy  ·  3Comments

andschwa picture andschwa  ·  3Comments

Offpics picture Offpics  ·  3Comments

wsdjeg picture wsdjeg  ·  3Comments