dulwich.ignore module

Parsing of gitignore files.

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

class dulwich.ignore.IgnoreFilter(patterns: Iterable[bytes], ignorecase: bool = False, path=None)

Bases: object

append_pattern(pattern: bytes) None

Add a pattern to the set.

find_matching(path: Union[bytes, str]) Iterable[Pattern]

Yield all matching patterns for path.

Parameters

path – Path to match

Returns

Iterator over iterators

classmethod from_path(path, ignorecase: bool = False) IgnoreFilter
is_ignored(path: bytes) Optional[bool]

Check whether a path is ignored.

For directories, include a trailing slash.

Returns: status is None if file is not mentioned, True if it is

included, False if it is explicitly excluded.

class dulwich.ignore.IgnoreFilterManager(top_path: str, global_filters: List[IgnoreFilter], ignorecase: bool)

Bases: object

Ignore file manager.

find_matching(path: str) Iterable[Pattern]

Find matching patterns for path.

Parameters

path – Path to check

Returns

Iterator over Pattern instances

classmethod from_repo(repo: Repo) IgnoreFilterManager

Create a IgnoreFilterManager from a repository.

Parameters

repo – Repository object

Returns

A IgnoreFilterManager object

is_ignored(path: str) Optional[bool]

Check whether a path is explicitly included or excluded in ignores.

Parameters

path – Path to check

Returns

None if the file is not mentioned, True if it is included, False if it is explicitly excluded.

class dulwich.ignore.IgnoreFilterStack(filters)

Bases: object

Check for ignore status in multiple filters.

is_ignored(path: str) Optional[bool]

Check whether a path is explicitly included or excluded in ignores.

Parameters

path – Path to check

Returns

None if the file is not mentioned, True if it is included, False if it is explicitly excluded.

class dulwich.ignore.Pattern(pattern: bytes, ignorecase: bool = False)

Bases: object

A single ignore pattern.

match(path: bytes) bool

Try to match a path against this ignore pattern.

Parameters

path – Path to match (relative to ignore location)

Returns: boolean

dulwich.ignore.default_user_ignore_filter_path(config: Config) str

Return default user ignore filter path.

Parameters

config – A Config object

Returns

Path to a global ignore file

dulwich.ignore.match_pattern(path: bytes, pattern: bytes, ignorecase: bool = False) bool

Match a gitignore-style pattern against a path.

Parameters
  • path – Path to match

  • pattern – Pattern to match

  • ignorecase – Whether to do case-sensitive matching

Returns

bool indicating whether the pattern matched

dulwich.ignore.read_ignore_patterns(f: BinaryIO) Iterable[bytes]

Read a git ignore file.

Parameters

f – File-like object to read from

Returns: List of patterns

dulwich.ignore.translate(pat: bytes) bytes

Translate a shell PATTERN to a regular expression.

There is no way to quote meta-characters.

Originally copied from fnmatch in Python 2.7, but modified for Dulwich to cope with features in Git ignore patterns.