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
 
__init__(self, path)
x.__init__(...) initializes x; see help(type(x)) for signature
 
__build_env(self, extra_env)
Prepare environment for subprocess calls
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)
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.
 
force_head(self, commit, hard=False)
Force HEAD to a specific commit
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
str
get_config(self, name)
Gets the config value associated with name
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, **kwargs)
Create an archive from a treeish
 
collect_garbage(self, auto=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)
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
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
    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
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
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)
Get a trees content.
    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)
Download objects and refs from another repository.
 
pull(self, repo=None, ff_only=False)
Fetch and merge from another repository
 
push(self, repo=None, src=None, dst=None, ff_only=True)
Push changes to the remote repo
 
push_tag(self, repo, tag)
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
    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, commit)
Look up data of a specific commit
    Patches
 
format_patches(self, start, end, output_dir, signature=True, thread=None)
Output the commits between start and end as patches in output_dir
 
apply_patch(self, patch, index=True, context=None, strip=None)
Apply a patch using git apply
str
diff(self, obj1, obj2)
Diff two git repository objects
    Submodules
bool
has_submodules(self)
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]
    Repository Creation
GitRepository
create(klass, path, description=None, bare=False)
Create a repository at path
GitRepository
clone(klass, path, remote, depth=0, recursive=False, mirror=False, bare=False, auto_name=True)
Clone a git repository at remote to path.
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
Wheter this is a bare repository
  tags
List of all tags in the repository
  branch
The currently checked out branch
  head
return the SHA1 of the current HEAD

Inherited from object: __class__

Method Details [hide private]

__init__(self, path)
(Constructor)

 

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

Raises:
Overrides: object.__init__
(inherited documentation)

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

 

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

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)

 

Create a new branch

Parameters:
  • branch - the branch's name
  • rev - where to start the branch from

    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

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) - wheter 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

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

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

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)

 

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

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

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. contents has the same format than the 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)

 

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

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

 

Get all remote repositories

Returns: list of str
remote repositories

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)

 

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

pull(self, repo=None, ff_only=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

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

 

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

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

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') - comitter 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

get_commit_info(self, commit)

 

Look up data of a specific commit

Parameters:
  • commit - the commit to inspect
Returns: dict
the commit's including id, author, email, subject and body

diff(self, obj1, obj2)

 

Diff two git repository objects

Parameters:
  • obj1 (str) - first object
  • obj2 (str) - second object
Returns: str
diff

archive(self, format, prefix, output, treeish, **kwargs)

 

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
  • kwargs - additional commandline options passed to git-archive

collect_garbage(self, auto=False)

 

Cleanup unnecessary files and optimize the local repository

param auto: only cleanup if required param auto: bool

has_submodules(self)

 

Does the repo have any submodules?

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

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

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

Wheter this is a bare repository

Get Method:
unreachable.bare(self) - Wheter 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

return the SHA1 of the current HEAD

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