southwark

Extensions to the Dulwich Git library.

Classes:

GitStatus(staged, unstaged, untracked)

Represents the output of status().

StagedDict

The values are lists of filenames, relative to the repository root.

Data:

_DR

Invariant TypeVar bound to dulwich.repo.Repo.

Functions:

assert_clean(repo[, allow_config])

Returns True if the working directory is clean.

check_git_status(repo_path)

Check the git status of the given repository.

clone(source[, target, bare, checkout, ...])

Clone a local or remote git repository.

get_tags([repo])

Returns a mapping of commit SHAs to tags.

get_tree_changes(repo)

Return add/delete/modify changes to tree by comparing the index to HEAD.

get_untracked_paths(path, index)

Returns a list of untracked files.

open_repo_closing(path_or_repo)

Returns a context manager which will return dulwich.repo.Repo objects unchanged, but will create a new dulwich.repo.Repo when a filesystem path is given.

status([repo])

Returns staged, unstaged, and untracked changes relative to the HEAD.

windows_clone_helper()

Contextmanager to aid cloning on Windows during tests.

namedtuple GitStatus(staged, unstaged, untracked)[source]

Bases: NamedTuple

Represents the output of status().

New in version 0.6.1.

Fields:
  1.  staged (StagedDict) – Dict with lists of staged paths.

  2.  unstaged (List[PathPlus]) – List of unstaged paths.

  3.  untracked (List[PathPlus]) – List of untracked, un-ignored & non-.git paths.

__repr__()

Return a nicely formatted representation string

typeddict StagedDict[source]

Bases: TypedDict

The values are lists of filenames, relative to the repository root.

New in version 0.6.1.

Required Keys:
_DR = TypeVar(_DR, bound=Repo)

Type:    TypeVar

Invariant TypeVar bound to dulwich.repo.Repo.

assert_clean(repo, allow_config=())[source]

Returns True if the working directory is clean.

If not, returns False and prints a helpful error message to stderr.

Parameters:
Return type:

bool

check_git_status(repo_path)[source]

Check the git status of the given repository.

Parameters:

repo_path (Union[str, Path, PathLike]) – Path to the repository root.

Return type:

Tuple[bool, List[str]]

Returns:

Whether the git working directory is clean, and the list of uncommitted files if it isn’t.

clone(source, target=None, bare=False, checkout=None, errstream=<_io.BufferedWriter name='<stderr>'>, origin='origin', depth=None, **kwargs)[source]

Clone a local or remote git repository.

Parameters:
  • source (Union[str, bytes]) – Path or URL for source repository.

  • target (Union[str, Path, PathLike, bytes, None]) – Path to target repository. Default None.

  • bare (bool) – Whether to create a bare repository. Default False.

  • checkout (Optional[bool]) – Whether to check-out HEAD after cloning. Default None.

  • errstream (IO) – Optional stream to write progress to. Default <_io.BufferedWriter name='<stderr>'>.

  • origin (Union[str, bytes]) – Name of remote from the repository used to clone. Default 'origin'.

  • depth (Optional[int]) – Depth to fetch at. Default None.

Return type:

Repo

Returns:

The cloned repository.

New in version 0.6.1.

Changed in version 0.7.2:
get_tags(repo='.')[source]

Returns a mapping of commit SHAs to tags.

Parameters:

repo (Union[Repo, str, Path, PathLike]) – Default '.'.

Return type:

Dict[str, str]

get_tree_changes(repo)[source]

Return add/delete/modify changes to tree by comparing the index to HEAD.

Parameters:

repo (Union[str, Path, PathLike, Repo]) – repo path or object.

Return type:

StagedDict

Returns:

Dictionary containing changes for each type of change.

New in version 0.6.1.

get_untracked_paths(path, index)[source]

Returns a list of untracked files.

Parameters:
Return type:

Iterator[str]

open_repo_closing(path_or_repo)[source]

Returns a context manager which will return dulwich.repo.Repo objects unchanged, but will create a new dulwich.repo.Repo when a filesystem path is given.

New in version 0.7.0.

Parameters:

path_or_repo – Either a dulwich.repo.Repo object or the path of a repository.

Return type:

ContextManager

Overloads:
status(repo='.')[source]

Returns staged, unstaged, and untracked changes relative to the HEAD.

Parameters:

repo (Union[Repo, str, Path, PathLike]) – Path to repository or repository object. Default '.'.

Return type:

GitStatus

windows_clone_helper()[source]

Contextmanager to aid cloning on Windows during tests.

New in version 0.8.0.

Attention

This function is intended only for use in tests.

Usage:

with windows_clone_helper():
    repo = clone(...)
Return type:

Iterator[None]