summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2016-10-31 19:53:25 -0400
committerAndrew Gallant <jamslam@gmail.com>2016-10-31 19:53:25 -0400
commit971446a9af2d837e9a062cb6b4a473924c5af73c (patch)
tree139b3c09e416d8ef441a624f363e22bd22e1e79e
parent271f4d34f32bd80b7f38b9fba9f8b00d39fe2deb (diff)
Fixes a matching bug in the glob override matcher.
This was probably a transcription error when moving the ignore matcher code out of ripgrep core. Specifically, the override glob matcher should not ignore directories if they don't match. Fixes #206
-rw-r--r--ignore/src/overrides.rs23
-rw-r--r--tests/tests.rs10
2 files changed, 29 insertions, 4 deletions
diff --git a/ignore/src/overrides.rs b/ignore/src/overrides.rs
index c53a50f7..c737b04e 100644
--- a/ignore/src/overrides.rs
+++ b/ignore/src/overrides.rs
@@ -79,8 +79,9 @@ impl Override {
///
/// If there are no overrides, then this always returns `Match::None`.
///
- /// If there is at least one whitelist override, then this never returns
- /// `Match::None`, since non-matches are interpreted as ignored.
+ /// If there is at least one whitelist override and `is_dir` is false, then
+ /// this never returns `Match::None`, since non-matches are interpreted as
+ /// ignored.
///
/// The given path is matched to the globs relative to the path given
/// when building the override matcher. Specifically, before matching
@@ -97,7 +98,7 @@ impl Override {
return Match::None;
}
let mat = self.0.matched(path, is_dir).invert();
- if mat.is_none() && self.num_whitelists() > 0 {
+ if mat.is_none() && self.num_whitelists() > 0 && !is_dir {
return Match::Ignore(Glob::unmatched());
}
mat.map(move |giglob| Glob(GlobInner::Matched(giglob)))
@@ -166,7 +167,7 @@ mod tests {
assert!(ov.matched("a.foo", false).is_whitelist());
assert!(ov.matched("a.foo", true).is_whitelist());
assert!(ov.matched("a.rs", false).is_ignore());
- assert!(ov.matched("a.rs", true).is_ignore());
+ assert!(ov.matched("a.rs", true).is_none());
assert!(ov.matched("a.bar", false).is_ignore());
assert!(ov.matched("a.bar", true).is_ignore());
}
@@ -199,4 +200,18 @@ mod tests {
assert!(ov.matched("baz/a", false).is_whitelist());
assert!(ov.matched("baz/a/b", false).is_whitelist());
}
+
+ #[test]
+ fn allow_directories() {
+ // This tests that directories are NOT ignored when they are unmatched.
+ let ov = ov(&["*.rs"]);
+ assert!(ov.matched("foo.rs", false).is_whitelist());
+ assert!(ov.matched("foo.c", false).is_ignore());
+ assert!(ov.matched("foo", false).is_ignore());
+ assert!(ov.matched("foo", true).is_none());
+ assert!(ov.matched("src/foo.rs", false).is_whitelist());
+ assert!(ov.matched("src/foo.c", false).is_ignore());
+ assert!(ov.matched("src/foo", false).is_ignore());
+ assert!(ov.matched("src/foo", true).is_none());
+ }
}
diff --git a/tests/tests.rs b/tests/tests.rs
index 795c0996..65962c74 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -865,6 +865,16 @@ clean!(regression_184, "test", ".", |wd: WorkDir, mut cmd: Command| {
assert_eq!(lines, "baz:test\n");
});
+// See: https://github.com/BurntSushi/ripgrep/issues/206
+clean!(regression_206, "test", ".", |wd: WorkDir, mut cmd: Command| {
+ wd.create_dir("foo");
+ wd.create("foo/bar.txt", "test");
+ cmd.arg("-g").arg("*.txt");
+
+ let lines: String = wd.stdout(&mut cmd);
+ assert_eq!(lines, format!("{}:test\n", path("foo/bar.txt")));
+});
+
// See: https://github.com/BurntSushi/ripgrep/issues/20
sherlock!(feature_20_no_filename, "Sherlock", ".",
|wd: WorkDir, mut cmd: Command| {