API Reference

class giterator.Git(path: Path | str)

Represents a local work tree and repo.

Parameters:

path – The path to an existing work tree or local repo.

path: Path

The path where this instance is located.

__call__(*command, env: dict = None, cwd: Path = None) str

Run a git command in this repo. For example:

Git(...)('log', '-1')
git(*command, env: dict = None, cwd: Path = None) str

Run a git command in this repo. For example:

Git(...)('log', '-1')
init(user: User = None) None

Create an empty Git repository or reinitialize an existing one. If the path doesn’t exist, it will be created. This includes any missing parent directories.

Parameters:

user – The user to configure in the local repo.

commit(msg: str, author_date: date | datetime | str = None, commit_date: date | datetime | str = None, short: bool = True) str

Commit changes in this repo, including and new or deleted files.

Parameters:
  • msg – The commit message.

  • author_date – The author date.

  • commit_date – The commit date. Defaults to author date if not specified.

  • short – Return the short commit hash instead of the full 40-character hash.

tag(name: str) None

Create a tag with the specified name.

tags() List[str]

Return a list of tags in this repo.

tag_hashes() Dict[str, str]

Return a mapping of tag name to commit hash.

branch(name: str) None

Create and checkout a branch with the specified name.

branches() List[str]

Return a list of branches in this repo.

branch_hashes() Dict[str, str]

Return a mapping of branch name to commit hash.

class giterator.User(name: str, email: str)

Represents a git user, for configuring a repo.

class giterator.testing.Repo(path: Path | str)

A repo for use in automated tests.

classmethod make(path: Path | str, user: User = None)

Make a repo at the path specified and ensure a user is configured in the repo. The user can be specified.

commit(msg: str, author_date: date | datetime | str = None, commit_date: date | datetime | str = None, short: bool = True) str

Commit changes in this repo, including and new or deleted files.

Parameters:
  • msg – The commit message.

  • author_date – The author date.

  • commit_date – The commit date. Defaults to author date if not specified.

  • short – Return the short commit hash instead of the full 40-character hash.

commit_content(prefix: str, dt: datetime = None, *, tag: str = None, branch: str = None, short: bool = True) str

Write new context based on the prefix and then commit it at the specified datetime, or using at a sequence of increasing datetimes if not specified.