class GitRepository(object):
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. |
| Class Method | clone |
Clone a git repository at remote to path. |
| Class Method | create |
Create a repository at path |
| Class Method | git |
As _git_inout but can be used without an instance |
| Static Method | ensure |
Make sure a branch name is prefixed with `refs/heads' |
| Static Method | strip |
Strip a given sha1 and check if the resulting hash has the expected length. |
| Method | __init__ |
No summary |
| Method | abort |
Abort a merge |
| Method | add |
Add files to a the repository |
| Method | add |
Add a tracked remote repository |
| Method | add |
Add a submodule |
| Method | apply |
Apply a patch using git apply |
| Method | archive |
Create an archive from a treeish |
| Method | branch |
Check if branch branch contains commit commit |
| Method | checkout |
Checkout treeish |
| Method | clean |
Remove untracked files from the working tree. |
| Method | collect |
Cleanup unnecessary files and optimize the local repository |
| Method | commit |
Commit all changes to the repository |
| Method | commit |
Replace the current tip of branch branch with the contents from unpack_dir |
| Method | commit |
Commit the given files to the repository |
| Method | commit |
Commit currently staged files to the repository |
| Method | commit |
Commit a tree with commit msg msg and parents parents |
| Method | create |
Create a new branch |
| Method | create |
Create a new tag. |
| Method | delete |
Delete branch branch |
| Method | delete |
Delete a tag named tag |
| Method | describe |
Describe commit, relative to the latest tag reachable from it. |
| Method | diff |
Diff two git repository objects |
| Method | diff |
Get file-status of two git repository objects |
| Method | fetch |
Download objects and refs from another repository. |
| Method | find |
Find the closest tag on a certain branch to a given commit |
| Method | find |
Find the closest tag to a given commit |
| Method | force |
Force HEAD to a specific commit |
| Method | format |
Output the commits between start and end as patches in output_dir. |
| Method | get |
Determine a sane values for author name and author email from git's config and environment variables. |
| Method | get |
On what branch is the current working copy |
| Method | get |
Look up data of a specific commit-ish. Dereferences given commit-ish to the commit it points to. |
| Method | get |
Get commits from since to until touching paths |
| Method | get |
Gets the config value associated with name |
| Method | get |
Get a list of local branches |
| Method | get |
Get the common ancestor between two commits |
| Method | get |
Get the branch we'd merge from |
| Method | get |
Get type of a git repository object |
| Method | get |
Get a list of remote branches |
| Method | get |
Get all remote repositories |
| Method | get |
Get a list of remote repositories |
| Method | get |
Gets the subject of a commit. |
| Method | get |
List the submodules of treeish |
| Method | get |
List tags |
| Method | get |
Get upstream branch for the local branch |
| Method | grep |
Get commmits matching regex |
| Method | has |
Check if the repository has branch named branch. |
| Method | has |
Do we know about a remote named name? |
| Method | has |
Does the repo have any submodules? |
| Method | has |
Check if the repository has a tag named tag. |
| Method | has |
Check if the repository has the treeish object treeish. |
| Method | is |
Does the repository contain any uncommitted modifications? |
| Method | is |
Is the repository empty? |
| Method | is |
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 | is |
Undocumented |
| Method | list |
List files in index and working tree |
| Method | list |
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 | make |
Create a tree based on contents. |
| Method | merge |
Merge changes from the named commit into the current branch |
| Method | move |
Undocumented |
| Method | pull |
Fetch and merge from another repository |
| Method | push |
Push changes to the remote repo |
| Method | push |
Push a tag to the remote repo |
| Method | remove |
Remove files from the repository |
| Method | remove |
Undocumented |
| Method | rename |
Rename branch |
| Method | rename |
Rename file, directory, or symlink |
| Method | rev |
Find the SHA1 of a given name |
| Method | set |
Switch to branch branch |
| Method | set |
Set a git config value in this repository |
| Method | set |
Set upstream branches for local branch |
| Method | set |
Sets the email address to use for git commits. |
| Method | set |
Sets the full name to use for git commits. |
| Method | show |
Show a git object |
| Method | status |
Check status of repository. |
| Method | update |
Update ref ref to commit new if ref currently points to old |
| Method | update |
Update all submodules |
| Method | verify |
Verify a signed tag |
| Method | write |
Hash a single file and write it into the object database |
| Method | write |
Create a tree object from the current index |
| Property | bare |
Whether this is a bare repository |
| Property | branch |
The currently checked out branch |
| Property | git |
The absolute path to git's metadata |
| Property | head |
SHA1 of the current HEAD |
| Property | path |
The absolute path to the repository |
| Property | tags |
List of all tags in the repository |
| Static Method | __build |
Prepare environment for subprocess calls |
| Method | _check |
Check whether this is a bare repository |
| Method | _check |
Undocumented |
| Method | _cmd |
Check if the git command has certain feature enabled. |
| Method | _commit |
Undocumented |
| Method | _get |
Get a list of branches |
| Method | _get |
Undocumented |
| Method | _git |
Execute git command with arguments args and environment env at path. |
| Method | _git |
Run a git command and return the output |
| Method | _git |
Run a git command with input and return output |
| Method | _status |
Undocumented |
| Instance Variable | _bare |
Whether this is a bare repository |
| Instance Variable | _git |
Undocumented |
| Instance Variable | _path |
The path to the working tree |
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:str | where to clone the repository to |
| remote:str | URL to clone |
| depth:int | create a shallow clone of depth depth |
| recursive:bool | whether to clone submodules |
| mirror:bool | whether to pass --mirror to git-clone |
| bare:bool | whether to create a bare repository |
| auto | If True create a directory below path based on the remotes name. Otherwise create the repo directly at path. |
| reference:str | create a clone using local objects from reference repository |
| Returns | |
GitRepository | git repository object |
Create a repository at path
| Parameters | |
| path:str | where to create the repository |
| description | Undocumented |
| bare:bool | whether to create a bare repository |
| Returns | |
GitRepository | git repository object |
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
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
| Parameters | |
| path:str | path to git repo (or subdir) |
| toplevel:bool | whether path points to the toplevel dir of git repository |
Add files to a the repository
| Parameters | |
| paths:list or str | list of files to add |
| force:bool | add files even if they would be ignored by .gitignore |
| index | alternative index file to use |
| work | alternative working tree to use |
Add a tracked remote repository
| Parameters | |
| name:str | the name to use for the remote |
| url:str | the url to add |
| tags:bool | whether to fetch tags |
| fetch:bool | whether to fetch immediately from the remote side |
Create an archive from a treeish
| Parameters | |
| format:str | the type of archive to create, e.g. 'tar.gz' |
| prefix:str | prefix to prepend to each filename in the archive |
| output:str | the name of the archive to create |
| treeish:str | the treeish to create the archive from |
| cwd:str | The directory to run in. Defaults to the current dir |
Check if branch branch contains commit commit
| Parameters | |
| branch:str | the branch the commit should be on |
| commit:str | the str commit to check |
| remote:bool | whether to check remote instead of local branches |
Remove untracked files from the working tree.
| Parameters | |
| directories:bool | remove untracked directories, too |
| force:bool | satisfy git configuration variable clean.requireForce |
| dry | don’t actually remove anything |
Cleanup unnecessary files and optimize the local repository
param auto: only cleanup if required param auto: bool
Commit all changes to the repository
| Parameters | |
| msg:str | commit message |
authorGitModifier | authorship information |
| edit | Undocumented |
Replace the current tip of branch branch with the contents from unpack_dir
| Parameters | |
| unpack | content to add |
| msg:str | commit message to use |
| branch:str | branch to add the contents of unpack_dir to |
| other | additional parents of this commit |
| author:dict with keys name, email, date | author information to use for commit |
committer:dict with keys name, email, date or GitModifier | committer information to use for commit |
| create | create branch as detached branch if it doesn't already exist. |
Commit the given files to the repository
| Parameters | |
| files:str or list | file or files to commit |
| msg:str | commit message |
authorGitModifier | authorship information |
Commit currently staged files to the repository
| Parameters | |
| msg:str | commit message |
authorGitModifier | authorship information |
| edit:bool | whether to spawn an editor to edit the commit info |
Commit a tree with commit msg msg and parents parents
| Parameters | |
| tree | tree to commit |
| msg | commit message |
| parents | parents of this commit |
author:dict with keys 'name' and 'email' or GitModifier | authorship information |
| committer:dict with keys 'name' and 'email' | committer information |
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. |
Create a new tag.
| Parameters | |
| name:str | the tag's name |
| msg:str | The tag message. |
| commit:str | the commit or object to create the tag at, default is HEAD |
| sign:bool | Whether to sing the tag |
| keyid:str | the GPG keyid used to sign the tag |
Describe commit, relative to the latest tag reachable from it.
| Parameters | |
| commitish:str | the commit-ish to describe |
| pattern:str | only look for tags matching pattern |
| longfmt:bool | describe the commit in the long format |
| always:bool | return commit sha1 as fallback if no tag is found |
| abbrev:None or long | abbreviate sha1 to given length instead of the default |
| tags:bool | enable matching a lightweight (non-annotated) tag |
| exact | only output exact matches (a tag directly references the supplied commit) |
| Returns | |
| str | tag name plus/or the abbreviated sha1 |
Diff two git repository objects
| Parameters | |
| obj1:str | first object |
| obj2:str | second object |
| paths:list | List of paths to diff |
| stat:bool or int or str | Show diffstat |
| summary:bool | Show diffstat |
| text:bool | Generate textual diffs, treat all files as text |
| ignore | ignore changes to submodules |
| abbrev | Undocumented |
| renames | Undocumented |
| Returns | |
| binary | diff |
Get file-status of two git repository objects
| Parameters | |
| obj1:str | first object |
| obj2:str | second object |
| Returns | |
| defaultdict of str | name-status |
Download objects and refs from another repository.
| Parameters | |
| repo:str | repository to fetch from |
| tags:bool | whether to fetch all tag objects |
| depth:int | deepen the history of (shallow) repository to depth depth |
| refspec:str | refspec to use instead of the default from git config |
| all | fetch all remotes |
Find the closest tag on a certain branch to a given commit
| Parameters | |
| commit:str | the commit to describe |
| branch:str | Undocumented |
| pattern:str | only look for tags matching pattern |
| Returns | |
| str | the found tag |
Find the closest tag to a given commit
| Parameters | |
| commit:str | the commit to describe |
| pattern:str | only look for tags matching pattern |
| Returns | |
| str | the found tag |
Force HEAD to a specific commit
| Parameters | |
| commit | commit to move HEAD to |
| hard:bool | also update the working copy |
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 | 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) |
Determine a sane values for author name and author email from git's config and environment variables.
| Returns | |
GitModifier | name and email |
On what branch is the current working copy
| Returns | |
| str | current branch or None in an empty repo |
| Raises | |
GitRepositoryError | if HEAD is not a symbolic ref (e.g. when in detached HEAD state) |
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 | |
| dict | the commit's including id, author, email, subject and body |
Get commits from since to until touching paths
| Parameters | |
| since:str | commit to start from |
| until:str | last commit to get |
| paths:list of str | only list commits touching paths |
| num:int | maximum number of commits to fetch |
| first | only follow first parent when seeing a merge commit |
| options:list of strings | list of additional options passed to git log |
Gets the config value associated with name
| Parameters | |
| name | config value to get |
| Returns | |
| str | fetched config value |
Get the common ancestor between two commits
| Parameters | |
| commit1:str | commit SHA1 or name of a branch or tag |
| commit2:str | commit SHA1 or name of a branch or tag |
| Returns | |
| str | SHA1 of the common ancestor |
Get type of a git repository object
| Parameters | |
| obj:str | repository object |
| Returns | |
| str | type of the repository object |
Get all remote repositories
| Returns | |
| list of str | remote repositories |
| Unknown Field: deprecated | |
| Use get_remotes() instead | |
Gets the subject of a commit.
| Parameters | |
| commit | the commit to get the subject from |
| Returns | |
| str | the commit's subject |
| Unknown Field: deprecated | |
| Use get_commit_info directly | |
Get upstream branch for the local branch
| Parameters | |
| local | name fo the local branch |
| Returns | |
| str | upstream (remote/branch) or '' if no upstream found |
Get commmits matching regex
| Parameters | |
| regex:str | regular expression |
| since:str | where to start grepping (e.g. a branch) |
| merges | Undocumented |
Check if the repository has branch named branch.
| Parameters | |
| branch | branch to look for |
| remote:bool | only look for remote branches |
| Returns | |
| bool | True if the repository has this branch, False otherwise |
Do we know about a remote named name?
| Parameters | |
| name:str | name of the remote repository |
| Returns | |
| bool | True if the remote repositore is known, False otherwise |
Does the repo have any submodules?
| Parameters | |
| treeish:str | look into treeish |
| Returns | |
| bool | True if the repository has any submodules, False otherwise |
Check if the repository has a tag named tag.
| Parameters | |
| tag:str | tag to look for |
| Returns | |
| bool | True if the repository has that tag, False otherwise |
Check if the repository has the treeish object treeish.
| Parameters | |
| treeish:str | treeish object to look for |
| Returns | |
| bool | True if the repository has that tree, False otherwise |
Does the repository contain any uncommitted modifications?
| Parameters | |
| ignore | whether to ignore untracked files when checking the repository status |
| paths:list of stings | only check changes on paths |
| Returns | |
| tuple | True if the repository is clean, False otherwise and Git's status message |
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 | |
| tuple | can_fast_forward, up_to_date |
List files in index and working tree
| Parameters | |
| types:list | list of types to show |
| Returns | |
| list of str | list of files as byte string |
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:str | the treeish object to list |
| recurse:bool | whether to list the tree recursively |
| paths | Undocumented |
| sizes | whether to include object sizes |
| Returns | |
| list of objects. See above. | the tree |
Create a tree based on contents.
| Parameters | |
| contents:list of str | same format as GitRepository.list_tree output. |
Merge changes from the named commit into the current branch
| Parameters | |
| commit:str | the commit to merge from (usually a branch name or tag) |
| verbose:bool | whether to print a summary after the merge |
| edit:bool | whether to invoke an editor to edit the merge message |
Fetch and merge from another repository
| Parameters | |
| repo:str | repository to fetch from |
| ff | only merge if this results in a fast forward merge |
| all | fetch all remotes |
Push changes to the remote repo
| Parameters | |
| repo:str | repository to push to |
| src:str | the source ref to push |
| dst:str | the name of the destination ref to push to |
| ff | only push if it's a fast forward update |
| force:bool | force push, can cause the remote repository to lose commits; use it with care |
| tags:bool | push all refs under refs/tags, in addition to other refs |
| dry | dry run |
Push a tag to the remote repo
| Parameters | |
| repo:str | repository to push to |
| tag:str | the name of the tag |
| dry | dry run |
Find the SHA1 of a given name
| Parameters | |
| name:str | the name to look for |
| short:int | try to abbreviate SHA1 to given length |
| Returns | |
| str | the name's sha1 |
Set upstream branches for local branch
| Parameters | |
| local | name of the local branch |
| upstream:str | Remote branch in the form remote/branch, e.g. origin/master |
Check status of repository.
| Parameters | |
| pathlist:list @return dict of lists of paths, where key is a git status flag. @rtype dict | List of paths to check status for |
Update ref ref to commit new if ref currently points to old
| Parameters | |
| ref:str | the ref to update |
| new:str | the new value for ref |
| old:str | the old value of ref |
| msg:str | the reason for the update |
Update all submodules
| Parameters | |
| init:bool | whether to initialize the submodule if necessary |
| recursive:bool | whether to update submodules recursively |
| fetch:bool | whether to fetch new objects |
Verify a signed tag
| Parameters | |
| tag:str | the tag's name |
| Returns | |
| bool | Whether the signature on the tag could be verified |
Hash a single file and write it into the object database
| Parameters | |
| filename:bytestr | the filename to the content of the file to hash |
| filters:bool | whether to run filters |
| Returns | |
| str | the hash of the file |
Create a tree object from the current index
| Parameters | |
| index | alternate index file to read changes from |
| Returns | |
| str | the new tree object's sha1 |
Check if the git command has certain feature enabled.
| Parameters | |
| command:str | git command |
| feature:str | feature / command option to check |
| Returns | |
| bool | True if feature is supported |
Get a list of branches
| Parameters | |
| remote:bool | whether to list local or remote branches |
| Returns | |
| list | local or remote branches |
Execute git command with arguments args and environment env at path.
| Parameters | |
| command:str | git command |
| args:list | command line arguments |
| extra | extra environment variables to set when running command |
Run a git command and return the output
| Parameters | |
| command:str | git command to run |
| args:list | list of arguments |
| extra | extra environment variables to pass |
| cwd:str | directory to switch to when running the command, defaults to self.path |
| Returns | |
| tuple of list of bytestr and int | stdout, return code |
| Unknown Field: deprecated | |
use gbp.git.repository.GitRepository._git_inout instead. | |
Run a git command with input and return output
| Parameters | |
| command:str | git command to run |
| args:list | list of arguments |
| input:str | input to pipe to command |
| extra | extra environment variables to pass |
| cwd:str | directory to switch to when running the command, defaults to self.path |
| capture | whether to capture stderr |
| config | Undocumented |
| Returns | |
| tuple of bytestr, bytestr, int | stdout, stderr, return code |