gbp.git.repository.GitRepository(object) class documentationgbp.git.repository
(View In Hierarchy)
Known subclasses: gbp.pkg.git.PkgGitRepository
Represents a git repository at I{path}. It's currently assumed that the git
repository is stored in a directory named I{.git/} below I{path}.
@ivar _path: The path to the working tree
@type _path: C{str}
@ivar _bare: Whether this is a bare repository
@type _bare: C{bool}
@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 I{branch} |
| Method | get_branch | On what branch is the current working copy |
| Method | has_branch | Check if the repository has branch named I{branch}. |
| Method | set_branch | Switch to branch I{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 I{from from_branch} to I{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 I{ref} to commit I{new} if I{ref} currently points to I{old} |
| Method | branch_contains | Check if branch I{branch} contains commit I{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 I{tag} |
| Method | move_tag | Undocumented |
| Method | has_tag | Check if the repository has a tag named I{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 I{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 I{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 I{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 I{branch} with the contents from I{unpack_dir} |
| Method | commit_tree | Commit a tree with commit msg I{msg} and parents I{parents} |
| Method | get_commits | Get commits from since to until touching paths |
| Method | show | Show a git object |
| Method | grep_log | Get commmits matching I{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 I{remote} to I{path}. |
| Method | _check_bare | Check whether this is a bare repository |
| Method | _get_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 |
@param path: path to git repo (or subdir)
@type path: C{str}
@param toplevel: whether path points to the toplevel dir of
git repository
@type toplevel: C{bool}
Run a git command and return the output
@param command: git command to run
@type command: C{str}
@param args: list of arguments
@type args: C{list}
@param extra_env: extra environment variables to pass
@type extra_env: C{dict}
@param cwd: directory to switch to when running the command, defaults to I{self.path}
@type cwd: C{str}
@return: stdout, return code
@rtype: C{tuple} of C{list} of C{bytestr} and C{int}
@deprecated: use L{gbp.git.repository.GitRepository._git_inout} instead.
Run a git command with input and return output
@param command: git command to run
@type command: C{str}
@param input: input to pipe to command
@type input: C{str}
@param args: list of arguments
@type args: C{list}
@param extra_env: extra environment variables to pass
@type extra_env: C{dict}
@param cwd: directory to switch to when running the command, defaults to I{self.path}
@type cwd: C{str}
@param capture_stderr: whether to capture stderr
@type capture_stderr: C{bool}
@return: stdout, stderr, return code
@rtype: C{tuple} of C{bytestr}, C{bytestr}, C{int}
As _git_inout but can be used without an instance
Execute git command with arguments args and environment env
at path.
@param command: git command
@type command: C{str}
@param args: command line arguments
@type args: C{list}
@param extra_env: extra environment variables to set when running command
@type extra_env: C{dict}
Check if the git command has certain feature enabled.
@param command: git command
@type command: C{str}
@param feature: feature / command option to check
@type feature: C{str}
@return: True if feature is supported
@rtype: C{bool}
Rename branch @param branch: name of the branch to be renamed @param newbranch: new name of the branch
Create a new branch @param branch: the branch's name @param rev: where to start the branch from @param force: reset branch HEAD to start point, if it already exists If rev is None the branch starts from the current HEAD.
Delete branch I{branch}
@param branch: name of the branch to delete
@type branch: C{str}
@param remote: delete a remote branch
@param remote: C{bool}
On what branch is the current working copy
@return: current branch or C{None} in an empty repo
@rtype: C{str}
@raises GitRepositoryError: if HEAD is not a symbolic ref
(e.g. when in detached HEAD state)
Check if the repository has branch named I{branch}.
@param branch: branch to look for
@param remote: only look for remote branches
@type remote: C{bool}
@return: C{True} if the repository has this branch, C{False} otherwise
@rtype: C{bool}
Switch to branch I{branch}
@param branch: name of the branch to switch to
@type branch: C{str}
Get the branch we'd merge from
@return: repo and branch we would merge from
@rtype: C{str}
Get the common ancestor between two commits
@param commit1: commit SHA1 or name of a branch or tag
@type commit1: C{str}
@param commit2: commit SHA1 or name of a branch or tag
@type commit2: C{str}
@return: SHA1 of the common ancestor
@rtype: C{str}
Merge changes from the named commit into the current branch
@param commit: the commit to merge from (usually a branch name or tag)
@type commit: C{str}
@param verbose: whether to print a summary after the merge
@type verbose: C{bool}
@param edit: whether to invoke an editor to edit the merge message
@type edit: C{bool}
Check if an update I{from from_branch} to I{to_branch} would be a fast
forward or if the branch is up to date already.
@return: can_fast_forward, up_to_date
@rtype: C{tuple}
Get a list of branches
@param remote: whether to list local or remote branches
@type remote: C{bool}
@return: local or remote branches
@rtype: C{list}
Get a list of remote branches
@return: remote branches
@rtype: C{list}
Update ref I{ref} to commit I{new} if I{ref} currently points to
I{old}
@param ref: the ref to update
@type ref: C{str}
@param new: the new value for ref
@type new: C{str}
@param old: the old value of ref
@type old: C{str}
@param msg: the reason for the update
@type msg: C{str}
Check if branch I{branch} contains commit I{commit}
@param branch: the branch the commit should be on
@type branch: C{str}
@param commit: the C{str} commit to check
@type commit: C{str}
@param remote: whether to check remote instead of local branches
@type remote: C{bool}
Set upstream branches for local branch
@param local_branch: name of the local branch
@type local_branch: C{str}
@param upstream: Remote branch in the form remote/branch, e.g. origin/master
@type upstream: C{str}
Get upstream branch for the local branch
@param local_branch: name fo the local branch
@type local_branch: C{str}
@return: upstream (remote/branch) or '' if no upstream found
@rtype: C{str}
Create a new tag.
@param name: the tag's name
@type name: C{str}
@param msg: The tag message.
@type msg: C{str}
@param commit: the commit or object to create the tag at, default
is I{HEAD}
@type commit: C{str}
@param sign: Whether to sing the tag
@type sign: C{bool}
@param keyid: the GPG keyid used to sign the tag
@type keyid: C{str}
Delete a tag named I{tag}
@param tag: the tag to delete
@type tag: C{str}
Check if the repository has a tag named I{tag}.
@param tag: tag to look for
@type tag: C{str}
@return: C{True} if the repository has that tag, C{False} otherwise
@rtype: C{bool}
Describe commit, relative to the latest tag reachable from it.
@param commitish: the commit-ish to describe
@type commitish: C{str}
@param pattern: only look for tags matching I{pattern}
@type pattern: C{str}
@param longfmt: describe the commit in the long format
@type longfmt: C{bool}
@param always: return commit sha1 as fallback if no tag is found
@type always: C{bool}
@param abbrev: abbreviate sha1 to given length instead of the default
@type abbrev: None or C{long}
@param tags: enable matching a lightweight (non-annotated) tag
@type tags: C{bool}
@param exact_match: only output exact matches (a tag directly
references the supplied commit)
@type exact_match: C{bool}
@return: tag name plus/or the abbreviated sha1
@rtype: C{str}
Find the closest tag to a given commit
@param commit: the commit to describe
@type commit: C{str}
@param pattern: only look for tags matching I{pattern}
@type pattern: C{str}
@return: the found tag
@rtype: C{str}
Find the closest tag on a certain branch to a given commit
@param commit: the commit to describe
@type commit: C{str}
@type branch: C{str}
@param pattern: only look for tags matching I{pattern}
@type pattern: C{str}
@return: the found tag
@rtype: C{str}
List tags
@param pattern: only list tags matching I{pattern}
@type pattern: C{str}
@return: tags
@rtype: C{list} of C{str}
Verify a signed tag
@param tag: the tag's name
@type tag: C{str}
@return: Whether the signature on the tag could be verified
@rtype: C{bool}
Force HEAD to a specific commit
@param commit: commit to move HEAD to
@param hard: also update the working copy
@type hard: C{bool}
Does the repository contain any uncommitted modifications?
@param ignore_untracked: whether to ignore untracked files when
checking the repository status
@type ignore_untracked: C{bool}
@param paths: only check changes on paths
@type paths: C{list} of C{stings}
@return: C{True} if the repository is clean, C{False} otherwise
and Git's status message
@rtype: C{tuple}
Remove untracked files from the working tree.
@param directories: remove untracked directories, too
@type directories: C{bool}
@param force: satisfy git configuration variable clean.requireForce
@type force: C{bool}
@param dry_run: don’t actually remove anything
@type dry_run: C{bool}
Check status of repository.
@param pathlist: List of paths to check status for
@type pathlist: C{list}
@return C{dict} of C{lists} of paths, where key is a git status flag.
@rtype C{dict}
Is the repository empty?
@return: True if the repositorydoesn't have any commits,
False otherwise
@rtype: C{bool}
Find the SHA1 of a given name
@param name: the name to look for
@type name: C{str}
@param short: try to abbreviate SHA1 to given length
@type short: C{int}
@return: the name's sha1
@rtype: C{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
Checkout treeish
@param treeish: the treeish to check out
@type treeish: C{str}
Check if the repository has the treeish object I{treeish}.
@param treeish: treeish object to look for
@type treeish: C{str}
@return: C{True} if the repository has that tree, C{False} otherwise
@rtype: C{bool}
Create a tree object from the current index
@param index_file: alternate index file to read changes from
@type index_file: C{str}
@return: the new tree object's sha1
@rtype: C{str}
Create a tree based on contents.
@param contents: same format as I{GitRepository.list_tree} output.
@type contents: C{list} of C{str}
Get type of a git repository object
@param obj: repository object
@type obj: C{str}
@return: type of the repository object
@rtype: C{str}
Get a trees content. It returns a list of objects that match the
'ls-tree' output: [mode, type, sha1, path].
@param treeish: the treeish object to list
@type treeish: C{str}
@param recurse: whether to list the tree recursively
@type recurse: C{bool}
@return: the tree
@rtype: C{list} of objects. See above.
Gets the config value associated with I{name}
@param name: config value to get
@return: fetched config value
@rtype: C{str}
Sets the full name to use for git commits. @param name: full name to use
Sets the email address to use for git commits. @param email: email address to use
Determine a sane values for author name and author email from git's
config and environment variables.
@return: name and email
@rtype: L{GitModifier}
Get a list of remote repositories
@return: remote repositories
@rtype: C{dict} of C{GitRemote}
Get all remote repositories
@deprecated: Use get_remotes() instead
@return: remote repositories
@rtype: C{list} of C{str}
Do we know about a remote named I{name}?
@param name: name of the remote repository
@type name: C{str}
@return: C{True} if the remote repositore is known, C{False} otherwise
@rtype: C{bool}
Add a tracked remote repository
@param name: the name to use for the remote
@type name: C{str}
@param url: the url to add
@type url: C{str}
@param tags: whether to fetch tags
@type tags: C{bool}
@param fetch: whether to fetch immediately from the remote side
@type fetch: C{bool}
Download objects and refs from another repository.
@param repo: repository to fetch from
@type repo: C{str}
@param tags: whether to fetch all tag objects
@type tags: C{bool}
@param depth: deepen the history of (shallow) repository to depth I{depth}
@type depth: C{int}
@param refspec: refspec to use instead of the default from git config
@type refspec: C{str}
@param all_remotes: fetch all remotes
@type all_remotes: C{bool}
Fetch and merge from another repository
@param repo: repository to fetch from
@type repo: C{str}
@param ff_only: only merge if this results in a fast forward merge
@type ff_only: C{bool}
@param all_remotes: fetch all remotes
@type all_remotes: C{bool}
Push changes to the remote repo
@param repo: repository to push to
@type repo: C{str}
@param src: the source ref to push
@type src: C{str}
@param dst: the name of the destination ref to push to
@type dst: C{str}
@param ff_only: only push if it's a fast forward update
@type ff_only: C{bool}
@param force: force push, can cause the remote repository to lose
commits; use it with care
@type force: C{bool}
@param tags: push all refs under refs/tags, in addition to other refs
@type tags: C{bool}
@param dry_run: dry run
@type dry_run: C{bool}
Push a tag to the remote repo
@param repo: repository to push to
@type repo: C{str}
@param tag: the name of the tag
@type tag: C{str}
@param dry_run: dry run
@type dry_run: C{bool}
Add files to a the repository
@param paths: list of files to add
@type paths: list or C{str}
@param force: add files even if they would be ignored by .gitignore
@type force: C{bool}
@param index_file: alternative index file to use
@param work_tree: alternative working tree to use
Remove files from the repository
@param paths: list of files to remove
@param paths: C{list} or C{str}
@param verbose: be verbose
@type verbose: C{bool}
List files in index and working tree
@param types: list of types to show
@type types: C{list}
@return: list of files as byte string
@rtype: C{list} of C{str}
Hash a single file and write it into the object database
@param filename: the filename to the content of the file to hash
@type filename: C{bytestr}
@param filters: whether to run filters
@type filters: C{bool}
@return: the hash of the file
@rtype: C{str}
Commit currently staged files to the repository
@param msg: commit message
@type msg: C{str}
@param author_info: authorship information
@type author_info: L{GitModifier}
@param edit: whether to spawn an editor to edit the commit info
@type edit: C{bool}
Commit all changes to the repository
@param msg: commit message
@type msg: C{str}
@param author_info: authorship information
@type author_info: L{GitModifier}
Commit the given files to the repository
@param files: file or files to commit
@type files: C{str} or C{list}
@param msg: commit message
@type msg: C{str}
@param author_info: authorship information
@type author_info: L{GitModifier}
Replace the current tip of branch I{branch} with the contents from I{unpack_dir}
@param unpack_dir: content to add
@type unpack_dir: C{str}
@param msg: commit message to use
@type msg: C{str}
@param branch: branch to add the contents of unpack_dir to
@type branch: C{str}
@param other_parents: additional parents of this commit
@type other_parents: C{list} of C{str}
@param author: author information to use for commit
@type author: C{dict} with keys I{name}, I{email}, I{date}
@param committer: committer information to use for commit
@type committer: C{dict} with keys I{name}, I{email}, I{date}
or L{GitModifier}
@param create_missing_branch: create I{branch} as detached branch if it
doesn't already exist.
@type create_missing_branch: C{bool}
Commit a tree with commit msg I{msg} and parents I{parents}
@param tree: tree to commit
@param msg: commit message
@param parents: parents of this commit
@param author: authorship information
@type author: C{dict} with keys 'name' and 'email' or L{GitModifier}
@param committer: committer information
@type committer: C{dict} with keys 'name' and 'email'
Get commits from since to until touching paths
@param since: commit to start from
@type since: C{str}
@param until: last commit to get
@type until: C{str}
@param paths: only list commits touching paths
@type paths: C{list} of C{str}
@param num: maximum number of commits to fetch
@type num: C{int}
@param options: list of additional options passed to git log
@type options: C{list} of C{str}ings
@param first_parent: only follow first parent when seeing a
merge commit
@type first_parent: C{bool}
Get commmits matching I{regex}
@param regex: regular expression
@type regex: C{str}
@param since: where to start grepping (e.g. a branch)
@type since: C{str}
Gets the subject of a commit.
@deprecated: Use get_commit_info directly
@param commit: the commit to get the subject from
@return: the commit's subject
@rtype: C{str}
Look up data of a specific commit-ish. Dereferences given commit-ish to the commit it points to. @param commitish: the commit-ish to inspect @return: the commit's including id, author, email, subject and body @rtype: dict
Output the commits between start and end as patches in output_dir.
This outputs the revisions I{start...end} by default. When using
I{symmetric} to C{false} it uses I{start..end} instead.
@param start: the commit on the left side of the revision range
@param end: the commit on the right hand side of the revisino range
@param output_dir: directory to write the patches to
@param signature: whether to output a signature
@param thread: whether to include In-Reply-To references
@param symmetric: whether to use the symmetric difference (see above)
Apply a patch using git apply
Diff two git repository objects
@param obj1: first object
@type obj1: C{str}
@param obj2: second object
@type obj2: C{str}
@param paths: List of paths to diff
@type paths: C{list}
@param stat: Show diffstat
@type stat: C{bool} or C{int} or C{str}
@param summary: Show diffstat
@type summary: C{bool}
@param text: Generate textual diffs, treat all files as text
@type text: C{bool}
@param ignore_submodules: ignore changes to submodules
@type ignore_submodules: C{bool}
@return: diff
@rtype: C{binary}
Get file-status of two git repository objects
@param obj1: first object
@type obj1: C{str}
@param obj2: second object
@type obj2: C{str}
@return: name-status
@rtype: C{defaultdict} of C{str}
Create an archive from a treeish
@param format: the type of archive to create, e.g. 'tar.gz'
@type format: C{str}
@param prefix: prefix to prepend to each filename in the archive
@type prefix: C{str}
@param output: the name of the archive to create
@type output: C{str}
@param treeish: the treeish to create the archive from
@type treeish: C{str}
@param cwd: The directory to run in. Defaults to the current dir
@type cwd: C{str}
Cleanup unnecessary files and optimize the local repository
param auto: only cleanup if required
param auto: C{bool}
Does the repo have any submodules?
@param treeish: look into treeish
@type treeish: C{str}
@return: C{True} if the repository has any submodules, C{False}
otherwise
@rtype: C{bool}
Add a submodule
@param repo_path: path to submodule
@type repo_path: C{str}
Update all submodules
@param init: whether to initialize the submodule if necessary
@type init: C{bool}
@param recursive: whether to update submodules recursively
@type recursive: C{bool}
@param fetch: whether to fetch new objects
@type fetch: C{bool}
List the submodules of treeish @return: a list of submodule/commit-id tuples @rtype: list of tuples
Create a repository at path
@param path: where to create the repository
@type path: C{str}
@param bare: whether to create a bare repository
@type bare: C{bool}
@return: git repository object
@rtype: L{GitRepository}
Clone a git repository at I{remote} to I{path}.
@param path: where to clone the repository to
@type path: C{str}
@param remote: URL to clone
@type remote: C{str}
@param depth: create a shallow clone of depth I{depth}
@type depth: C{int}
@param recursive: whether to clone submodules
@type recursive: C{bool}
@param mirror: whether to pass --mirror to git-clone
@type mirror: C{bool}
@param bare: whether to create a bare repository
@type bare: C{bool}
@param auto_name: If I{True} create a directory below I{path} based on
the I{remote}s name. Otherwise create the repo directly at I{path}.
@type auto_name: C{bool}
@param reference: create a clone using local objects from I{reference} repository
@type reference: C{str}
@return: git repository object
@rtype: L{GitRepository}