ripgrep icon indicating copy to clipboard operation
ripgrep copied to clipboard

ignore: fix filtering searching subdir or .ignore in parent dir

Open WalterScottYoung opened this issue 1 year ago • 6 comments

The previous code deleted too many parts of the path when constructing the absolute path, resulting in a shortened final path. This patch creates the correct absolute path by only removing the necessary parts.

Fixes #2836 and #2747 and #2731

WalterScottYoung avatar Nov 15 '24 11:11 WalterScottYoung

One thing to notice is that commit cad1f5f didn't seems to fully fix https://github.com/BurntSushi/ripgrep/issues/1757, the test in issue 1757 will fail if we add one more directory in the path. I don't know if we should reopen 1757 or something like that to note others about this?

The following test from 1757 with "onemore" directory will fail before this fix.

mkdir tmp
cd tmp
mkdir rust
mkdir -p rust/target/onemore
echo needle > rust/source.rs
echo needle > rust/target/onemore/rustdoc-output.html
echo rust/target/onemore > .ignore
rg --files-with-matches needle
rg --files-with-matches needle rust
echo target >> .ignore
rg --files-with-matches needle rust

WalterScottYoung avatar Nov 15 '24 11:11 WalterScottYoung

@BurntSushi do you have time to review/merge this?

gstokkink avatar Jan 07 '25 06:01 gstokkink

I can confirm this fixes some bugs I was about to report where some files listed in gitignore glob rules were not excluded depending on the directory that rg --files was run from. Thanks!

Lucus16 avatar Feb 03 '25 12:02 Lucus16

This PR also fixes https://github.com/BurntSushi/ripgrep/issues/2778.

woess avatar Feb 12 '25 00:02 woess

@BurntSushi sorry for the mention, my project is affected by the underlying bugs fixed in this PR. Would it be possible to review it?

beeb avatar Apr 22 '25 11:04 beeb

I'm also affected by this bug in ripgrep, but also in https://github.com/sharkdp/fd/issues/1506 which also depends on ignore crate.

fenuks avatar May 26 '25 12:05 fenuks

Great work, thank you! 👍 Just wondering, one test was enough for negation and nesting?

reneleonhardt avatar Jul 01 '25 06:07 reneleonhardt

@BurntSushi any chance of a merge & release?

gstokkink avatar Jul 01 '25 07:07 gstokkink

Great work, thank you! 👍 Just wondering, one test was enough for negation and nesting?

It's been some time and I don't really remember the detail of this, but I'm pretty sure that the original problem was cause by the path concatenation and the target file's relative depth to where ripgrep was called be positive or 0 or negative was the boardline that this bug would be triggered, so only tests for those boardline scenarios was added, since more layer of dir won't matter as the bug would be triggered in the first nested layer of dir. Thank you for your question and you can add some more tests that you think is valuable :-)

WalterScottYoung avatar Jul 03 '25 12:07 WalterScottYoung