ignore: fix filtering searching subdir or .ignore in parent dir
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
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
@BurntSushi do you have time to review/merge this?
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!
This PR also fixes https://github.com/BurntSushi/ripgrep/issues/2778.
@BurntSushi sorry for the mention, my project is affected by the underlying bugs fixed in this PR. Would it be possible to review it?
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.
Great work, thank you! 👍 Just wondering, one test was enough for negation and nesting?
@BurntSushi any chance of a merge & release?
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 :-)