Handle relative ignores better?
This commit is contained in:
parent
93b7b0343f
commit
8770ae3967
|
@ -145,12 +145,12 @@ pub fn get_args() -> Args {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut ignores = vec![];
|
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("*.pyc"),
|
||||||
String::from("*.swp"),
|
String::from("*.swp"),
|
||||||
format!("*{}.git{}**", MAIN_SEPARATOR, MAIN_SEPARATOR),
|
format!("**{}.git{}**", MAIN_SEPARATOR, MAIN_SEPARATOR),
|
||||||
format!("*{}.hg{}**", MAIN_SEPARATOR, MAIN_SEPARATOR),
|
format!("**{}.hg{}**", MAIN_SEPARATOR, MAIN_SEPARATOR),
|
||||||
format!("*{}.svn{}**", MAIN_SEPARATOR, MAIN_SEPARATOR)];
|
format!("**{}.svn{}**", MAIN_SEPARATOR, MAIN_SEPARATOR)];
|
||||||
|
|
||||||
|
|
||||||
if args.occurrences_of("no-default-ignore") == 0 {
|
if args.occurrences_of("no-default-ignore") == 0 {
|
||||||
|
|
|
@ -35,9 +35,14 @@ impl NotificationFilter {
|
||||||
|
|
||||||
let mut ignore_set_builder = GlobSetBuilder::new();
|
let mut ignore_set_builder = GlobSetBuilder::new();
|
||||||
for i in &ignores {
|
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());
|
let filter_set = try!(filter_set_builder.build());
|
||||||
|
@ -99,6 +104,14 @@ mod tests {
|
||||||
assert!(!filter.is_excluded(&Path::new("foo")));
|
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]
|
#[test]
|
||||||
fn test_multiple_filters() {
|
fn test_multiple_filters() {
|
||||||
let filters = vec![String::from("*.rs"), String::from("*.toml")];
|
let filters = vec![String::from("*.rs"), String::from("*.toml")];
|
||||||
|
|
Loading…
Reference in New Issue