nathankleyn/gitignore.rs

is_excluded() returns false for files nested within ignore directories

mattgreen opened this issue ยท 4 comments

Let's say my .gitignore is a typical Rust project:

target
Cargo.lock

I configure a gitignore::File like so:

let cwd = env::current_dir().unwrap();
let gitignore_path = cwd.join(".gitignore");
let file = gitignore::File::new(&gitignore_path).unwrap();

Then I run the executable with CWD set to the same dir as the .gitignore.

When I call is_excluded on a file in target, (e.g. target/debug/executable), it returns false instead of true. Shouldn't it ignore the directory and everything below it?

Hey @mattgreen, sorry to not have gotten back to you sooner (I missed the notification for this)!

I have indeed confirmed this bug, which is a bit silly really: basically, the included_files method is doing the correct thing (which is what the majority of the tests are checking against), but is_excluded is not checking to see if any of the parent dirs were excluded too and that has been missed in the test coverage.

I will try to get a fix in for this ASAP, probably by implementing is_excluded in terms of included_files - thanks for reporting this! ๐Ÿ‘

Awesome, will give this a try when I get a chance. Thank you!

@mattgreen Fix for this has been published as v1.0.5 on crates.io - let me know if you encounter any issues! ๐Ÿ‘

Having the same issue on "1.0.7", is_excluded return true for files in ignored directories