diff --git a/pathspec/patterns/gitignore/basic.py b/pathspec/patterns/gitignore/basic.py index e93169c..93539a8 100644 --- a/pathspec/patterns/gitignore/basic.py +++ b/pathspec/patterns/gitignore/basic.py @@ -133,6 +133,14 @@ def pattern_to_regex( """ Convert the pattern into a regular expression. + Raises :class:`~pathspec.patterns.gitignore.base.GitIgnorePatternError` + for invalid patterns, including a bare ``!`` (also when followed by + unescaped trailing spaces) or an unmatched trailing backslash. Unlike + blank lines and comments, these inputs do not return ``(None, None)``. + Git accepts these lines without a diagnostic, so callers reading ignore + files must be prepared to handle this exception even when Git accepts + the file. + *pattern* (:class:`str` or :class:`bytes`) is the pattern to convert into a regular expression. diff --git a/pathspec/patterns/gitignore/spec.py b/pathspec/patterns/gitignore/spec.py index 28b299f..3da9f31 100644 --- a/pathspec/patterns/gitignore/spec.py +++ b/pathspec/patterns/gitignore/spec.py @@ -167,6 +167,14 @@ def pattern_to_regex( """ Convert the pattern into a regular expression. + Raises :class:`~pathspec.patterns.gitignore.base.GitIgnorePatternError` + for invalid patterns, including a bare ``!`` (also when followed by + unescaped trailing spaces) or an unmatched trailing backslash. Unlike + blank lines and comments, these inputs do not return ``(None, None)``. + Git accepts these lines without a diagnostic, so callers reading ignore + files must be prepared to handle this exception even when Git accepts + the file. + *pattern* (:class:`str` or :class:`bytes`) is the pattern to convert into a regular expression.