BurntSushi/ripgrep

.gitignore rule is matched incorrectly while in a subdir

woess opened this issue · 0 comments

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.0

How did you install ripgrep?

cargo install

What operating system are you using ripgrep on?

Linux

Describe your bug.

.gitignore rule to ignore /dir/*.ext works correctly when running rg from the repo root, but incorrectly ignores *.ext in all subdirs when running from dir.

What are the steps to reproduce the behavior? / What is the actual behavior?

mkdir /tmp/repro
cd /tmp/repro
git init
mkdir parent
mkdir parent/subdir
echo "/parent/*.txt" > .gitignore
echo "please ignore me" > parent/ignore-me.txt
echo "please don't ignore me" > parent/subdir/dont-ignore-me.txt

while in git repo root dir (/tmp/repro), everything is working as expected:

$ rg ignore
parent/subdir/dont-ignore-me.txt
1:please don't ignore me

but once you cd into ./parent, suddenly the rule is unexpectedly applied to the file in subdir, too, and nothing is found:

$ cd parent
$ rg ignore
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.

Debug output (argument parsing omitted: "no extra arguments found from configuration file", "heuristic chose to search ./"):

/tmp/repro $ rg ignore
rg: DEBUG|grep_regex::config|/…/grep-regex-0.1.12/src/config.rs:175: assembling HIR from 1 fixed string literals
rg: DEBUG|globset|/…/globset-0.4.14/src/lib.rs:453: built glob set; 0 literals, 0 basenames, 12 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
rg: DEBUG|globset|/…/globset-0.4.14/src/lib.rs:453: built glob set; 0 literals, 0 basenames, 0 extensions, 0 prefixes, 0 suffixes, 1 required extensions, 0 regexes
rg: DEBUG|ignore::walk|/…/ignore-0.4.22/src/walk.rs:1799: ignoring ./.git: Ignore(IgnoreMatch(Hidden))
rg: DEBUG|ignore::walk|/…/ignore-0.4.22/src/walk.rs:1799: ignoring ./.gitignore: Ignore(IgnoreMatch(Hidden))
rg: DEBUG|ignore::walk|/…/ignore-0.4.22/src/walk.rs:1799: ignoring ./parent/ignore-me.txt: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("./.gitignore"), original: "/parent/*.txt", actual: "parent/*.txt", is_whitelist: false, is_only_dir: false })))
test/subdir/ignore-me.txt
1:please don't ignore me

/tmp/repro/parent $ rg ignore
rg: DEBUG|grep_regex::config|/…/grep-regex-0.1.12/src/config.rs:175: assembling HIR from 1 fixed string literals
rg: DEBUG|globset|/…/globset-0.4.14/src/lib.rs:453: built glob set; 0 literals, 0 basenames, 12 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes
rg: DEBUG|globset|/…/globset-0.4.14/src/lib.rs:453: built glob set; 0 literals, 0 basenames, 0 extensions, 0 prefixes, 0 suffixes, 1 required extensions, 0 regexes
rg: DEBUG|ignore::walk|/…/ignore-0.4.22/src/walk.rs:1799: ignoring ./ignore-me.txt: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/tmp/repro/.gitignore"), original: "/parent/*.txt", actual: "parent/*.txt", is_whitelist: false, is_only_dir: false })))
rg: DEBUG|ignore::walk|/…/ignore-0.4.22/src/walk.rs:1799: ignoring ./subdir/dont-ignore-me.txt: Ignore(IgnoreMatch(Gitignore(Glob { from: Some("/tmp/repro/.gitignore"), original: "/parent/*.txt", actual: "parent/*.txt", is_whitelist: false, is_only_dir: false })))
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.

What is the expected behavior?

/tmp/repro/parent $ rg ignore
subdir/dont-ignore-me.txt
1:please don't ignore me