git_wrapper package¶
Subpackages¶
Submodules¶
git_wrapper.branch module¶
This module acts as an interface for acting on git branches
-
class
git_wrapper.branch.
GitBranch
(git_repo, logger)[source]¶ Bases:
object
-
apply_diff
(branch_name, diff_path, message, signoff=False)[source]¶ Apply a diff on top of the specified branch.
Parameters: - branch_name (str) – The name of the branch or reference to apply the diff to
- diff_path (str) – Path to the diff file
- message (str) – Commit message
- signoff (bool) – Whether to add signed-off-by to commit message
-
apply_patch
(branch_name, path)[source]¶ Apply a git patch file on top of the specified branch.
Parameters: - branch_name (str) – The name of the branch or reference to apply the patch to
- path (str) – Path to a git-formatted patch file (cf. git format-patch)
-
cherry_equivalent
(upstream, head)[source]¶ Get patches that are in both upstream and head.
Parameters: - upstream (str) – Branch name
- head (str) – Branch name
-
cherry_on_head_only
(upstream, head)[source]¶ Get new patches between upstream and head.
Parameters: - upstream (str) – Branch name
- head (str) – Branch name
-
create
(name, start_ref, reset_if_exists=False)[source]¶ Create a local branch based on start_ref.
If the branch exists, do nothing or hard reset it if reset_if_exists is set.
Parameters: - name (str) – New branch’s name
- start_ref (str) – Reference (branch, commit, tag, …) to use as a starting point.
- reset_if_exists (bool) – Whether to hard reset the branch to start_ref if the branch already exists.
-
exists
(name, remote=None)[source]¶ Checks if a branch exists locally or on the specified remote.
Parameters: - name (str) – Name of the branch to find
- remote (str) – Remote name to check for the branch, or None if local
-
hard_reset
(branch='master', remote='origin', remote_branch='master', refresh=True)[source]¶ Perform a hard reset of a local branch to a remote branch.
Parameters: - branch (str) – Local branch to reset
- remote (str) – Remote use as base for the reset
- remote_branch (str) – Remote branch to reset to
- refresh (bool) – Whether to refresh the remote before resetting
-
hard_reset_to_ref
(branch, ref)[source]¶ Perform a hard reset of a local branch to any reference.
Parameters: - branch (str) – Local branch to reset
- ref (str) – Reference (commit, tag, …) to reset to
-
log_diff
(hash_from, hash_to, pattern='$full_message')[source]¶ Return a list of strings for log entries between two hashes.
- Any of the following placeholders may be used in the pattern:
- $hash The full commit hash
- $short_hash The short commit hash, similar to –abbrev-commit
- $message The commit message
- $summary First line of the commit message
- $full_message Complete commit info with hash, author, message. Similar to default “git log” ouput
- $author Commit author
- $date Date the commit was authored
Parameters: - hash_from (str) – A commit hash
- hash_to (str) – A commit hash
- pattern (str) – Formatter containing any of the placeholders above
-
rebase_to_hash
(branch_name, hash_)[source]¶ Perform a rebase from a specific reference to another.
Parameters: - branch_name (str) – The name of the branch to rebase on
- hash (str) – The commit hash or reference to rebase to
-
git_wrapper.commit module¶
This module acts as an interface for acting on git commits
-
class
git_wrapper.commit.
GitCommit
(git_repo, logger)[source]¶ Bases:
object
-
commit
(message, signoff=False)[source]¶ Create a commit for changes to tracked files in the repo. Equivalent to git commit -a -m <message>.
Parameters: - message (str) – The commit message
- signoff (bool) – Whether to add signed-off-by to commit message
-
git_wrapper.exceptions module¶
-
exception
git_wrapper.exceptions.
AbortException
[source]¶ Bases:
git_wrapper.exceptions.GitWrapperException
Error occurred while attempting to abort a command.
-
exception
git_wrapper.exceptions.
ChangeNotAppliedException
[source]¶ Bases:
git_wrapper.exceptions.GitWrapperException
Error occurred while applying a patch or diff onto a repo.
-
exception
git_wrapper.exceptions.
CheckoutException
[source]¶ Bases:
git_wrapper.exceptions.GitWrapperException
Error occurred while switching branch.
-
exception
git_wrapper.exceptions.
CommitMessageMissingException
[source]¶ Bases:
git_wrapper.exceptions.GitWrapperException
Cannot create a commit without a commit message.
-
exception
git_wrapper.exceptions.
DescribeException
[source]¶ Bases:
git_wrapper.exceptions.GitWrapperException
Error occurred while running the describe command.
-
exception
git_wrapper.exceptions.
DirtyRepositoryException
[source]¶ Bases:
git_wrapper.exceptions.GitWrapperException
Repository workspace is dirty.
-
exception
git_wrapper.exceptions.
FileDoesntExistException
[source]¶ Bases:
git_wrapper.exceptions.GitWrapperException
File doesn’t exist.
-
exception
git_wrapper.exceptions.
GitWrapperException
[source]¶ Bases:
Exception
Superclass for this library’s exceptions
-
exception
git_wrapper.exceptions.
RebaseException
[source]¶ Bases:
git_wrapper.exceptions.GitWrapperException
Error occurred during a rebase.
-
exception
git_wrapper.exceptions.
ReferenceNotFoundException
[source]¶ Bases:
git_wrapper.exceptions.GitWrapperException
Reference (commit, tag, branch, …) doesn’t exist.
-
exception
git_wrapper.exceptions.
RemoteException
[source]¶ Bases:
git_wrapper.exceptions.GitWrapperException
Error occurred while doing an operation on a remote.
-
exception
git_wrapper.exceptions.
RepoCreationException
[source]¶ Bases:
git_wrapper.exceptions.GitWrapperException
Error occurred while creating or cloning a repo.
-
exception
git_wrapper.exceptions.
ResetException
[source]¶ Bases:
git_wrapper.exceptions.GitWrapperException
Error occurred while resetting.
-
exception
git_wrapper.exceptions.
RevertException
[source]¶ Bases:
git_wrapper.exceptions.GitWrapperException
Error occurred while attempting to perform a revert.
git_wrapper.remote module¶
This module acts as an interface for acting on git remotes
-
class
git_wrapper.remote.
GitRemote
(git_repo, logger)[source]¶ Bases:
object
-
add
(name, url)[source]¶ Adds a remote to the given repo
Parameters: - name (str) – The name for the remote
- url (str) – The url to use for the remote
Return bool: True if the remote was added, False otherwise
-
fetch
(remote='origin')[source]¶ Refresh the specified remote
Parameters: remote (str) – Remote to fetch
-
git_wrapper.repo module¶
This module acts as an interface for common git tasks
-
class
git_wrapper.repo.
GitRepo
(path='', repo=None, logger=None)[source]¶ Bases:
object
Provides a wrapper to interact with a git repository
-
branch
¶ Return object to act on the repo’s branches
-
static
clone
(clone_from, clone_to, bare=False)[source]¶ Clone a repository.
Parameters: - clone_from (str) – The url or path to clone the repo from
- clone_to (str) – The local path to clone to
- bare (bool) – Whether to create a bare repo
Return GitRepo: Returns the newly created repo object
-
commit
¶ Return object to act on the repo’s commits
-
git
¶ Returns the git command for a given repo
-
remote
¶ Return object to act on the repo’s remotes
-
repo
¶ Returns the git repo for a given path
Return git.Repo: A reference to the internal git.Repo object
-
Module contents¶
Top-level package for git_wrapper.