Skip to content

Commit ff29956

Browse files
committed
Document gitignore patterns that raise despite Git accepting them
1 parent 811bde1 commit ff29956

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

‎pathspec/patterns/gitignore/basic.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ def pattern_to_regex(
133133
"""
134134
Convert the pattern into a regular expression.
135135
136+
Raises :class:`~pathspec.patterns.gitignore.base.GitIgnorePatternError`
137+
for invalid patterns, including a bare ``!`` (also when followed by
138+
unescaped trailing spaces) or an unmatched trailing backslash. Unlike
139+
blank lines and comments, these inputs do not return ``(None, None)``.
140+
Git accepts these lines without a diagnostic, so callers reading ignore
141+
files must be prepared to handle this exception even when Git accepts
142+
the file.
143+
136144
*pattern* (:class:`str` or :class:`bytes`) is the pattern to convert into a
137145
regular expression.
138146

‎pathspec/patterns/gitignore/spec.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ def pattern_to_regex(
167167
"""
168168
Convert the pattern into a regular expression.
169169
170+
Raises :class:`~pathspec.patterns.gitignore.base.GitIgnorePatternError`
171+
for invalid patterns, including a bare ``!`` (also when followed by
172+
unescaped trailing spaces) or an unmatched trailing backslash. Unlike
173+
blank lines and comments, these inputs do not return ``(None, None)``.
174+
Git accepts these lines without a diagnostic, so callers reading ignore
175+
files must be prepared to handle this exception even when Git accepts
176+
the file.
177+
170178
*pattern* (:class:`str` or :class:`bytes`) is the pattern to convert into a
171179
regular expression.
172180

0 commit comments

Comments
 (0)