Skip to content

Commit 5eb60f2

Browse files
committed
Fix error when trying to match relative paths with exclude patterns
* bdx/binary.py (Exclusion.matches): Don't attempt to convert the path into a path relative to root dir if it's not a subpath of the root dir.
1 parent c493753 commit 5eb60f2

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

bdx/binary.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -593,13 +593,16 @@ def matches(self, path: Path, root_dir: Path) -> bool:
593593
"""Return true if this exclusion pattern matches ``path``."""
594594
flags = glob.GLOBSTAR
595595
relative = path
596-
if path.is_absolute():
596+
if path.is_absolute() and root_dir in path.parents:
597597
relative = path.relative_to(root_dir)
598-
return glob.globmatch(
598+
match = glob.globmatch(
599599
path, self.pattern, root_dir=root_dir, flags=flags
600-
) or glob.globmatch(
601-
relative, self.pattern, root_dir=root_dir, flags=flags
602600
)
601+
if not match and relative:
602+
match = glob.globmatch(
603+
relative, self.pattern, root_dir=root_dir, flags=flags
604+
)
605+
return match
603606

604607

605608
class FileSource:

0 commit comments

Comments
 (0)