Package gbp :: Package git :: Module repository :: Class GitRepository
[hide private]
[frames] | no frames]

Class GitRepository

object --+
         |
        GitRepository
Known Subclasses:

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

Instance Methods [hide private]
 
__init__(self, path)
x.__init__(...) initializes x; see help(type(x)) for signature
 
_check_dirs(self)
Get top level dir and git meta data dir
bool
_cmd_has_feature(self, command, feature)
Check if the git command has certain feature enabled.
 
_git_command(self, command, args=[], extra_env=None, interactive=False)
Execute git command with arguments args and environment env at path.
tuple of list of str and int
_git_getoutput(self, command, args=[], extra_env=None, cwd=None)
Run a git command and return the output
tuple of str, str, int
_git_inout(self, command, args, input=None, extra_env=None, cwd=None, capture_stderr=False, capture_stdout=True)
Run a git command with input and return output
 
_git_inout2(self, command, args, stdin=None, extra_env=None, cwd=None, capture_stderr=False)
Quite similar to _git_inout() but returns stdout output of the git command as a Python generator object, instead.
 
_status(self, porcelain, ignore_untracked)
None or generator of str
archive(self, format, prefix, output, treeish, paths=None)
Create an archive from a treeish
 
clean(self, directories=False, force=False, dry_run=False)
Remove untracked files from the working tree.
 
collect_garbage(self, auto=False)
Cleanup unnecessary files and optimize the local repository
 
force_head(self, commit, hard=False)
Force HEAD to a specific commit
GitModifier
get_author_info(self)
Determine a sane values for author name and author email from git's config and environment variables.
str
get_config(self, name)
Gets the config value associated with name
tuple
is_clean(self, ignore_untracked=False)
Does the repository contain any uncommitted modifications?
bool
is_empty(self)
Is the repository empty?
str
rev_parse(self, name, short=0)
Find the SHA1 of a given name
 
status(self, pathlist=None)
Check status of repository.

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

    Branches and Merging
list
_get_branches(self, remote=False)
Get a list of branches
 
branch_contains(self, branch, commit, remote=False)
Check if branch branch contains commit commit
 
create_branch(self, branch, rev=None, force=False)
Create a new branch
 
delete_branch(self, branch, remote=False)
Delete branch branch
str
get_branch(self)
On what branch is the current working copy
list
get_local_branches(self)
Get a list of local branches
str
get_merge_base(self, commit1, commit2)
Get the common ancestor between two commits
str
get_merge_branch(self, branch)
Get the branch we'd merge from
list
get_remote_branches(self)
Get a list of remote branches
str
get_upstream_branch(self, local_branch)
Get upstream branch for the local branch
bool
has_branch(self, branch, remote=False)
Check if the repository has branch named branch.
tuple
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.
 
merge(self, commit, verbose=False, edit=False)
Merge changes from the named commit into the current branch
 
rename_branch(self, branch, newbranch)
Rename branch
 
set_branch(self, branch)
Switch to branch branch
 
set_upstream_branch(self, local_branch, upstream)
Set upstream branches for local branch
 
update_ref(self, ref, new, old=None, msg=None)
Update ref ref to commit new if ref currently points to old
    Tags
 
create_tag(self, name, msg=None, commit=None, sign=False, keyid=None, annotate=False)
Create a new tag.
 
delete_tag(self, tag)
Delete a tag named tag
str
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.
str
find_tag(self, commit, pattern=None)
Find the closest tag to a given commit
list of str
get_tags(self, pattern=None)
List tags
bool
has_tag(self, tag)
Check if the repository has a tag named tag.
 
move_tag(self, old, new)
bool
verify_tag(self, tag)
Verify a signed tag
    Trees
 
checkout(self, treeish)
Checkout treeish
str
get_obj_type(self, obj)
Get type of a git repository object
bool
has_treeish(self, treeish)
Check if the repository has the treeish object treeish.
list of objects. See above.
list_tree(self, treeish, recurse=False, paths=None)
Get a trees content.
 
make_tree(self, contents)
Create a tree based on contents.
str
write_tree(self, index_file=None)
Create a tree object from the current index
    Remote Repositories
 
add_remote_repo(self, name, url, tags=True, fetch=False)
Add a tracked remote repository
 
fetch(self, repo=None, tags=False, depth=0, refspec=None, all_remotes=False)
Download objects and refs from another repository.
dict of list of str
get_remote_repos(self)
Get all remote repositories
dict of GitRemote
get_remotes(self)
Get a list of remote repositories
bool
has_remote_repo(self, name)
Do we know about a remote named name?
 
pull(self, repo=None, ff_only=False, all_remotes=False)
Fetch and merge from another repository
 
push(self, repo=None, src=None, dst=None, ff_only=True, force=False, tags=False)
Push changes to the remote repo
 
push_tag(self, repo, tag)
Push a tag to the remote repo
 
remove_remote_repo(self, name)
    Files
 
add_files(self, paths, force=False, untracked=True, index_file=None, work_tree=None)
Add files to a the repository
list of str
list_files(self, types=['cached'])
List files in index and working tree
 
remove_files(self, paths, verbose=False)
Remove files from the repository
str
write_file(self, filename, filters=True)
Hash a single file and write it into the object database
    Comitting
 
_commit(self, msg, args=[], author_info=None, committer_info=None, edit=False)
 
commit_all(self, msg, author_info=None, edit=False)
Commit all changes to the repository
 
commit_dir(self, unpack_dir, msg, branch, other_parents=None, author={}, committer={}, create_missing_branch=False)
Replace the current tip of branch branch with the contents from unpack_dir
 
commit_files(self, files, msg, author_info=None, committer_info=None, edit=False)
Commit the given files to the repository
 
commit_staged(self, msg, author_info=None, edit=False, committer_info=None)
Commit currently staged files to the repository
 
commit_tree(self, tree, msg, parents, author={}, committer={})
Commit a tree with commit msg msg and parents parents
str
create_tree(self, unpack_dir)
Create a tree object out of a directory content
    Commit Information
dict
get_commit_info(self, commitish)
Look up data of a specific commit-ish.
 
get_commits(self, since=None, until=None, paths=None, num=0, first_parent=False, options=None)
Get commits from since to until touching paths
str
get_subject(self, commit)
Gets the subject of a commit.
 
grep_log(self, regex, since=None)
Get commmits matching regex
 
show(self, id)
git-show id
    Patches
 
apply_patch(self, patch, index=True, context=None, strip=None)
Apply a patch using git apply
str
diff(self, obj1, obj2=None, paths=None, stat=False, summary=False, text=False, ignore_submodules=True)
Diff two git repository objects
defaultdict of str
diff_status(self, obj1, obj2)
Get file-status of two git repository objects
 
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.
    Submodules
 
add_submodule(self, repo_path)
Add a submodule
list of tuples
get_submodules(self, treeish, path=None, recursive=True)
List the submodules of treeish
bool
has_submodules(self, treeish=None)
Does the repo have any submodules?
 
update_submodules(self, init=True, recursive=True, fetch=False)
Update all submodules
Class Methods [hide private]
 
__git_inout(cls, command, args, stdin, extra_env, cwd, capture_stderr, capture_stdout)
Run a git command without a a GitRepostitory instance.
    Repository Creation
GitRepository
clone(klass, path, remote, depth=0, recursive=False, mirror=False, bare=False, auto_name=True)
Clone a git repository at remote to path.
GitRepository
create(klass, path, description=None, bare=False)
Create a repository at path
Static Methods [hide private]
 
__build_env(extra_env)
Prepare environment for subprocess calls
 
strip_sha1(sha1, length=0)
Strip a given sha1 and check if the resulting hash has the expected length.
Instance Variables [hide private]
bool _bare
Whether this is a bare repository
str _path
The path to the working tree
Properties [hide private]
  bare
Wheter this is a bare repository
  branch
The currently checked out branch
  git_dir
The absolute path to git's metadata
  head
return the SHA1 of the current HEAD
  path
The absolute path to the repository
  tags
List of all tags in the repository

Inherited from object: __class__

Method Details [hide private]

__git_inout(cls, command, args, stdin, extra_env, cwd, capture_stderr, capture_stdout)
Class Method

 

Run a git command without a a GitRepostitory instance.

Returns the git command output (stdout, stderr) as a Python generator object.

Note: The caller must consume the iterator that is returned, in order to make sure that the git command runs and terminates.

__init__(self, path)
(Constructor)

 

x.__init__(...) initializes x; see help(type(x)) for signature

Raises:
Overrides: object.__init__
(inherited documentation)

_cmd_has_feature(self, command, feature)

 

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_branches(self, remote=False)

 

Get a list of branches

Parameters:
  • remote (bool) - whether to list local or remote branches
Returns: list
local or remote branches

_git_command(self, command, args=[], extra_env=None, interactive=False)

 

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

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

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

 

Run a git command and return the output

Parameters:
  • command (str) - git command to run
  • args (list) - list of arguments
  • extra_env (dict) - extra environment variables to pass
  • cwd (str) - directory to swith to when running the command, defaults to self.path
Returns: tuple of list of str and int
stdout, return code

_git_inout(self, command, args, input=None, extra_env=None, cwd=None, capture_stderr=False, capture_stdout=True)

 

Run a git command with input and return output

Parameters:
  • command (str) - git command to run
  • input (str) - input to pipe to command
  • args (list) - list of arguments
  • extra_env (dict) - extra environment variables to pass
  • capture_stderr (bool) - whether to capture stderr
Returns: tuple of str, str, int
stdout, stderr, return code

_git_inout2(self, command, args, stdin=None, extra_env=None, cwd=None, capture_stderr=False)

 

Quite similar to _git_inout() but returns stdout output of the git command as a Python generator object, instead. Also, stderr is not returned.

Note: The caller must consume the iterator that is returned, in order to make sure that the git command runs and terminates.

add_files(self, paths, force=False, untracked=True, index_file=None, work_tree=None)

 

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
  • untracked (bool) - add also previously untracked files
  • index_file - alternative index file to use
  • work_tree - alternative working tree to use

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

 

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

add_submodule(self, repo_path)

 

Add a submodule

Parameters:
  • repo_path (str) - path to submodule

archive(self, format, prefix, output, treeish, paths=None)

 

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 or None) - the name of the archive to create, empty string or None gives data as return value
  • treeish (str) - the treeish to create the archive from
  • paths (list of str) - List of paths to include in the archive
Returns: None or generator of str
archive data as a generator object

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

 

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

checkout(self, treeish)

 

Checkout treeish

Parameters:
  • treeish (str) - the treeish to check out

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

 

Remove untracked files from the working tree.

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

clone(klass, path, remote, depth=0, recursive=False, mirror=False, bare=False, auto_name=True)
Class Method

 

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_name (bool) - If True create a directory below path based on the remotes name. Otherwise create the repo directly at path.
Returns: GitRepository
git repository object

collect_garbage(self, auto=False)

 

Cleanup unnecessary files and optimize the local repository

param auto: only cleanup if required param auto: bool

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

 

Commit all changes to the repository

Parameters:
  • msg (str) - commit message
  • author_info (GitModifier) - authorship information

commit_dir(self, unpack_dir, msg, branch, other_parents=None, author={}, committer={}, create_missing_branch=False)

 

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

Parameters:
  • unpack_dir (str) - content to add
  • msg (str) - commit message to use
  • branch (str) - branch to add the contents of unpack_dir to
  • other_parents (list of str) - 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_missing_branch (bool) - create branch as detached branch if it doesn't already exist.

commit_files(self, files, msg, author_info=None, committer_info=None, edit=False)

 

Commit the given files to the repository

Parameters:
  • files (str or list) - file or files to commit
  • msg (str) - commit message
  • author_info (GitModifier) - authorship information
  • committer_info (GitModifier) - committer information
  • edit (bool) - whether to spawn an editor to edit the commit info

commit_staged(self, msg, author_info=None, edit=False, committer_info=None)

 

Commit currently staged files to the repository

Parameters:
  • msg (str) - commit message
  • author_info (GitModifier) - authorship information
  • edit (bool) - whether to spawn an editor to edit the commit info
  • committer_info (GitModifier) - committer information

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 (dict with keys 'name' and 'email' or GitModifier) - authorship information
  • committer (dict with keys 'name' and 'email') - committer information

create(klass, path, description=None, bare=False)
Class Method

 

Create a repository at path

Parameters:
  • path (str) - where to create the repository
  • bare (bool) - whether to create a bare repository
Returns: GitRepository
git repository object

create_branch(self, branch, rev=None, force=False)

 

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 form the current HEAD.

create_tag(self, name, msg=None, commit=None, sign=False, keyid=None, annotate=False)

 

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
  • annotate (bool) - Create an annotated tag

create_tree(self, unpack_dir)

 

Create a tree object out of a directory content

Parameters:
  • unpack_dir (str) - content to add
Returns: str
the tree object hash

delete_branch(self, branch, remote=False)

 

Delete branch branch

Parameters:
  • branch (str) - name of the branch to delete
  • remote - delete a remote branch
  • remote - bool

delete_tag(self, tag)

 

Delete a tag named tag

Parameters:
  • tag (str) - the tag to delete

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 (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_match (bool) - only output exact matches (a tag directly references the supplied commit)
Returns: str
tag name plus/or the abbreviated sha1

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

 

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_submodules (bool) - ignore changes to submodules
Returns: str
diff

diff_status(self, obj1, obj2)

 

Get file-status of two git repository objects

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

fetch(self, repo=None, tags=False, depth=0, refspec=None, all_remotes=False)

 

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_remotes (bool) - fetch all remotes

find_tag(self, commit, pattern=None)

 

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(self, commit, hard=False)

 

Force HEAD to a specific commit

Parameters:
  • commit - commit to move HEAD to
  • hard (bool) - also update the working copy

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)

get_author_info(self)

 

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

Returns: GitModifier
name and email

get_branch(self)

 

On what branch is the current working copy

Returns: str
current branch or None in an empty repo
Raises:

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: dict
the commit's including id, author, email, subject and body

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 (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
  • options (list of strings) - list of additional options passed to git log
  • first_parent (bool) - only follow first parent when seeing a merge commit

get_config(self, name)

 

Gets the config value associated with name

Parameters:
  • name - config value to get
Returns: str
fetched config value

get_local_branches(self)

 

Get a list of local branches

Returns: list
local branches

get_merge_base(self, commit1, commit2)

 

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_merge_branch(self, branch)

 

Get the branch we'd merge from

Returns: str
repo and branch we would merge from

get_obj_type(self, obj)

 

Get type of a git repository object

Parameters:
  • obj (str) - repository object
Returns: str
type of the repository object

get_remote_branches(self)

 

Get a list of remote branches

Returns: list
remote branches

get_remote_repos(self)

 

Get all remote repositories

Returns: dict of list of str
remote repositories

Deprecated: Use get_remotes() instead

get_remotes(self)

 

Get a list of remote repositories

Returns: dict of GitRemote
remote repositories

get_subject(self, commit)

 

Gets the subject of a commit.

Parameters:
  • commit - the commit to get the subject from
Returns: str
the commit's subject

Deprecated: Use get_commit_info directly

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

 

List the submodules of treeish

Returns: list of tuples
a list of submodule/commit-id tuples

get_tags(self, pattern=None)

 

List tags

Parameters:
  • pattern (str) - only list tags matching pattern
Returns: list of str
tags

get_upstream_branch(self, local_branch)

 

Get upstream branch for the local branch

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

grep_log(self, regex, since=None)

 

Get commmits matching regex

Parameters:
  • regex (str) - regular expression
  • since (str) - where to start grepping (e.g. a branch)

has_branch(self, branch, remote=False)

 

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

has_remote_repo(self, name)

 

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

has_submodules(self, treeish=None)

 

Does the repo have any submodules?

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

has_tag(self, tag)

 

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

has_treeish(self, treeish)

 

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

is_clean(self, ignore_untracked=False)

 

Does the repository contain any uncommitted modifications?

Parameters:
  • ignore_untracked (bool) - whether to ignore untracked files when checking the repository status
Returns: tuple
True if the repository is clean, False otherwise and Git's status message

is_empty(self)

 

Is the repository empty?

Returns: bool
True if the repositorydoesn't have any commits, False otherwise

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: tuple
can_fast_forward, up_to_date

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

 

List files in index and working tree

Parameters:
  • types (list) - list of types to show
Returns: list of str
list of files

list_tree(self, treeish, recurse=False, paths=None)

 

Get a trees content. It returns a list of objects that match the 'ls-tree' output: [ mode, type, sha1, path ].

Parameters:
  • treeish (str) - the treeish object to list
  • recurse (bool) - whether to list the tree recursively
Returns: list of objects. See above.
the tree

make_tree(self, contents)

 

Create a tree based on contents. contents has the same format than the GitRepository.list_tree output.

merge(self, commit, verbose=False, edit=False)

 

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) - wheter to invoke an editor to edit the merge message

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

 

Fetch and merge from another repository

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

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

 

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 (bool) - 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

push_tag(self, repo, tag)

 

Push a tag to the remote repo

Parameters:
  • repo (str) - repository to push to
  • tag (str) - the name of the tag

remove_files(self, paths, verbose=False)

 

Remove files from the repository

Parameters:
  • paths - list of files to remove
  • paths - list or str
  • verbose (bool) - be verbose

rename_branch(self, branch, newbranch)

 

Rename branch

Parameters:
  • branch - name of the branch to be renamed
  • newbranch - new name of the branch

rev_parse(self, name, short=0)

 

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_branch(self, branch)

 

Switch to branch branch

Parameters:
  • branch (str) - name of the branch to switch to

set_upstream_branch(self, local_branch, upstream)

 

Set upstream branches for local branch

Parameters:
  • local_branch (str) - name of the local branch
  • upstream (str) - remote/branch, for example origin/master

status(self, pathlist=None)

 

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

strip_sha1(sha1, length=0)
Static Method

 

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):
...
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):
...
GitRepositoryError: 'foobar' is not a valid sha1

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

 

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_submodules(self, init=True, recursive=True, fetch=False)

 

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_tag(self, tag)

 

Verify a signed tag

Parameters:
  • tag (str) - the tag's name
Returns: bool
Whether the signature on the tag could be verified

write_file(self, filename, filters=True)

 

Hash a single file and write it into the object database

Parameters:
  • filename (str) - the filename to the content of the file to hash
  • filters (bool) - whether to run filters
Returns: str
the hash of the file

write_tree(self, index_file=None)

 

Create a tree object from the current index

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

Property Details [hide private]

bare

Wheter this is a bare repository

Get Method:
unreachable.bare(self) - Wheter this is a bare repository

branch

The currently checked out branch

Get Method:
unreachable.branch(self) - The currently checked out branch

git_dir

The absolute path to git's metadata

Get Method:
unreachable.git_dir(self) - The absolute path to git's metadata

head

return the SHA1 of the current HEAD

Get Method:
unreachable.head(self) - return the SHA1 of the current HEAD

path

The absolute path to the repository

Get Method:
unreachable.path(self) - The absolute path to the repository

tags

List of all tags in the repository

Get Method:
unreachable.tags(self) - List of all tags in the repository