gbp.git.repository.GitRepository(object)
class documentationgbp.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 returns a list of objects that match the 'ls-tree' output: [mode, type, sha1, 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 |
Parameters | path | path to git repo (or subdir) (type: str ) |
toplevel | whether path points to the toplevel dir of git repository (type: bool ) |
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. |
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 ) |
As _git_inout but can be used without an instance
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 ) |
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 ) |
Rename branch
Parameters | branch | name of the branch to be renamed |
newbranch | new name of the branch |
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. |
Delete branch branch
Parameters | branch | name of the branch to delete (type: str ) |
remote | delete a remote branch | |
remote | bool |
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) |
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 ) |
Switch to branch branch
Parameters | branch | name of the branch to switch to (type: str ) |
Get the branch we'd merge from
Returns | repo and branch we would merge from (type: str ) |
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 ) |
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 ) |
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 ) |
Get a list of branches
Parameters | remote | whether to list local or remote branches (type: bool ) |
Returns | local or remote branches (type: list ) |
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 ) |
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 ) |
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 ) |
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 ) |
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 ) |
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 ) |
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 ) |
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 ) |
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 ) |
List tags
Parameters | pattern | only list tags matching pattern (type: str ) |
Returns | tags (type: list of str ) |
Verify a signed tag
Parameters | tag | the tag's name (type: str ) |
Returns | Whether the signature on the tag could be verified (type: bool ) |
Force HEAD to a specific commit
Parameters | commit | commit to move HEAD to |
hard | also update the working copy (type: bool ) |
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 ) |
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 ) |
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 ) |
Is the repository empty?
Returns | True if the repositorydoesn't have any commits, False otherwise (type: bool ) |
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 ) |
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
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 ) |
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 ) |
Create a tree based on contents.
Parameters | contents | same format as GitRepository.list_tree output. (type: list of str ) |
Get type of a git repository object
Parameters | obj | repository object (type: str ) |
Returns | type of the repository object (type: str ) |
Get a trees content. It returns a list of objects that match the 'ls-tree' output: [mode, type, sha1, path].
Parameters | treeish | the treeish object to list (type: str ) |
recurse | whether to list the tree recursively (type: bool ) | |
Returns | the tree (type: list of objects. See above.) |
Gets the config value associated with name
Parameters | name | config value to get |
Returns | fetched config value (type: str ) |
Sets the full name to use for git commits.
Parameters | name | full name to use |
Sets the email address to use for git commits.
Parameters | email address to use |
Determine a sane values for author name and author email from git's config and environment variables.
Returns | name and email (type: GitModifier ) |
Get a list of remote repositories
Returns | remote repositories (type: dict of GitRemote ) |
Get all remote repositories
Returns | remote repositories (type: list of str ) | |
Unknown Field: deprecated | Use get_remotes() instead |
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 ) |
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 ) |
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 ) |
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 ) |
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 ) |
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 ) |
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 |
Remove files from the repository
Parameters | paths | list of files to remove |
paths | list or str | |
verbose | be verbose (type: bool ) |
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 ) |
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 ) |
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 ) |
Commit all changes to the repository
Parameters | msg | commit message (type: str ) |
author_info | authorship information (type: GitModifier ) |
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 ) |
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 ) |
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') |
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 ) |
Get commmits matching regex
Parameters | regex | regular expression (type: str ) |
since | where to start grepping (e.g. a branch) (type: str ) |
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 |
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) |
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) |
Apply a patch using git apply
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 ) |
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 ) |
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 ) |
Cleanup unnecessary files and optimize the local repository
param auto: only cleanup if required param auto: bool
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 ) |
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 ) |
List the submodules of treeish
Returns | a list of submodule/commit-id tuples (type: list of tuples) |
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 ) |
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 ) |