summaryrefslogtreecommitdiffstats
path: root/ignore
diff options
context:
space:
mode:
authorDavid Peter <sharkdp@users.noreply.github.com>2018-02-14 12:53:26 +0100
committerAndrew Gallant <jamslam@gmail.com>2018-02-14 06:53:26 -0500
commitb71a110ccf1c9cfe5f4c447cc3878a2e45ed7b8f (patch)
tree6f3c7e10f671c4d695130a835c4666d0852dcda6 /ignore
parent5c1af3c25dd1281ff3e8bd6cb13be9a2bb7a2e38 (diff)
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 #800
Diffstat (limited to 'ignore')
-rw-r--r--ignore/src/dir.rs18
-rw-r--r--ignore/src/walk.rs20
2 files changed, 30 insertions, 8 deletions
diff --git a/ignore/src/dir.rs b/ignore/src/dir.rs
index 923d574e..77ee6ad3 100644
--- a/ignore/src/dir.rs
+++ b/ignore/src/dir.rs
@@ -73,13 +73,6 @@ struct IgnoreOptions {
git_exclude: bool,
}
-impl IgnoreOptions {
- /// Returns true if at least one type of ignore rules should be matched.
- fn has_any_ignore_options(&self) -> bool {
- self.ignore || self.git_global || self.git_ignore || self.git_exclude
- }
-}
-
/// Ignore is a matcher useful for recursively walking one or more directories.
#[derive(Clone, Debug)]
pub struct Ignore(Arc<IgnoreInner>);
@@ -267,6 +260,15 @@ impl Ignore {
(ig, errs.into_error_option())
}
+ /// Returns true if at least one type of ignore rule should be matched.
+ fn has_any_ignore_rules(&self) -> bool {
+ let opts = self.0.opts;
+ let has_custom_ignore_files = !self.0.custom_ignore_filenames.is_empty();
+
+ opts.ignore || opts.git_global || opts.git_ignore
+ || opts.git_exclude || has_custom_ignore_files
+ }
+
/// Returns a match indicating whether the given file path should be
/// ignored or not.
///
@@ -295,7 +297,7 @@ impl Ignore {
}
}
let mut whitelisted = Match::None;
- if self.0.opts.has_any_ignore_options() {
+ if self.has_any_ignore_rules() {
let mat = self.matched_ignore(path, is_dir);
if mat.is_ignore() {
return mat;
diff --git a/ignore/src/walk.rs b/ignore/src/walk.rs
index 0ecd28bc..e43aa452 100644
--- a/ignore/src/walk.rs
+++ b/ignore/src/walk.rs
@@ -1586,6 +1586,26 @@ mod tests {
}
#[test]
+ fn custom_ignore_exclusive_use() {
+ let td = TempDir::new("walk-test-").unwrap();
+ let custom_ignore = ".customignore";
+ mkdirp(td.path().join("a"));
+ wfile(td.path().join(custom_ignore), "foo");
+ wfile(td.path().join("foo"), "");
+ wfile(td.path().join("a/foo"), "");
+ wfile(td.path().join("bar"), "");
+ wfile(td.path().join("a/bar"), "");
+
+ let mut builder = WalkBuilder::new(td.path());
+ builder.ignore(false);
+ builder.git_ignore(false);
+ builder.git_global(false);
+ builder.git_exclude(false);
+ builder.add_custom_ignore_filename(&custom_ignore);
+ assert_paths(td.path(), &builder, &["bar", "a", "a/bar"]);
+ }
+
+ #[test]
fn gitignore() {
let td = TempDir::new("walk-test-").unwrap();
mkdirp(td.path().join("a"));