[ignore] Fix matched_path_or_any_parents() for patterns ending in slash

In `matched_path_or_any_parents()` implementation, we missed the point
that when we start walking up the tree, we have to set `is_dir` to
`true`, so path `ROOT/a/b/c` matches pattern `/a/`, although the
original path is not a dir.
This commit is contained in:
Behnam Esfahbod
2017-07-12 21:55:07 -06:00
committed by Andrew Gallant
parent 1c03298903
commit 0668c74ed4
2 changed files with 140 additions and 104 deletions

View File

@@ -220,15 +220,17 @@ impl Gitignore {
!path.has_root(),
"path is expect to be under the root"
);
loop {
match self.matched_stripped(path, is_dir) {
Match::None => match path.parent() {
Some(parent) => path = parent,
None => return Match::None,
},
match self.matched_stripped(path, is_dir) {
Match::None => (), // walk up
a_match => return a_match,
}
while let Some(parent) = path.parent() {
match self.matched_stripped(parent, /* is_dir */ true) {
Match::None => path = parent, // walk up
a_match => return a_match,
}
}
Match::None
}
/// Like matched, but takes a path that has already been stripped.