# `gbp.git.repository.GitRepository(object)` class documentation

Part of `gbp.git.repository` (View In Hierarchy)

Known subclasses: gbp.pkg.git.PkgGitRepository

Represents a git repository at path. It's currently assumed that the git repository is stored in a directory named .git/ below path.

Raises | GitRepositoryError | on git errors GitRepositoryError is raised by all methods.

Method | __init__ | No summary
Class Method | git_inout | As _git_inout but can be used without an instance
Method | path | The absolute path to the repository
Method | git_dir | The absolute path to git's metadata
Method | bare | Whether this is a bare repository
Method | tags | List of all tags in the repository
Method | branch | The currently checked out branch
Method | head | SHA1 of the current HEAD
Method | rename_branch | Rename branch
Method | create_branch | Create a new branch
Method | delete_branch | Delete branch branch
Method | get_branch | On what branch is the current working copy
Method | has_branch | Check if the repository has branch named branch.
Method | set_branch | Switch to branch branch
Method | get_merge_branch | Get the branch we'd merge from
Method | get_merge_base | Get the common ancestor between two commits
Method | merge | Merge changes from the named commit into the current branch
Method | abort_merge | Abort a merge
Method | is_in_merge | Undocumented
Method | is_fast_forward | Check if an update from from_branch to to_branch would be a fast forward or if the branch is up to date already.
Method | get_local_branches | Get a list of local branches
Method | get_remote_branches | Get a list of remote branches
Method | update_ref | Update ref ref to commit new if ref currently points to old
Method | branch_contains | Check if branch branch contains commit commit
Method | set_upstream_branch | Set upstream branches for local branch
Method | get_upstream_branch | Get upstream branch for the local branch
Method | create_tag | Create a new tag.
Method | delete_tag | Delete a tag named tag
Method | move_tag | Undocumented
Method | has_tag | Check if the repository has a tag named tag.
Method | describe | Describe commit, relative to the latest tag reachable from it.
Method | find_tag | Find the closest tag to a given commit
Method | find_branch_tag | Find the closest tag on a certain branch to a given commit
Method | get_tags | List tags
Method | verify_tag | Verify a signed tag
Method | force_head | Force HEAD to a specific commit
Method | is_clean | Does the repository contain any uncommitted modifications?
Method | clean | Remove untracked files from the working tree.
Method | status | Check status of repository.
Method | is_empty | Is the repository empty?
Method | rev_parse | Find the SHA1 of a given name
Static Method | strip_sha1 | Strip a given sha1 and check if the resulting hash has the expected length.
Method | checkout | Checkout treeish
Method | has_treeish | Check if the repository has the treeish object treeish.
Method | write_tree | Create a tree object from the current index
Method | make_tree | Create a tree based on contents.
Method | get_obj_type | Get type of a git repository object
Method | list_tree | Get a trees content. It yields tuples that match the 'ls-tree' output: (mode, type, sha1, path). When sizes is True, includes object sizes: (mode, type, sha1, size, path)
Method | get_config | Gets the config value associated with name
Method | set_config | Set a git config value in this repository
Method | set_user_name | Sets the full name to use for git commits.
Method | set_user_email | Sets the email address to use for git commits.
Method | get_author_info | Determine a sane values for author name and author email from git's config and environment variables.
Method | get_remotes | Get a list of remote repositories
Method | get_remote_repos | Get all remote repositories
Method | has_remote_repo | Do we know about a remote named name?
Method | add_remote_repo | Add a tracked remote repository
Method | remove_remote_repo | Undocumented
Method | fetch | Download objects and refs from another repository.
Method | pull | Fetch and merge from another repository
Method | push | Push changes to the remote repo
Method | push_tag | Push a tag to the remote repo
Method | add_files | Add files to a the repository
Method | remove_files | Remove files from the repository
Method | list_files | List files in index and working tree
Method | write_file | Hash a single file and write it into the object database
Method | rename_file | Rename file, directory, or symlink
Method | commit_staged | Commit currently staged files to the repository
Method | commit_all | No summary
Method | commit_files | Commit the given files to the repository
Method | commit_dir | Replace the current tip of branch branch with the contents from unpack_dir
Method | commit_tree | Commit a tree with commit msg msg and parents parents
Method | get_commits | Get commits from since to until touching paths
Method | show | Show a git object
Method | grep_log | Get commmits matching regex
Method | get_subject | Gets the subject of a commit.
Method | get_commit_info | Look up data of a specific commit-ish. Dereferences given commit-ish to the commit it points to.
Method | format_patches | Output the commits between start and end as patches in output_dir.
Method | apply_patch | Apply a patch using git apply
Method | diff | Diff two git repository objects
Method | diff_status | Get file-status of two git repository objects
Method | archive | Create an archive from a treeish
Method | collect_garbage | Cleanup unnecessary files and optimize the local repository
Method | has_submodules | Does the repo have any submodules?
Method | add_submodule | Add a submodule
Method | update_submodules | Update all submodules
Method | get_submodules | List the submodules of treeish
Class Method | create | Create a repository at path
Class Method | clone | Clone a git repository at remote to path.
Instance Variable | _path | The path to the working tree
Instance Variable | _bare | Whether this is a bare repository
Method | _check_bare | Check whether this is a bare repository
Method | _get_git_dir | Undocumented
Instance Variable | _git_dir | Undocumented
Method | _check_repo | Undocumented
Static Method | __build_env | Prepare environment for subprocess calls
Method | _git_getoutput | Run a git command and return the output
Method | _git_inout | Run a git command with input and return output
Method | _git_command | Execute git command with arguments args and environment env at path.
Method | _cmd_has_feature | Check if the git command has certain feature enabled.
Method | _get_branches | Get a list of branches
Method | _status | Undocumented
Method | _commit | Undocumented

_path =
The path to the working tree
(type: `str`)
_bare =
Whether this is a bare repository
(type: `bool`)
def _check_bare(self):

Check whether this is a bare repository

def _get_git_dir(self):
Undocumented
_git_dir =
Undocumented
def _check_repo(self, path, toplevel):
Undocumented
def __init__(self, path, toplevel=(True)):
overridden in gbp.pkg.git.PkgGitRepository

Parameters | path | path to git repo (or subdir) (type: `str`)
| toplevel | whether path points to the toplevel dir of git repository (type: `bool`)

@staticmethod
def __build_env(extra_env):

Prepare environment for subprocess calls

def _git_getoutput(self, command, args=[], extra_env=None, cwd=None):

Run a git command and return the output

Parameters | command | git command to run (type: `str`)
| args | list of arguments (type: `list`)
| extra_env | extra environment variables to pass (type: `dict`)
| cwd | directory to switch to when running the command, defaults to self.path (type: `str`)
Returns | stdout, return code (type: `tuple` of `list` of `bytestr` and `int`)
Unknown Field: deprecated | use `gbp.git.repository.GitRepository._git_inout` instead.

def _git_inout(self, command, args, input=None, extra_env=None, cwd=None, capture_stderr=(False), config_args=None):

Run a git command with input and return output

Parameters | command | git command to run (type: `str`)
| input | input to pipe to command (type: `str`)
| args | list of arguments (type: `list`)
| extra_env | extra environment variables to pass (type: `dict`)
| cwd | directory to switch to when running the command, defaults to self.path (type: `str`)
| capture_stderr | whether to capture stderr (type: `bool`)
Returns | stdout, stderr, return code (type: `tuple` of `bytestr`, `bytestr`, `int`)

@classmethod
def git_inout(cls, command, args, input, extra_env, cwd, capture_stderr, config_args=None):

As _git_inout but can be used without an instance

def _git_command(self, command, args=[], extra_env=None):

Execute git command with arguments args and environment env at path.

Parameters | command | git command (type: `str`)
| args | command line arguments (type: `list`)
| extra_env | extra environment variables to set when running command (type: `dict`)

def _cmd_has_feature(self, command, feature):

Check if the git command has certain feature enabled.

Parameters | command | git command (type: `str`)
| feature | feature / command option to check (type: `str`)
Returns | True if feature is supported (type: `bool`)

@property
def path(self):

The absolute path to the repository

@property
def git_dir(self):

The absolute path to git's metadata

@property
def bare(self):

Whether this is a bare repository

@property
def tags(self):

List of all tags in the repository

@property
def branch(self):

The currently checked out branch

@property
def head(self):

SHA1 of the current HEAD

def rename_branch(self, branch, newbranch):

Rename branch

Parameters | branch | name of the branch to be renamed
| newbranch | new name of the branch

def create_branch(self, branch, rev=None, force=(False)):
overridden in gbp.deb.rollbackgit.RollbackDebianGitRepository

Create a new branch

Parameters | branch | the branch's name
| rev | where to start the branch from
| force | reset branch HEAD to start point, if it already exists If rev is None the branch starts from the current HEAD.

def delete_branch(self, branch, remote=(False)):

Delete branch branch

Parameters | branch | name of the branch to delete (type: `str`)
| remote | delete a remote branch
| remote | `bool`

def get_branch(self):

On what branch is the current working copy

Returns | current branch or `None` in an empty repo (type: `str`)
Raises | GitRepositoryError | if HEAD is not a symbolic ref (e.g. when in detached HEAD state)

def has_branch(self, branch, remote=(False)):

Check if the repository has branch named branch.

Parameters | branch | branch to look for
| remote | only look for remote branches (type: `bool`)
Returns | `True` if the repository has this branch, `False` otherwise (type: `bool`)

def set_branch(self, branch):

Switch to branch branch

Parameters | branch | name of the branch to switch to (type: `str`)

def get_merge_branch(self, branch):

Get the branch we'd merge from

Returns | repo and branch we would merge from (type: `str`)

def get_merge_base(self, commit1, commit2):

Get the common ancestor between two commits

Parameters | commit1 | commit SHA1 or name of a branch or tag (type: `str`)
| commit2 | commit SHA1 or name of a branch or tag (type: `str`)
Returns | SHA1 of the common ancestor (type: `str`)

def merge(self, commit, verbose=(False), edit=(False)):
overridden in gbp.deb.rollbackgit.RollbackDebianGitRepository

Merge changes from the named commit into the current branch

Parameters | commit | the commit to merge from (usually a branch name or tag) (type: `str`)
| verbose | whether to print a summary after the merge (type: `bool`)
| edit | whether to invoke an editor to edit the merge message (type: `bool`)

def abort_merge(self):

Abort a merge

def is_in_merge(self):
Undocumented
def is_fast_forward(self, from_branch, to_branch):

Check if an update from from_branch to to_branch would be a fast forward or if the branch is up to date already.

Returns | can_fast_forward, up_to_date (type: `tuple`)

def _get_branches(self, remote=(False)):

Get a list of branches

Parameters | remote | whether to list local or remote branches (type: `bool`)
Returns | local or remote branches (type: `list`)

def get_local_branches(self):

Get a list of local branches

Returns | local branches (type: `list`)

def get_remote_branches(self):

Get a list of remote branches

Returns | remote branches (type: `list`)

def update_ref(self, ref, new, old=None, msg=None):

Update ref ref to commit new if ref currently points to old

Parameters | ref | the ref to update (type: `str`)
| new | the new value for ref (type: `str`)
| old | the old value of ref (type: `str`)
| msg | the reason for the update (type: `str`)

def branch_contains(self, branch, commit, remote=(False)):

Check if branch branch contains commit commit

Parameters | branch | the branch the commit should be on (type: `str`)
| commit | the `str` commit to check (type: `str`)
| remote | whether to check remote instead of local branches (type: `bool`)

def set_upstream_branch(self, local_branch, upstream):

Set upstream branches for local branch

Parameters | local_branch | name of the local branch (type: `str`)
| upstream | Remote branch in the form remote/branch, e.g. origin/master (type: `str`)

def get_upstream_branch(self, local_branch):

Get upstream branch for the local branch

Parameters | local_branch | name fo the local branch (type: `str`)
Returns | upstream (remote/branch) or '' if no upstream found (type: `str`)

def create_tag(self, name, msg=None, commit=None, sign=(False), keyid=None):
overridden in gbp.deb.rollbackgit.RollbackDebianGitRepository

Create a new tag.

Parameters | name | the tag's name (type: `str`)
| msg | The tag message. (type: `str`)
| commit | the commit or object to create the tag at, default is HEAD (type: `str`)
| sign | Whether to sing the tag (type: `bool`)
| keyid | the GPG keyid used to sign the tag (type: `str`)

def delete_tag(self, tag):

Delete a tag named tag

Parameters | tag | the tag to delete (type: `str`)

def move_tag(self, old, new):
Undocumented
def has_tag(self, tag):

Check if the repository has a tag named tag.

Parameters | tag | tag to look for (type: `str`)
Returns | `True` if the repository has that tag, `False` otherwise (type: `bool`)

def describe(self, commitish, pattern=None, longfmt=(False), always=(False), abbrev=None, tags=(False), exact_match=(False)):

Describe commit, relative to the latest tag reachable from it.

Parameters | commitish | the commit-ish to describe (type: `str`)
| pattern | only look for tags matching pattern (type: `str`)
| longfmt | describe the commit in the long format (type: `bool`)
| always | return commit sha1 as fallback if no tag is found (type: `bool`)
| abbrev | abbreviate sha1 to given length instead of the default (type: None or `long`)
| tags | enable matching a lightweight (non-annotated) tag (type: `bool`)
| exact_match | only output exact matches (a tag directly references the supplied commit) (type: `bool`)
Returns | tag name plus/or the abbreviated sha1 (type: `str`)

def find_tag(self, commit, pattern=None):

Find the closest tag to a given commit

Parameters | commit | the commit to describe (type: `str`)
| pattern | only look for tags matching pattern (type: `str`)
Returns | the found tag (type: `str`)

def find_branch_tag(self, commit, branch, pattern=None):

Find the closest tag on a certain branch to a given commit

Parameters | commit | the commit to describe (type: `str`)
| pattern | only look for tags matching pattern (type: `str`)
Returns | the found tag (type: `str`)

def get_tags(self, pattern=None):

List tags

Parameters | pattern | only list tags matching pattern (type: `str`)
Returns | tags (type: `list` of `str`)

def verify_tag(self, tag):

Verify a signed tag

Parameters | tag | the tag's name (type: `str`)
Returns | Whether the signature on the tag could be verified (type: `bool`)

def force_head(self, commit, hard=(False)):

Force HEAD to a specific commit

Parameters | commit | commit to move HEAD to
| hard | also update the working copy (type: `bool`)

def _status(self, porcelain, ignore_untracked, paths):
Undocumented
def is_clean(self, ignore_untracked=(False), paths=None):

Does the repository contain any uncommitted modifications?

Parameters | ignore_untracked | whether to ignore untracked files when checking the repository status (type: `bool`)
| paths | only check changes on paths (type: `list` of `stings`)
Returns | `True` if the repository is clean, `False` otherwise and Git's status message (type: `tuple`)

def clean(self, directories=(False), force=(False), dry_run=(False)):

Remove untracked files from the working tree.

Parameters | directories | remove untracked directories, too (type: `bool`)
| force | satisfy git configuration variable clean.requireForce (type: `bool`)
| dry_run | don’t actually remove anything (type: `bool`)

def status(self, pathlist=None):

Check status of repository.

Parameters | pathlist | List of paths to check status for (type: `list` @return `dict` of `lists` of paths, where key is a git status flag. @rtype `dict`)

def is_empty(self):

Is the repository empty?

Returns | True if the repositorydoesn't have any commits, False otherwise (type: `bool`)

def rev_parse(self, name, short=0):

Find the SHA1 of a given name

Parameters | name | the name to look for (type: `str`)
| short | try to abbreviate SHA1 to given length (type: `int`)
Returns | the name's sha1 (type: `str`)

@staticmethod
def strip_sha1(sha1, length=0):

Strip a given sha1 and check if the resulting hash has the expected length.

    >>> GitRepository.strip_sha1('  58ef37dbeb12c44b206b92f746385a6f61253c0a\n')
    '58ef37dbeb12c44b206b92f746385a6f61253c0a'
    >>> GitRepository.strip_sha1('58ef37d', 10)
    Traceback (most recent call last):
    ...
    gbp.git.repository.GitRepositoryError: '58ef37d' is not a valid sha1 of length 10
    >>> GitRepository.strip_sha1('58ef37d', 7)
    '58ef37d'
    >>> GitRepository.strip_sha1('123456789', 7)
    '123456789'
    >>> GitRepository.strip_sha1('foobar')
    Traceback (most recent call last):
    ...
    gbp.git.repository.GitRepositoryError: 'foobar' is not a valid sha1

def checkout(self, treeish):

Checkout treeish

Parameters | treeish | the treeish to check out (type: `str`)

def has_treeish(self, treeish):

Check if the repository has the treeish object treeish.

Parameters | treeish | treeish object to look for (type: `str`)
Returns | `True` if the repository has that tree, `False` otherwise (type: `bool`)

def write_tree(self, index_file=None):

Create a tree object from the current index

Parameters | index_file | alternate index file to read changes from (type: `str`)
Returns | the new tree object's sha1 (type: `str`)

def make_tree(self, contents):

Create a tree based on contents.

Parameters | contents | same format as GitRepository.list_tree output. (type: `list` of `str`)

def get_obj_type(self, obj):

Get type of a git repository object

Parameters | obj | repository object (type: `str`)
Returns | type of the repository object (type: `str`)

def list_tree(self, treeish, recurse=(False), paths=None, sizes=(False)):

Get a trees content. It yields tuples that match the 'ls-tree' output: (mode, type, sha1, path). When sizes is True, includes object sizes: (mode, type, sha1, size, path)

Parameters | treeish | the treeish object to list (type: `str`)
| recurse | whether to list the tree recursively (type: `bool`)
| sizes | whether to include object sizes
Returns | the tree (type: `list` of objects. See above.)

def get_config(self, name):

Gets the config value associated with name

Parameters | name | config value to get
Returns | fetched config value (type: `str`)

def set_config(self, name, value):

Set a git config value in this repository

def set_user_name(self, name):

Sets the full name to use for git commits.

Parameters | name | full name to use

def set_user_email(self, email):

Sets the email address to use for git commits.

Parameters | email | email address to use

def get_author_info(self):

Determine a sane values for author name and author email from git's config and environment variables.

Returns | name and email (type: `GitModifier`)

def get_remotes(self):

Get a list of remote repositories

Returns | remote repositories (type: `dict` of `GitRemote`)

def get_remote_repos(self):

Get all remote repositories

Returns | remote repositories (type: `list` of `str`)
Unknown Field: deprecated | Use get_remotes() instead

def has_remote_repo(self, name):

Do we know about a remote named name?

Parameters | name | name of the remote repository (type: `str`)
Returns | `True` if the remote repositore is known, `False` otherwise (type: `bool`)

def add_remote_repo(self, name, url, tags=(True), fetch=(False)):

Add a tracked remote repository

Parameters | name | the name to use for the remote (type: `str`)
| url | the url to add (type: `str`)
| tags | whether to fetch tags (type: `bool`)
| fetch | whether to fetch immediately from the remote side (type: `bool`)

def remove_remote_repo(self, name):
Undocumented
def fetch(self, repo=None, tags=(False), depth=0, refspec=None, all_remotes=(False)):

Download objects and refs from another repository.

Parameters | repo | repository to fetch from (type: `str`)
| tags | whether to fetch all tag objects (type: `bool`)
| depth | deepen the history of (shallow) repository to depth depth (type: `int`)
| refspec | refspec to use instead of the default from git config (type: `str`)
| all_remotes | fetch all remotes (type: `bool`)

def pull(self, repo=None, ff_only=(False), all_remotes=(False)):

Fetch and merge from another repository

Parameters | repo | repository to fetch from (type: `str`)
| ff_only | only merge if this results in a fast forward merge (type: `bool`)
| all_remotes | fetch all remotes (type: `bool`)

def push(self, repo=None, src=None, dst=None, ff_only=(True), force=(False), tags=(False), dry_run=(False)):

Push changes to the remote repo

Parameters | repo | repository to push to (type: `str`)
| src | the source ref to push (type: `str`)
| dst | the name of the destination ref to push to (type: `str`)
| ff_only | only push if it's a fast forward update (type: `bool`)
| force | force push, can cause the remote repository to lose commits; use it with care (type: `bool`)
| tags | push all refs under refs/tags, in addition to other refs (type: `bool`)
| dry_run | dry run (type: `bool`)

def push_tag(self, repo, tag, dry_run=(False)):

Push a tag to the remote repo

Parameters | repo | repository to push to (type: `str`)
| tag | the name of the tag (type: `str`)
| dry_run | dry run (type: `bool`)

def add_files(self, paths, force=(False), index_file=None, work_tree=None):

Add files to a the repository

Parameters | paths | list of files to add (type: list or `str`)
| force | add files even if they would be ignored by .gitignore (type: `bool`)
| index_file | alternative index file to use
| work_tree | alternative working tree to use

def remove_files(self, paths, verbose=(False)):

Remove files from the repository

Parameters | paths | list of files to remove
| paths | `list` or `str`
| verbose | be verbose (type: `bool`)

def list_files(self, types=['cached']):

List files in index and working tree

Parameters | types | list of types to show (type: `list`)
Returns | list of files as byte string (type: `list` of `str`)

def write_file(self, filename, filters=(True)):

Hash a single file and write it into the object database

Parameters | filename | the filename to the content of the file to hash (type: `bytestr`)
| filters | whether to run filters (type: `bool`)
Returns | the hash of the file (type: `str`)

def rename_file(self, old, new):

Rename file, directory, or symlink

def _commit(self, msg, args=[], author_info=None):
Undocumented
def commit_staged(self, msg, author_info=None, edit=(False)):

Commit currently staged files to the repository

Parameters | msg | commit message (type: `str`)
| author_info | authorship information (type: `GitModifier`)
| edit | whether to spawn an editor to edit the commit info (type: `bool`)

def commit_all(self, msg, author_info=None, edit=(False)):

Commit all changes to the repository

Parameters | msg | commit message (type: `str`)
| author_info | authorship information (type: `GitModifier`)

def commit_files(self, files, msg, author_info=None):

Commit the given files to the repository

Parameters | files | file or files to commit (type: `str` or `list`)
| msg | commit message (type: `str`)
| author_info | authorship information (type: `GitModifier`)

def commit_dir(self, unpack_dir, msg, branch, other_parents=None, author={}, committer={}, create_missing_branch=(False)):
overridden in gbp.deb.rollbackgit.RollbackDebianGitRepository

Replace the current tip of branch branch with the contents from unpack_dir

Parameters | unpack_dir | content to add (type: `str`)
| msg | commit message to use (type: `str`)
| branch | branch to add the contents of unpack_dir to (type: `str`)
| other_parents | additional parents of this commit (type: `list` of `str`)
| author | author information to use for commit (type: `dict` with keys name, email, date)
| committer | committer information to use for commit (type: `dict` with keys name, email, date or `GitModifier`)
| create_missing_branch | create branch as detached branch if it doesn't already exist. (type: `bool`)

def commit_tree(self, tree, msg, parents, author={}, committer={}):

Commit a tree with commit msg msg and parents parents

Parameters | tree | tree to commit
| msg | commit message
| parents | parents of this commit
| author | authorship information (type: `dict` with keys 'name' and 'email' or `GitModifier`)
| committer | committer information (type: `dict` with keys 'name' and 'email')

def get_commits(self, since=None, until=None, paths=None, num=0, first_parent=(False), options=None):

Get commits from since to until touching paths

Parameters | since | commit to start from (type: `str`)
| until | last commit to get (type: `str`)
| paths | only list commits touching paths (type: `list` of `str`)
| num | maximum number of commits to fetch (type: `int`)
| options | list of additional options passed to git log (type: `list` of `str`ings)
| first_parent | only follow first parent when seeing a merge commit (type: `bool`)

def show(self, id):

Show a git object

Returns | (type: `bytestr`)

def grep_log(self, regex, since=None, merges=(True)):

Get commmits matching regex

Parameters | regex | regular expression (type: `str`)
| since | where to start grepping (e.g. a branch) (type: `str`)

def get_subject(self, commit):

Gets the subject of a commit.

Parameters | commit | the commit to get the subject from
Returns | the commit's subject (type: `str`)
Unknown Field: deprecated | Use get_commit_info directly

def get_commit_info(self, commitish):

Look up data of a specific commit-ish. Dereferences given commit-ish to the commit it points to.

Parameters | commitish | the commit-ish to inspect
Returns | the commit's including id, author, email, subject and body (type: dict)

def format_patches(self, start, end, output_dir, signature=(True), thread=None, symmetric=(True)):

Output the commits between start and end as patches in output_dir.

This outputs the revisions start...end by default. When using symmetric to `false` it uses start..end instead.

Parameters | start | the commit on the left side of the revision range
| end | the commit on the right hand side of the revisino range
| output_dir | directory to write the patches to
| signature | whether to output a signature
| thread | whether to include In-Reply-To references
| symmetric | whether to use the symmetric difference (see above)

def apply_patch(self, patch, index=(True), context=None, strip=None, fix_ws=(False)):

Apply a patch using git apply

def diff(self, obj1, obj2=None, paths=None, stat=(False), summary=(False), text=(False), ignore_submodules=(True), abbrev=None, renames=(False)):

Diff two git repository objects

Parameters | obj1 | first object (type: `str`)
| obj2 | second object (type: `str`)
| paths | List of paths to diff (type: `list`)
| stat | Show diffstat (type: `bool` or `int` or `str`)
| summary | Show diffstat (type: `bool`)
| text | Generate textual diffs, treat all files as text (type: `bool`)
| ignore_submodules | ignore changes to submodules (type: `bool`)
Returns | diff (type: `binary`)

def diff_status(self, obj1, obj2):

Get file-status of two git repository objects

Parameters | obj1 | first object (type: `str`)
| obj2 | second object (type: `str`)
Returns | name-status (type: `defaultdict` of `str`)

def archive(self, format, prefix, output, treeish, cwd=None):

Create an archive from a treeish

Parameters | format | the type of archive to create, e.g. 'tar.gz' (type: `str`)
| prefix | prefix to prepend to each filename in the archive (type: `str`)
| output | the name of the archive to create (type: `str`)
| treeish | the treeish to create the archive from (type: `str`)
| cwd | The directory to run in. Defaults to the current dir (type: `str`)

def collect_garbage(self, auto=(False), prune=(False), aggressive=(False)):

Cleanup unnecessary files and optimize the local repository

param auto: only cleanup if required param auto: `bool`

def has_submodules(self, treeish=None):

Does the repo have any submodules?

Parameters | treeish | look into treeish (type: `str`)
Returns | `True` if the repository has any submodules, `False` otherwise (type: `bool`)

def add_submodule(self, repo_path):

Add a submodule

Parameters | repo_path | path to submodule (type: `str`)

def update_submodules(self, init=(True), recursive=(True), fetch=(False)):

Update all submodules

Parameters | init | whether to initialize the submodule if necessary (type: `bool`)
| recursive | whether to update submodules recursively (type: `bool`)
| fetch | whether to fetch new objects (type: `bool`)

def get_submodules(self, treeish, path=None, recursive=(True)):

List the submodules of treeish

Returns | a list of submodule/commit-id tuples (type: list of tuples)

@classmethod
def create(cls, path, description=None, bare=(False)):

Create a repository at path

Parameters | path | where to create the repository (type: `str`)
| bare | whether to create a bare repository (type: `bool`)
Returns | git repository object (type: `GitRepository`)

@classmethod
def clone(cls, path, remote, depth=0, recursive=(False), mirror=(False), bare=(False), auto_name=(True), reference=None):

Clone a git repository at remote to path.

Parameters | path | where to clone the repository to (type: `str`)
| remote | URL to clone (type: `str`)
| depth | create a shallow clone of depth depth (type: `int`)
| recursive | whether to clone submodules (type: `bool`)
| mirror | whether to pass --mirror to git-clone (type: `bool`)
| bare | whether to create a bare repository (type: `bool`)
| auto_name | If True create a directory below path based on the remotes name. Otherwise create the repo directly at path. (type: `bool`)
| reference | create a clone using local objects from reference repository (type: `str`)
Returns | git repository object (type: `GitRepository`)