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]
 
_check_bare(self)
Check whether this is a bare repository
 
_get_git_dir(self)
 
_check_repo(self, path, toplevel)
 
__init__(self, path, toplevel=True)
x.__init__(...) initializes x; see help(type(x)) for signature
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, config_args=None)
Run a git command with input and return output
 
_git_command(self, command, args=[], extra_env=None)
Execute git command with arguments args and environment env at path.
bool
_cmd_has_feature(self, command, feature)
Check if the git command has certain feature enabled.
 
force_head(self, commit, hard=False)
Force HEAD to a specific commit
 
_status(self, porcelain, ignore_untracked, paths)
tuple
is_clean(self, ignore_untracked=False, paths=None)
Does the repository contain any uncommitted modifications?
 
clean(self, directories=False, force=False, dry_run=False)
Remove untracked files from the working tree.
 
status(self, pathlist=None)
Check status of repository.
bool
is_empty(self)
Is the repository empty?
str
rev_parse(self, name, short=0)
Find the SHA1 of a given name
str
get_config(self, name)
Gets the config value associated with name
 
set_config(self, name, value)
Set a git config value in this repository
 
set_user_name(self, name)
Sets the full name to use for git commits.
 
set_user_email(self, email)
Sets the email address to use for git commits.
GitModifier
get_author_info(self)
Determine a sane values for author name and author email from git's config and environment variables.
 
archive(self, format, prefix, output, treeish, cwd=None)
Create an archive from a treeish
 
collect_garbage(self, auto=False, prune=False, aggressive=False)
Cleanup unnecessary files and optimize the local repository

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

    Branches and Merging
 
rename_branch(self, branch, newbranch)
Rename branch
 
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
bool
has_branch(self, branch, remote=False)
Check if the repository has branch named branch.
 
set_branch(self, branch)
Switch to branch branch
str
get_merge_branch(self, branch)
Get the branch we'd merge from
str
get_merge_base(self, commit1, commit2)
Get the common ancestor between two commits
 
merge(self, commit, verbose=False, edit=False)
Merge changes from the named commit into the current branch
 
abort_merge(self)
Abort a merge
 
is_in_merge(self)
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.
list
_get_branches(self, remote=False)
Get a list of branches
list
get_local_branches(self)
Get a list of local branches
list
get_remote_branches(self)
Get a list of remote branches
 
update_ref(self, ref, new, old=None, msg=None)
Update ref ref to commit new if ref currently points to old
 
branch_contains(self, branch, commit, remote=False)
Check if branch branch contains commit commit
 
set_upstream_branch(self, local_branch, upstream)
Set upstream branches for local branch
str
get_upstream_branch(self, local_branch)
Get upstream branch for the local branch
    Tags
 
create_tag(self, name, msg=None, commit=None, sign=False, keyid=None)
Create a new tag.
 
delete_tag(self, tag)
Delete a tag named tag
 
move_tag(self, old, new)
bool
has_tag(self, tag)
Check if the repository has 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
str
find_branch_tag(self, commit, branch, pattern=None)
Find the closest tag on a certain branch to a given commit
list of str
get_tags(self, pattern=None)
List tags
bool
verify_tag(self, tag)
Verify a signed tag
    Trees
 
checkout(self, treeish)
Checkout treeish
bool
has_treeish(self, treeish)
Check if the repository has the treeish object treeish.
str
write_tree(self, index_file=None)
Create a tree object from the current index
 
make_tree(self, contents)
Create a tree based on contents.
str
get_obj_type(self, obj)
Get type of a git repository object
list of objects. See above.
list_tree(self, treeish, recurse=False, paths=None)
Get a trees content.
    Remote Repositories
dict of GitRemote
get_remotes(self)
Get a list of remote repositories
list of str
get_remote_repos(self)
Get all remote repositories
bool
has_remote_repo(self, name)
Do we know about a remote named name?
 
add_remote_repo(self, name, url, tags=True, fetch=False)
Add a tracked remote repository
 
remove_remote_repo(self, name)
 
fetch(self, repo=None, tags=False, depth=0, refspec=None, all_remotes=False)
Download objects and refs from another repository.
 
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, dry_run=False)
Push changes to the remote repo
 
push_tag(self, repo, tag, dry_run=False)
Push a tag to the remote repo
    Files
 
add_files(self, paths, force=False, index_file=None, work_tree=None)
Add files to a the repository
 
remove_files(self, paths, verbose=False)
Remove files from the repository
list of str
list_files(self, types=['cached'])
List files in index and working tree
str
write_file(self, filename, filters=True)
Hash a single file and write it into the object database
 
rename_file(self, old, new)
Rename file, directory, or symlink
    Comitting
 
_commit(self, msg, args=[], author_info=None)
 
commit_staged(self, msg, author_info=None, edit=False)
Commit currently staged files to the repository
 
commit_all(self, msg, author_info=None, edit=False)
Commit all changes to the repository
 
commit_files(self, files, msg, author_info=None)
Commit the given files 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_tree(self, tree, msg, parents, author={}, committer={})
Commit a tree with commit msg msg and parents parents
    Commit Information
 
get_commits(self, since=None, until=None, paths=None, num=0, first_parent=False, options=None)
Get commits from since to until touching paths
 
show(self, id)
git-show id
 
grep_log(self, regex, since=None)
Get commmits matching regex
str
get_subject(self, commit)
Gets the subject of a commit.
dict
get_commit_info(self, commitish)
Look up data of a specific commit-ish.
    Patches
 
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.
 
apply_patch(self, patch, index=True, context=None, strip=None, fix_ws=False)
Apply a patch using git apply
str
diff(self, obj1, obj2=None, paths=None, stat=False, summary=False, text=False, ignore_submodules=True, abbrev=None, renames=False)
Diff two git repository objects
defaultdict of str
diff_status(self, obj1, obj2)
Get file-status of two git repository objects
    Submodules
bool
has_submodules(self, treeish=None)
Does the repo have any submodules?
 
add_submodule(self, repo_path)
Add a submodule
 
update_submodules(self, init=True, recursive=True, fetch=False)
Update all submodules
list of tuples
get_submodules(self, treeish, path=None, recursive=True)
List the submodules of treeish
Class Methods [hide private]
 
__git_inout(cls, command, args, input, extra_env, cwd, capture_stderr, config_args=None)
As _git_inout but can be used without an instance
    Repository Creation
GitRepository
create(cls, path, description=None, bare=False)
Create a repository at path
GitRepository
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.
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]
  path
The absolute path to the repository
  git_dir
The absolute path to git's metadata
  bare
Whether this is a bare repository
  tags
List of all tags in the repository
  branch
The currently checked out branch
  head
SHA1 of the current HEAD

Inherited from object: __class__

Method Details [hide private]

__init__(self, path, toplevel=True)
(Constructor)

 

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

Parameters:
  • path (str) - path to git repo (or subdir)
  • toplevel (bool) - whether path points to the toplevel dir of git repository
Raises:
Overrides: object.__init__

_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 switch 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, config_args=None)

 

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
  • cwd (str) - directory to switch to when running the command, defaults to self.path
  • capture_stderr (bool) - whether to capture stderr
Returns: tuple of str, str, int
stdout, stderr, return code

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

 

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

_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

rename_branch(self, branch, newbranch)

 

Rename branch

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

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.

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

get_branch(self)

 

On what branch is the current working copy

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

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

set_branch(self, branch)

 

Switch to branch branch

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

get_merge_branch(self, branch)

 

Get the branch we'd merge from

Returns: str
repo and branch we would merge from

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

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

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

_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

get_local_branches(self)

 

Get a list of local branches

Returns: list
local branches

get_remote_branches(self)

 

Get a list of remote branches

Returns: list
remote branches

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

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

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

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

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

 

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

delete_tag(self, tag)

 

Delete a tag named tag

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

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

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

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

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

 

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

Parameters:
  • commit (str) - the commit to describe
  • pattern (str) - only look for tags matching pattern
  • branch (str)
Returns: str
the found tag

get_tags(self, pattern=None)

 

List tags

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

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

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

is_clean(self, ignore_untracked=False, paths=None)

 

Does the repository contain any uncommitted modifications?

Parameters:
  • ignore_untracked (bool) - 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

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

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

is_empty(self)

 

Is the repository empty?

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

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

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

checkout(self, treeish)

 

Checkout treeish

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

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

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

make_tree(self, contents)

 

Create a tree based on contents.

Parameters:
  • contents (list of str) - same format as GitRepository.list_tree output.

get_obj_type(self, obj)

 

Get type of a git repository object

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

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

get_config(self, name)

 

Gets the config value associated with name

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

set_user_name(self, name)

 

Sets the full name to use for git commits.

Parameters:
  • name - full name to use

set_user_email(self, email)

 

Sets the email address to use for git commits.

Parameters:
  • email - email address to use

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_remotes(self)

 

Get a list of remote repositories

Returns: dict of GitRemote
remote repositories

get_remote_repos(self)

 

Get all remote repositories

Returns: list of str
remote repositories

Deprecated: Use get_remotes() instead

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

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

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

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, dry_run=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
  • dry_run (bool) - dry run

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

 

Push a tag to the remote repo

Parameters:
  • repo (str) - repository to push to
  • tag (str) - the name of the tag
  • dry_run (bool) - dry run

add_files(self, paths, force=False, 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
  • index_file - alternative index file to use
  • work_tree - alternative working tree to use

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

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

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

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

 

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

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_files(self, files, msg, author_info=None)

 

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

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_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

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

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)

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_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

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)

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

 

Diff two git repository objects

Parameters:
  • obj1 (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

archive(self, format, prefix, output, treeish, cwd=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) - 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

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

 

Cleanup unnecessary files and optimize the local repository

param auto: only cleanup if required param auto: bool

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

add_submodule(self, repo_path)

 

Add a submodule

Parameters:
  • repo_path (str) - path to submodule

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

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

 

List the submodules of treeish

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

create(cls, 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

clone(cls, path, remote, depth=0, recursive=False, mirror=False, bare=False, auto_name=True, reference=None)
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.
  • reference (str) - create a clone using local objects from reference repository
Returns: GitRepository
git repository object

Property Details [hide private]

path

The absolute path to the repository

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

git_dir

The absolute path to git's metadata

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

bare

Whether this is a bare repository

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

tags

List of all tags in the repository

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

branch

The currently checked out branch

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

head

SHA1 of the current HEAD

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