Skip to content

Commit b71a110

Browse files
sharkdpBurntSushi
authored andcommitted
ignore: fix custom ignore name bug
This commit fixes a bug in the handling of custom gitignore file names. Previously, the directory walker would check for whether there were any ignore rules present, but this check didn't incorporate the custom gitignore rules. At a high level, this permits custom gitignore names to be used even if no other source of gitignore rules is used. Fixes BurntSushi#800
1 parent 5c1af3c commit b71a110

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

ignore/src/dir.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,6 @@ struct IgnoreOptions {
7373
git_exclude: bool,
7474
}
7575

76-
impl IgnoreOptions {
77-
/// Returns true if at least one type of ignore rules should be matched.
78-
fn has_any_ignore_options(&self) -> bool {
79-
self.ignore || self.git_global || self.git_ignore || self.git_exclude
80-
}
81-
}
82-
8376
/// Ignore is a matcher useful for recursively walking one or more directories.
8477
#[derive(Clone, Debug)]
8578
pub struct Ignore(Arc<IgnoreInner>);
@@ -267,6 +260,15 @@ impl Ignore {
267260
(ig, errs.into_error_option())
268261
}
269262

263+
/// Returns true if at least one type of ignore rule should be matched.
264+
fn has_any_ignore_rules(&self) -> bool {
265+
let opts = self.0.opts;
266+
let has_custom_ignore_files = !self.0.custom_ignore_filenames.is_empty();
267+
268+
opts.ignore || opts.git_global || opts.git_ignore
269+
|| opts.git_exclude || has_custom_ignore_files
270+
}
271+
270272
/// Returns a match indicating whether the given file path should be
271273
/// ignored or not.
272274
///
@@ -295,7 +297,7 @@ impl Ignore {
295297
}
296298
}
297299
let mut whitelisted = Match::None;
298-
if self.0.opts.has_any_ignore_options() {
300+
if self.has_any_ignore_rules() {
299301
let mat = self.matched_ignore(path, is_dir);
300302
if mat.is_ignore() {
301303
return mat;

ignore/src/walk.rs

+20
Original file line numberDiff line numberDiff line change
@@ -1585,6 +1585,26 @@ mod tests {
15851585
assert_paths(td.path(), &builder, &["bar", "a", "a/bar"]);
15861586
}
15871587

1588+
#[test]
1589+
fn custom_ignore_exclusive_use() {
1590+
let td = TempDir::new("walk-test-").unwrap();
1591+
let custom_ignore = ".customignore";
1592+
mkdirp(td.path().join("a"));
1593+
wfile(td.path().join(custom_ignore), "foo");
1594+
wfile(td.path().join("foo"), "");
1595+
wfile(td.path().join("a/foo"), "");
1596+
wfile(td.path().join("bar"), "");
1597+
wfile(td.path().join("a/bar"), "");
1598+
1599+
let mut builder = WalkBuilder::new(td.path());
1600+
builder.ignore(false);
1601+
builder.git_ignore(false);
1602+
builder.git_global(false);
1603+
builder.git_exclude(false);
1604+
builder.add_custom_ignore_filename(&custom_ignore);
1605+
assert_paths(td.path(), &builder, &["bar", "a", "a/bar"]);
1606+
}
1607+
15881608
#[test]
15891609
fn gitignore() {
15901610
let td = TempDir::new("walk-test-").unwrap();

0 commit comments

Comments
 (0)