mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-07-26 09:42:00 -07:00
Compare commits
4 Commits
grep-searc
...
ignore-0.1
Author | SHA1 | Date | |
---|---|---|---|
|
5f87c03189 | ||
|
971446a9af | ||
|
271f4d34f3 | ||
|
67af19d723 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@ tags
|
|||||||
target
|
target
|
||||||
/grep/Cargo.lock
|
/grep/Cargo.lock
|
||||||
/globset/Cargo.lock
|
/globset/Cargo.lock
|
||||||
|
/ignore/Cargo.lock
|
||||||
|
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -1,6 +1,6 @@
|
|||||||
[root]
|
[root]
|
||||||
name = "ripgrep"
|
name = "ripgrep"
|
||||||
version = "0.2.3"
|
version = "0.2.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ctrlc 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ctrlc 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "ignore"
|
name = "ignore"
|
||||||
version = "0.1.1" #:version
|
version = "0.1.2" #:version
|
||||||
authors = ["Andrew Gallant <jamslam@gmail.com>"]
|
authors = ["Andrew Gallant <jamslam@gmail.com>"]
|
||||||
description = """
|
description = """
|
||||||
A fast library for efficiently matching ignore files such as `.gitignore`
|
A fast library for efficiently matching ignore files such as `.gitignore`
|
||||||
|
@@ -79,8 +79,9 @@ impl Override {
|
|||||||
///
|
///
|
||||||
/// If there are no overrides, then this always returns `Match::None`.
|
/// If there are no overrides, then this always returns `Match::None`.
|
||||||
///
|
///
|
||||||
/// If there is at least one whitelist override, then this never returns
|
/// If there is at least one whitelist override and `is_dir` is false, then
|
||||||
/// `Match::None`, since non-matches are interpreted as ignored.
|
/// 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
|
/// The given path is matched to the globs relative to the path given
|
||||||
/// when building the override matcher. Specifically, before matching
|
/// when building the override matcher. Specifically, before matching
|
||||||
@@ -97,7 +98,7 @@ impl Override {
|
|||||||
return Match::None;
|
return Match::None;
|
||||||
}
|
}
|
||||||
let mat = self.0.matched(path, is_dir).invert();
|
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());
|
return Match::Ignore(Glob::unmatched());
|
||||||
}
|
}
|
||||||
mat.map(move |giglob| Glob(GlobInner::Matched(giglob)))
|
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", false).is_whitelist());
|
||||||
assert!(ov.matched("a.foo", true).is_whitelist());
|
assert!(ov.matched("a.foo", true).is_whitelist());
|
||||||
assert!(ov.matched("a.rs", false).is_ignore());
|
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", false).is_ignore());
|
||||||
assert!(ov.matched("a.bar", true).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", false).is_whitelist());
|
||||||
assert!(ov.matched("baz/a/b", 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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -865,6 +865,16 @@ clean!(regression_184, "test", ".", |wd: WorkDir, mut cmd: Command| {
|
|||||||
assert_eq!(lines, "baz:test\n");
|
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
|
// See: https://github.com/BurntSushi/ripgrep/issues/20
|
||||||
sherlock!(feature_20_no_filename, "Sherlock", ".",
|
sherlock!(feature_20_no_filename, "Sherlock", ".",
|
||||||
|wd: WorkDir, mut cmd: Command| {
|
|wd: WorkDir, mut cmd: Command| {
|
||||||
|
Reference in New Issue
Block a user