Skip to content

Commit 874f3df

Browse files
committed
ignore: fix has_any_ignore_rules for explicit ignores
When building a ignore::WalkBuilder by disabling all standard filters and adding a custom global ignore file, the ignore file is not used. Example: let mut walker = ignore::WalkBuilder::new(dir); walker.standard_filters(false); walker.add_ignore(myfile); This makes it impossible to use the ignore crate to walk a directory with only custom ignore files. Very similar to issue BurntSushi#800 (fixed in b71a110).
1 parent 7b6af5a commit 874f3df

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

ignore/src/dir.rs

+2
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,11 @@ impl Ignore {
266266
fn has_any_ignore_rules(&self) -> bool {
267267
let opts = self.0.opts;
268268
let has_custom_ignore_files = !self.0.custom_ignore_filenames.is_empty();
269+
let has_explicit_ignores = !self.0.explicit_ignores.is_empty();
269270

270271
opts.ignore || opts.git_global || opts.git_ignore
271272
|| opts.git_exclude || has_custom_ignore_files
273+
|| has_explicit_ignores
272274
}
273275

274276
/// Returns a match indicating whether the given file path should be

ignore/src/walk.rs

+18
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,24 @@ mod tests {
16731673
assert_paths(td.path(), &builder, &["bar", "a", "a/bar"]);
16741674
}
16751675

1676+
#[test]
1677+
fn explicit_ignore_exclusive_use() {
1678+
let td = TempDir::new("walk-test-").unwrap();
1679+
let igpath = td.path().join(".not-an-ignore");
1680+
mkdirp(td.path().join("a"));
1681+
wfile(&igpath, "foo");
1682+
wfile(td.path().join("foo"), "");
1683+
wfile(td.path().join("a/foo"), "");
1684+
wfile(td.path().join("bar"), "");
1685+
wfile(td.path().join("a/bar"), "");
1686+
1687+
let mut builder = WalkBuilder::new(td.path());
1688+
builder.standard_filters(false);
1689+
assert!(builder.add_ignore(&igpath).is_none());
1690+
assert_paths(td.path(), &builder,
1691+
&[".not-an-ignore", "bar", "a", "a/bar"]);
1692+
}
1693+
16761694
#[test]
16771695
fn gitignore_parent() {
16781696
let td = TempDir::new("walk-test-").unwrap();

0 commit comments

Comments
 (0)