module documentation

Parsing of gitignore files.

For details for the matching rules, see https://git-scm.com/docs/gitignore

Important: When checking if directories are ignored, include a trailing slash in the path. For example, use "dir/" instead of "dir" to check if a directory is ignored.

Class IgnoreFilter Filter to apply gitignore patterns.
Class IgnoreFilterManager Ignore file manager with Git-compliant behavior.
Class IgnoreFilterStack Check for ignore status in multiple filters.
Class Pattern A single ignore pattern.
Function default_user_ignore_filter_path Return default user ignore filter path.
Function match_pattern Match a gitignore-style pattern against a path.
Function read_ignore_patterns Read a git ignore file.
Function translate Translate a gitignore pattern to a regular expression following Git rules exactly.
Function _check_parent_exclusion Check if a parent directory exclusion prevents negation patterns from taking effect.
Function _handle_double_asterisk Handle ** segment processing, returns (regex_part, skip_next).
Function _handle_leading_patterns Handle leading patterns like /**/, **/, or /.
Function _parent_directories Return parent directories for a path, with trailing slashes.
Function _pattern_excludes_parent Check if a pattern excludes a parent directory of the given path.
Function _pattern_to_str Convert a pattern to string, handling both Pattern objects and raw patterns.
Function _translate_segment Translate a single path segment to regex, following Git rules exactly.
def default_user_ignore_filter_path(config: Config) -> str:

Return default user ignore filter path.

Parameters
config:ConfigA Config object
Returns
strPath to a global ignore file
def match_pattern(path: bytes, pattern: bytes, ignorecase: bool = False) -> bool:

Match a gitignore-style pattern against a path.

Parameters
path:bytesPath to match
pattern:bytesPattern to match
ignorecase:boolWhether to do case-sensitive matching
Returns
boolbool indicating whether the pattern matched
def read_ignore_patterns(f: BinaryIO) -> Iterable[bytes]:

Read a git ignore file.

Returns: List of patterns

Parameters
f:BinaryIOFile-like object to read from
Returns
Iterable[bytes]Undocumented
def translate(pat: bytes) -> bytes:

Translate a gitignore pattern to a regular expression following Git rules exactly.

def _check_parent_exclusion(path: str, matching_patterns: Sequence[Pattern]) -> bool:

Check if a parent directory exclusion prevents negation patterns from taking effect.

Parameters
path:strPath to check
matching_patterns:Sequence[Pattern]List of Pattern objects that matched the path
Returns
boolTrue if parent exclusion applies (negation should be ineffective), False otherwise
def _handle_double_asterisk(segments: Sequence[bytes], i: int) -> tuple[bytes, bool]:

Handle ** segment processing, returns (regex_part, skip_next).

def _handle_leading_patterns(pat: bytes, res: bytes) -> tuple[bytes, bytes]:

Handle leading patterns like /**/, **/, or /.

def _parent_directories(path: str) -> list[str]:

Return parent directories for a path, with trailing slashes.

def _pattern_excludes_parent(pattern_str: str, path: str, final_pattern_str: str) -> bool:

Check if a pattern excludes a parent directory of the given path.

def _pattern_to_str(pattern: Pattern | bytes | str) -> str:

Convert a pattern to string, handling both Pattern objects and raw patterns.

def _translate_segment(segment: bytes) -> bytes:

Translate a single path segment to regex, following Git rules exactly.