git_dag.git_commands.GitCommandMutate

class git_dag.git_commands.GitCommandMutate(path: str | Path = '.', author: str = 'First Last <first.last@mail.com>', committer: str = 'Nom Prenom <nom.prenom@mail.com>', date: str | None = None, evolving_date: bool = False)[source]

Bases: GitCommandBase

Git commands that create/modify a repository.

Warning

The functionality in this class is rudimentary and is used only to create a repository for the tests.

Methods

add

Add files to the index.

br

Create/switch/delete branch.

clone_from_local

Clone a local repository with --depth 1 flag.

cm

Add commit(s).

config

Set a gonfig option.

fetch

Push.

init

Initialise a git repository.

init_remote_head

Init remote HEAD.

mg

Merge.

mg_multiple

Merge multiple (possibly orphan) branches without conflicts.

note

Add a git note to a given ref (e.g., hash, branch name).

pull

Push.

push

Push.

rebase

Rebase the current branch on the given branch (assuming no conflicts).

run_general

Run a general command.

stash

Stash.

tag

Create/delete annotated or lightweight tag.

Attributes

env

Return environment with author and committer to pass to commands.

add(files: dict[str, str]) None[source]

Add files to the index.

files specifies files to be added to the index (its format is {'filename': 'file contents', ...}). Names of files should not include the path to the repository (it is prepended).

br(branch: str, create: bool = False, orphan: bool = False, delete: bool = False) None[source]

Create/switch/delete branch.

classmethod clone_from_local(src_dir: Path | str, target_dir: Path | str, depth: int | None = None) None[source]

Clone a local repository with --depth 1 flag.

Note

This command doesn’t mutate a repository but appears under GitCommandMutate as it is meant to be used only in the unit tests and docs examples.

cm(messages: str | list[str], files: dict[str, str] | None = None, author_info: dict[str, str] | None = None) None[source]

Add commit(s).

If files is not specified an empty commit is created.

Note

When messages is a list, multiple empty commits are created (files cannot be specified).

config(option: str) None[source]

Set a gonfig option.

property env: dict[str, str]

Return environment with author and committer to pass to commands.

fetch() None[source]

Push.

init(branch: str = 'main', bare: bool = False) None[source]

Initialise a git repository.

init_remote_head(remote: str = 'origin', branch: str = 'main') None[source]

Init remote HEAD.

Note

When we clone an empty repo the remote HEAD is not initialized (we can use this method to do it manually). If we clone a repo with at least one commit on it (and a reasonable setup), then the remote HEAD would be initialized upon cloning.

mg(branch: str, message: str = 'm', strategy: str = 'theirs', unrelated: bool = False) None[source]

Merge.

mg_multiple(branches: list[str], message: str = 'm') None[source]

Merge multiple (possibly orphan) branches without conflicts.

note(msg: str, ref: str | None = None) None[source]

Add a git note to a given ref (e.g., hash, branch name).

pull() None[source]

Push.

push() None[source]

Push.

rebase(branch: str) None[source]

Rebase the current branch on the given branch (assuming no conflicts).

static run_general(command: str, env: dict[str, str] | None = None, encoding: str = 'utf-8', expected_stderr: str | None = None) str

Run a general command.

stash(files: dict[str, str], title: str | None = None, sleep: bool = True) None[source]

Stash.

Note

files specifies files to be modified before we stash (its format is {'filename': 'file contents', ...}. At least one file should be modified in order for git stash to be meaningful.

Warning

At the end of this method we sleep for 1 second otherwise stashes created very fast one after another might share the “index commit” (or might not, depending on delay). See https://github.com/drdv/git-dag/issues/84.

tag(name: str, message: str | None = None, ref: str | None = None, delete: bool = False) None[source]

Create/delete annotated or lightweight tag.

Note

When a message is specified, an annotated tag is created.