Skip to content

.gitignore logic is not followed #3067

@savchenko

Description

@savchenko

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
  • .gitignore file at $HOME/mygitrepo/.gitignore, contains foobar/debug
  • $HOME/mygitrepo/foobar/some/debug/flag file, contains baz
  • $HOME/mygitrepo/foobar/debug/flag2 file, also contains baz

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    rollupA PR that has been merged with many others in a rollup.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions