-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ignore
: gitignore relative paths are not treated relatively
#1909
Comments
I believe these are the relevant gitignore docs:
In particular, the "Otherwise ..." language applies here since there is no This is very likely an API-level bug. In particular, when building the crate, I likely assumed that a gitignore matcher would only be used on paths at or below the directory in which it was created. And generally speaking, that's how the I don't see this bug getting fixed any time soon unfortunately. The |
I suppose it could depend on what use std::path::PathBuf;
use ignore::gitignore::GitignoreBuilder;
fn main() {
let mut builder = GitignoreBuilder::new("/root/scratch");
builder.add_line(Some(PathBuf::from("/root/scratch/.gitignore")), "!/**/*.html").unwrap();
// builder.add_line(None, "!/**/*.html").unwrap(); // Using `None` doesn't help, unfortunately.
let matcher = dbg!(builder.build().unwrap());
assert!(matcher.matched("/root/scratch/foo.html", false).is_whitelist());
assert!(dbg!(matcher.matched("/root/unknown/foo.html", false)).is_none());
} Here, we see:
I understand. I'm working on a replacement for the core gitignore pattern matching part of |
@SergioBenitez Yeah, that looks like the same variant of the bug that is "the gitignore matcher has an undocumented and in some cases inconvenient assumption that you only use it with paths at or below the directory in which the gitignore rules were defined." |
@BurntSushi : is there some way to group the issues related to the I am aware of #278 for example, but searching the issue tracker for |
@LeGEC No, such a grouping doesn't exist. You're right that it should, but it will take work and effort to do. |
I hit to this bug when I was developing something with the ignore crate.
I can submit a PR to add directory to the pattern. Currently lines in |
In short, gitignore rules that should be relative to a specific gitgnore path are instead reinterpreted as
**/rule
. Here's the failing test case:The relevant output:
The text was updated successfully, but these errors were encountered: