southwark.repo

Modified Dulwich repository object.

New in version 0.3.0.

Classes:

Repo(root[, object_store, bare])

Modified Dulwich repository object.

Data:

_R

Invariant TypeVar bound to southwark.repo.Repo.

Functions:

get_user_identity(config[, kind])

Determine the identity to use for new commits.

class Repo(root, object_store=None, bare=None)[source]

Bases: Repo

Modified Dulwich repository object.

A git repository backed by local disk.

To open an existing repository, call the constructor with the path of the repository.

To create a new repository, use the Repo.init class method.

Parameters

root

Methods:

do_commit([message, committer, author, …])

Create a new commit.

init(path[, mkdir])

Create a new repository.

init_bare(path[, mkdir])

Create a new bare repository.

list_remotes()

Returns a mapping of remote names to remote URLs, for the repo’s current remotes.

reset_to(sha)

Reset the state of the repository to the given commit sha.

do_commit(message=None, committer=None, author=None, commit_timestamp=None, commit_timezone=None, author_timestamp=None, author_timezone=None, tree=None, encoding=None, ref=b'HEAD', merge_heads=None)[source]

Create a new commit.

If not specified, committer and author default to get_user_identity(..., 'COMMITTER') and get_user_identity(..., 'AUTHOR') respectively.

Parameters
  • message (Union[str, bytes, None]) – Commit message. Default None.

  • committer (Union[str, bytes, None]) – Committer fullname. Default None.

  • author (Union[str, bytes, None]) – Author fullname. Default None.

  • commit_timestamp (Optional[float]) – Commit timestamp (defaults to now). Default None.

  • commit_timezone (Optional[float]) – Commit timestamp timezone (defaults to GMT). Default None.

  • author_timestamp (Optional[float]) – Author timestamp (defaults to commit timestamp). Default None.

  • author_timezone (Optional[float]) – Author timestamp timezone (defaults to commit timestamp timezone). Default None.

  • tree (Optional[Any]) – SHA1 of the tree root to use (if not specified the current index will be committed). Default None.

  • encoding (Union[str, bytes, None]) – Encoding. Default None.

  • ref (bytes) – Optional ref to commit to (defaults to current branch). Default b'HEAD'.

  • merge_heads (Optional[Any]) – Merge heads (defaults to .git/MERGE_HEADS). Default None.

Return type

bytes

Returns

New commit SHA1

classmethod init(path, mkdir=False)[source]

Create a new repository.

Parameters
  • path (Union[str, Path, PathLike]) – Path in which to create the repository.

  • mkdir (bool) – Whether to create the directory if it doesn’t exist. Default False.

Return type

~_R

classmethod init_bare(path, mkdir=False)[source]

Create a new bare repository.

Parameters
Return type

~_R

list_remotes()[source]

Returns a mapping of remote names to remote URLs, for the repo’s current remotes.

New in version 0.7.0.

Return type

Dict[str, str]

reset_to(sha)[source]

Reset the state of the repository to the given commit sha.

Any files added in subsequent commits will be removed, any deleted will be restored, and any modified will be reverted.

New in version 0.8.0.

Parameters

sha (Union[str, bytes])

_R = TypeVar(_R, bound=Repo)

Type:    TypeVar

Invariant TypeVar bound to southwark.repo.Repo.

get_user_identity(config, kind=None)[source]

Determine the identity to use for new commits.

If kind is set, this first checks GIT_${KIND}_NAME and GIT_${KIND}_EMAIL.

If those variables are not set, then it will fall back to reading the user.name and user.email settings from the specified configuration.

If that also fails, then it will fall back to using the current users’ identity as obtained from the host system (e.g. the gecos field, $EMAIL, $USER@$(hostname -f).

Parameters
  • config (StackedConfig)

  • kind (Optional[str]) – Optional kind to return identity for, usually either 'AUTHOR' or 'COMMITTER'. Default None.

Return type

bytes

Returns

A user identity