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 files to the index.
Create/switch/delete branch.
Clone a local repository with
--depth 1
flag.Add commit(s).
Set a gonfig option.
Push.
Initialise a git repository.
Init remote HEAD.
Merge.
Merge multiple (possibly orphan) branches without conflicts.
Add a git note to a given ref (e.g., hash, branch name).
Push.
Push.
Rebase the current branch on the given branch (assuming no conflicts).
Run a general command.
Stash.
Create/delete annotated or lightweight tag.
Attributes
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).
- property env: dict[str, str]¶
Return environment with author and committer to pass to commands.
- 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).
- 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 forgit 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.