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>(&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; diff --git a/tests/tests.rs b/tests/tests.rs index d6fe35d2..a559045c 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -837,6 +837,20 @@ clean!( assert_eq!(lines, TESTCASE); }); +// See: https://github.com/BurntSushi/ripgrep/issues/184 +clean!(regression_184, "test", ".", |wd: WorkDir, mut cmd: Command| { + wd.create(".gitignore", ".*"); + wd.create_dir("foo/bar"); + wd.create("foo/bar/baz", "test"); + + let lines: String = wd.stdout(&mut cmd); + assert_eq!(lines, format!("{}:test\n", path("foo/bar/baz"))); + + cmd.current_dir(wd.path().join("./foo/bar")); + let lines: String = wd.stdout(&mut cmd); + assert_eq!(lines, "baz:test\n"); +}); + // See: https://github.com/BurntSushi/ripgrep/issues/20 sherlock!(feature_20_no_filename, "Sherlock", ".", |wd: WorkDir, mut cmd: Command| {