Ripgrep: Specific .gitignore makes ripgrep find files in .git directory

Created on 5 Sep 2018  路  2Comments  路  Source: BurntSushi/ripgrep

What version of ripgrep are you using?

ripgrep 0.9.0
-SIMD -AVX

How did you install ripgrep?

pacman -S ripgrep

What operating system are you using ripgrep on?

Archlinux

Linux pc080 4.18.5-arch1-1-ARCH #1 SMP PREEMPT Fri Aug 24 12:48:58 UTC 2018 x86_64 GNU/Linux

Describe your question, feature request, or bug.

When I聽have this .gitignore file:

*
!*.*

the command ripgrep --files will show files in the .git directory, which does not make sense, because the .gitignore does not affect the files in the .git directory.

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

  1. In a git repository, create a .gitignore file with the above content.
  2. Run rg --files.
  3. See that rg shows files in the .git directory.

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

rg --files shows the files in the .git directory.

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

rg --files should not show the files in the .git directory because of a pattern of the .gitignore file.

bug gitignore question wontfix

Most helpful comment

This is a little tricky to fix in a consistent way. In particular, a .git directory is ignored because it's hidden, but the ignore matching rules permit any ignore-related file (.gitignore, .ignore, .rgignore) to override skipping hidden files when there is an explicit whitelist, which is the case here. To make this work like you expect, we'd have to special case the handling of git-specific ignore files to make it so it does not impact .git directories.

A work-around to this problem is to add .git/ to a .ignore file alongside your .gitignore. The simplicity of the work-around makes it tempting to declare this as wontfix, but I'll leave it open as something to consider if and when the ignore crate gets an overhaul.

All 2 comments

This is a little tricky to fix in a consistent way. In particular, a .git directory is ignored because it's hidden, but the ignore matching rules permit any ignore-related file (.gitignore, .ignore, .rgignore) to override skipping hidden files when there is an explicit whitelist, which is the case here. To make this work like you expect, we'd have to special case the handling of git-specific ignore files to make it so it does not impact .git directories.

A work-around to this problem is to add .git/ to a .ignore file alongside your .gitignore. The simplicity of the work-around makes it tempting to declare this as wontfix, but I'll leave it open as something to consider if and when the ignore crate gets an overhaul.

I think the right answer here is to probably just add .git to your ignore file. It's a corner case with a simple work around that I think is better than complicating ignore more than it is.

Was this page helpful?
0 / 5 - 0 ratings