Fix whitelisting precedence.

Once a file is known to be whitelisted, we shouldn't check any ancestor
gitignores.
This commit is contained in:
Andrew Gallant
2016-09-24 20:09:29 -04:00
parent 71ad9bf393
commit 872a107658

View File

@@ -217,17 +217,25 @@ impl Ignore {
return true;
}
if !self.no_ignore {
let mut whitelisted = false;
for id in self.stack.iter().rev() {
let mat = id.matched(path, is_dir);
// println!("path: {}, mat: {:?}, id: {:?}",
// path.display(), mat, id);
if let Some(is_ignored) = self.ignore_match(path, mat) {
if is_ignored {
return true;
}
// If this path is whitelisted by an ignore, then
// fallthrough and let the file type matcher have a say.
whitelisted = true;
break;
}
}
// If the file has been whitelisted, then we have to stop checking
// parent directories. The only thing that can override a whitelist
// at this point is a type filter.
if !whitelisted {
let mut path = path.to_path_buf();
for id in self.parent_stack.iter().rev() {
if let Some(ref dirname) = id.name {
@@ -239,11 +247,13 @@ impl Ignore {
return true;
}
// If this path is whitelisted by an ignore, then
// fallthrough and let the file type matcher have a say.
// fallthrough and let the file type matcher have a
// say.
break;
}
}
}
}
let mat = self.types.matched(path, is_dir);
if let Some(is_ignored) = self.ignore_match(path, mat) {
return is_ignored;