pontos.git package¶
- exception pontos.git.GitError(returncode, cmd, output=None, stderr=None)¶
Bases:
CalledProcessError
,PontosError
Error raised while executing a git command
- class pontos.git.ConfigScope(value)¶
Possible scopes for git settings
- GLOBAL¶
Apply setting user wide (~/.gitconfig)
- LOCAL¶
Apply setting to the local repository only (.git/config)
- SYSTEM¶
Apply settings system wide (/etc/gitconfig)
- WORKTREE¶
Similar to LOCAL except that $GIT_DIR/config.worktree is used if extensions.worktreeConfig is enabled. If not it’s the same as LOCAL.
- class pontos.git.Git(cwd=None)¶
Run git commands as subprocesses
Create a new Git instance
- Parameters:
cwd (Path | None) – Set the current working directory for the git commands
- init(*, bare=False)¶
Init a git repository
- Parameters:
bare (bool | None) – Wether to create a bare repository or not. Defaults to false.
- create_branch(branch, *, start_point=None)¶
Create a new branch
- rebase(base, *, head=None, onto=None, strategy=None)¶
Rebase a branch
- Parameters:
base (str) – Apply changes of this branch.
head (str | None) – Apply changes on this branch. If not set the current branch is used.
onto (str | None) – Apply changes on top of this branch.
strategy (MergeStrategy | None) – Merge strategy to use.
- clone(repo_url, destination, *, branch=None, remote=None, depth=None)¶
Clone a repository
- push(refspec=None, *, remote=None, branch=None, follow_tags=False, force=None, delete=None)¶
Push changes to remote repository
- Parameters:
remote (str | None) – Push changes to the named remote
branch (str | None) – Branch to push. Will only be considered in combination with a remote. Deprecated, use refs instead.
follow_tags (bool) – Push all tags pointing to a commit included in the to be pushed branch.
force (bool | None) – Force push changes.
delete (bool | None) – Delete remote refspec
- config(key, value=None, *, scope=None)¶
Get and set a git config
- Parameters:
key (str) – Key of the Git config setting. For example: core.filemode
value (str | None) – Value to set for a Git setting.
scope (ConfigScope | str | None) – Scope of the setting.
- Return type:
- cherry_pick(commits)¶
Apply changes of a commit(s) to the current branch
- Parameters:
commit – A single git reference (e.g. sha) of the commit or a list of git references.
- list_tags(*, sort=None, tag_name=None, sort_suffix=None)¶
List all available tags
- Parameters:
- Return type:
- add(files)¶
Add files to the git staging area
- commit(message, *, verify=None, gpg_sign=None, gpg_signing_key=None)¶
Create a new commit
- tag(tag, *, gpg_key_id=None, message=None, force=False, sign=None)¶
Create a Tag
- fetch(remote=None, refspec=None, *, verbose=False)¶
Fetch from changes from remote
- add_remote(remote, url)¶
Add a new git remote
- remote_url(remote='origin')¶
Get the url of a remote
- checkout(branch, *, start_point=None)¶
Checkout a branch
- log(*log_args, oneline=None, format=None)¶
Get log of a git repository
- show(*show_args, format=None, oneline=None, patch=None, objects=None)¶
Show various types of git objects
- Parameters:
format (str | None) – Pretty format the output.
oneline (bool | None) – Print the abbreviated commit id and commit message in one line per commit.
patch (bool | None) – True to generate patch output. False to suppress diff output.
show_args (str) – Additional arguments for git show
objects (str | Collection[str] | None) – Git objects (commits, refs, …) to get details for.
- Returns:
A list of details about the passed object the object if more then one object is passed. Otherwise a single details is returned.
- Return type:
- rev_list(*commit, max_parents=None, abbrev_commit=False)¶
Lists commit objects in reverse chronological order
- Parameters:
- Return type:
Examples
This will “list all the commits which are reachable from foo or bar, but not from baz”.
from pontos.git import Git git = Git() git.rev_list("foo", "bar", "^baz")
This will return the first commit of foo.
from pontos.git import Git git = Git() git.rev_list("foo", max_parents=0)
- move(old, new)¶
Move a file from old to new
- remove(to_remove)¶
Remove a file from git
- status(files=None)¶
Get information about the current git status.
- Parameters:
files (Iterable[PathLike] | None) – specify an iterable of
os.PathLike
and exclude all other paths for the status.- Returns:
An iterator of
StatusEntry
instances that contain the status of the specific files.- Return type:
- reset(commit, *, mode)¶
Reset the git history
- Parameters:
Examples
This will “list all the commits which are reachable from foo or bar, but not from baz”.
from pontos.git import Git, ResetMode git = Git() git.reset("HEAD^", mode=ResetMode.HARD)
- class pontos.git.MergeStrategy(value)¶
Possible strategies for a merge
- ORT¶
- ORT_OURS¶
- RECURSIVE¶
- OCTOPUS¶
- OURS¶
- SUBTREE¶
- class pontos.git.ResetMode(value)¶
An enumeration.
- class pontos.git.Status(value)¶
Status of a file in git