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, ignorecase=False)

Bases: object

append_pattern(pattern)

Add a pattern to the set.

find_matching(path)

Yield all matching patterns for path.

Parameters:path – Path to match
Returns:Iterator over iterators
classmethod from_path(path, ignorecase=False)
is_ignored(path)

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, global_filters, ignorecase)

Bases: object

Ignore file manager.

find_matching(path)

Find matching patterns for path.

Stops after the first ignore file with matches.

Parameters:path – Path to check
Returns:Iterator over Pattern instances
classmethod from_repo(repo)

Create a IgnoreFilterManager from a repository.

Parameters:repo – Repository object
Returns:A IgnoreFilterManager object
is_ignored(path)

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)

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, ignorecase=False)

Bases: object

A single ignore pattern.

match(path)

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)

Return default user ignore filter path.

Parameters:config – A Config object
Returns:Path to a global ignore file
dulwich.ignore.match_pattern(path, pattern, ignorecase=False)

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)

Read a git ignore file.

Parameters:f – File-like object to read from
Returns:List of patterns
dulwich.ignore.translate(pat)

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.