-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
Please tick this box to confirm you have reviewed the above.
- I have a different issue.
What version of ripgrep are you using?
ripgrep 14.1.1
features:+pcre2
simd(compile):+SSE2,-SSSE3,-AVX2
simd(runtime):+SSE2,+SSSE3,+AVX2
PCRE2 10.43 is available (JIT is available)
Setup
- Git repository at
$HOME/mygitrepo .gitignorefile at$HOME/mygitrepo/.gitignore, containsfoobar/debug$HOME/mygitrepo/foobar/some/debug/flagfile, containsbaz$HOME/mygitrepo/foobar/debug/flag2file, also containsbaz
Repository filetree:
.
└── foobar
├── debug
│ └── flag2
└── some
└── debug
└── flag
Walkthrough
Now, git add foobar/ && git status --branch --short shows:
## master
A foobar/some/debug/flag
Which is correct, as we want to ignore folder debug only if it is $HOME/mygitrepo/foobar/debug (child node of the foobar folder located in the $GITROOT), not if it is $HOME/mygitrepo/foobar/some/debug (folder named debug elsewhere in the repository).
Now let's try to use rg here: cd "$HOME/mygitrepo/foobar && rg baz"
rg: No files were searched, which means ripgrep probably applied a filter you didn't expect.
Running with --debug will show why files are being skipped.
OK, sure: rg --debug "baz" 2>&1 | grep debug
rg: DEBUG|ignore::walk|/usr/share/cargo/registry/ignore-0.4.23/src/walk.rs:1799: ignoring ./debu: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/home/user/mygitrepo/.gitignore"), original: "foobar/debug", actual: "foobar/debug", is_whitelist: false, is_only_dir: false })))
rg: DEBUG|ignore::walk|/usr/share/cargo/registry/ignore-0.4.23/src/walk.rs:1799: ignoring ./somedebug: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/home/user/mygitrepo/.gitignore"), original: "foobar/debug", actual: "foobar/debug", is_whitelist: false, is_only_dir: false })))
Running with --debug will show why files are being skipped.
What's going on? Let's try to remove the .gitignore temporarily: rm ../.gitignore && rg baz:
some/debug/flag
baz
debug/flag2
baz
Which leads us to unclear logic where foobar/debug in the .gitignore makes rg to ignore foobar/some/debug/flag.
How did you install ripgrep?
apt
What operating system are you using ripgrep on?
Debian 13
Describe your bug.
ripgrep ignores files that should not be ignored
What are the steps to reproduce the behavior?
ripgrep treats .gitignore differently compared to git
What is the actual behavior?
rg: DEBUG|ignore::walk|/usr/share/cargo/registry/ignore-0.4.23/src/walk.rs:1799: ignoring ./debu: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/home/user/mygitrepo/.gitignore"), original: "foobar/debug", actual: "foobar/debug", is_whitelist: false, is_only_dir: false })))
rg: DEBUG|ignore::walk|/usr/share/cargo/registry/ignore-0.4.23/src/walk.rs:1799: ignoring ./somedebug: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/home/user/mygitrepo/.gitignore"), original: "foobar/debug", actual: "foobar/debug", is_whitelist: false, is_only_dir: false })))
What is the expected behavior?
ripgrep should have returned 2 matches