ignore: support custom file names

This commit adds support for ignore files with custom names. This
allows for application specific ignorefile names, e.g. using
`.fdignore` for `fd`.

See also: https://github.com/BurntSushi/ripgrep/issues/673

See also: https://github.com/sharkdp/fd/issues/156
This commit is contained in:
ptzz
2018-01-29 22:06:05 +01:00
committed by Andrew Gallant
parent 8514d4fbb4
commit 3cb4d1337e
3 changed files with 134 additions and 13 deletions

View File

@@ -538,7 +538,7 @@ impl WalkBuilder {
self
}
/// Add an ignore file to the matcher.
/// Add a global ignore file to the matcher.
///
/// This has lower precedence than all other sources of ignore rules.
///
@@ -557,6 +557,20 @@ impl WalkBuilder {
errs.into_error_option()
}
/// Add a custom ignore file name
///
/// These ignore files have higher precedence than all other ignore files.
///
/// When specifying multiple names, earlier names have lower precedence than
/// later names.
pub fn add_custom_ignore_filename<S: AsRef<OsStr>>(
&mut self,
file_name: S
) -> &mut WalkBuilder {
self.ig_builder.add_custom_ignore_filename(file_name);
self
}
/// Add an override matcher.
///
/// By default, no override matcher is used.
@@ -1476,6 +1490,22 @@ mod tests {
]);
}
#[test]
fn custom_ignore() {
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.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();