diff options
author | Andrew Gallant <jamslam@gmail.com> | 2016-10-16 10:15:11 -0400 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2016-10-16 10:15:11 -0400 |
commit | f2e1711781d245eca7bc9087fc833cf59af98a0b (patch) | |
tree | e49b35d6446f18d55cefe63feaf333c0d8cc6704 /src | |
parent | 94d600e6e160c817176c48a07cb8ac1d29c553d7 (diff) |
Fix bug when processing parent gitignore files.
This particular bug was triggered whenever a search was run in a directory
with a parent directory that contains a relevant .gitignore file. In
particular, before matching against a parent directory's gitignore rules,
a path's leading `./` was not stripped, which results in errant matching.
We now make sure `./` is stripped.
Fixes #184.
Diffstat (limited to 'src')
-rw-r--r-- | src/ignore.rs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/ignore.rs b/src/ignore.rs index d24909c5..a8cbac1a 100644 --- a/src/ignore.rs +++ b/src/ignore.rs @@ -20,7 +20,7 @@ use std::io; use std::path::{Path, PathBuf}; use gitignore::{self, Gitignore, GitignoreBuilder, Match, Pattern}; -use pathutil::{file_name, is_hidden}; +use pathutil::{file_name, is_hidden, strip_prefix}; use types::Types; const IGNORE_NAMES: &'static [&'static str] = &[ @@ -222,7 +222,10 @@ impl Ignore { /// Returns true if and only if the given file path should be ignored. pub fn ignored<P: AsRef<Path>>(&self, path: P, is_dir: bool) -> bool { - let path = path.as_ref(); + let mut path = path.as_ref(); + if let Some(p) = strip_prefix("./", path) { + path = p; + } let mat = self.overrides.matched(path, is_dir); if let Some(is_ignored) = self.ignore_match(path, mat) { return is_ignored; |