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

Class GitRepository

object --+
         |
        GitRepository

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
__git_getoutput(self, command, args=[], extra_env=None, cwd=None)
Run a git command and return the output
tuple
__git_inout(self, command, args, input, extra_env=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.
 
force_head(self, commit, hard=False)
Force HEAD to a specific commit
tuple
is_clean(self)
Does the repository contain any uncommitted modifications?
bool
is_empty(self)
Is the repository empty?
str
rev_parse(self, name)
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)
 
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
 
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
 
merge(self, commit, verbose=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
    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.
 
_build_legacy_tag(self, format, version)
legacy version numbering
 
find_version(self, format, version)
Check if a certain version is stored in this repo.
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
    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
    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
 
fetch(self, repo=None)
Download objects and refs from another repository.
 
pull(self, repo=None, ff_only=False)
Fetch and merge from another repository
    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
    Comitting
 
_commit(self, msg, args=[], author_info=None)
 
commit_staged(self, msg, author_info=None)
Commit currently staged files to the repository
 
commit_all(self, msg, author_info=None)
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={})
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, options=None, first_parent=False)
Get commits from since to until touching paths
 
show(self, id)
git-show id
 
grep_log(self, regex, where=None)
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)
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
    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

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
stdout, return code

__git_inout(self, command, args, input, extra_env=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
Returns: tuple
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

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

merge(self, commit, verbose=False)

 

Merge changes from the named commit into the current branch

Parameters:
  • commit (str) - the commit to merge from (usually a branch name)

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

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_version(self, format, version)

 

Check if a certain version is stored in this repo. Return it's SHA1 in this case. For legacy tags Don't check only the tag but also the message, since the former wasn't injective until recently. You only need to use this funciton if you also need to check for legacy tags.

Parameters:
  • format - tag pattern
  • version - debian version number
Returns:
sha1 of the version tag

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

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)

 

Does the repository contain any uncommitted modifications?

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)

 

Find the SHA1 of a given name

Parameters:
  • name (str) - the name to look for
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 write the current index to
Returns: str
the new tree object's sha1

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)

 

Download objects and refs from another repository.

Parameters:
  • repo (str) - repository to fetch from

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

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

commit_staged(self, msg, author_info=None)

 

Commit currently staged files to the repository

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

commit_all(self, msg, author_info=None)

 

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={})

 

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) - committer information to use for commit

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

get_commits(self, since=None, until=None, paths=None, options=None, first_parent=False)

 

Get commits from since to until touching paths

Parameters:
  • since - commit to start from
  • until - last commit to get
  • paths - only list commits touching paths
  • options (list of strings) - list of options passed to git log
  • first_parent (bool) - only follow first parent when seeing a merge commit

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

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