Handle relative ignores better?

This commit is contained in:
Matt Green 2017-10-07 15:50:47 -04:00
parent 93b7b0343f
commit 8770ae3967
2 changed files with 19 additions and 6 deletions

View File

@ -145,12 +145,12 @@ pub fn get_args() -> Args {
}
let mut ignores = vec![];
let default_ignores = vec![format!("*{}.DS_Store", MAIN_SEPARATOR),
let default_ignores = vec![format!("**{}.DS_Store", MAIN_SEPARATOR),
String::from("*.pyc"),
String::from("*.swp"),
format!("*{}.git{}**", MAIN_SEPARATOR, MAIN_SEPARATOR),
format!("*{}.hg{}**", MAIN_SEPARATOR, MAIN_SEPARATOR),
format!("*{}.svn{}**", MAIN_SEPARATOR, MAIN_SEPARATOR)];
format!("**{}.git{}**", MAIN_SEPARATOR, MAIN_SEPARATOR),
format!("**{}.hg{}**", MAIN_SEPARATOR, MAIN_SEPARATOR),
format!("**{}.svn{}**", MAIN_SEPARATOR, MAIN_SEPARATOR)];
if args.occurrences_of("no-default-ignore") == 0 {

View File

@ -35,9 +35,14 @@ impl NotificationFilter {
let mut ignore_set_builder = GlobSetBuilder::new();
for i in &ignores {
ignore_set_builder.add(try!(Glob::new(i)));
let mut ignore_path = Path::new(i).to_path_buf();
if ignore_path.is_relative() && !i.starts_with("*") {
ignore_path = Path::new("**").join(&ignore_path);
}
let pattern = ignore_path.to_str().unwrap();
ignore_set_builder.add(try!(Glob::new(pattern)));
debug!("Adding ignore: \"{}\"", i);
debug!("Adding ignore: \"{}\"", pattern);
}
let filter_set = try!(filter_set_builder.build());
@ -99,6 +104,14 @@ mod tests {
assert!(!filter.is_excluded(&Path::new("foo")));
}
#[test]
fn test_filename() {
let filter = NotificationFilter::new(vec![], vec![String::from("test.json")], gitignore::load(&vec![])).unwrap();
assert!(filter.is_excluded(&Path::new("/path/to/test.json")));
assert!(filter.is_excluded(&Path::new("test.json")));
}
#[test]
fn test_multiple_filters() {
let filters = vec![String::from("*.rs"), String::from("*.toml")];