aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2012-01-10 15:58:56 +0100
committerGuido Günther <agx@sigxcpu.org>2012-01-10 17:02:00 +0100
commite3482c406796152ea3ab9d2c3c4afe43ca5056fd (patch)
tree004642b8fe7f26545498aa7e3ae985af981f798d
parent07b86440438286a03ffa7b314534f9bbb3d0a805 (diff)
GitRepository: Add branch_contains()
to check if a branch contains a specific commit
-rw-r--r--gbp/git/repository.py21
-rw-r--r--tests/test_GitRepository.py3
2 files changed, 24 insertions, 0 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py
index 92cd40d4..640cc88a 100644
--- a/gbp/git/repository.py
+++ b/gbp/git/repository.py
@@ -370,6 +370,27 @@ class GitRepository(object):
args = [ '-m', msg ] + args
self._git_command("update-ref", args)
+ def branch_contains(self, branch, commit, remote=False):
+ """
+ Check if branch I{branch} contains commit I{commit}
+
+ @param branch: the branch the commit should be on
+ @type branch: C{str}
+ @param commit: the C{str} commit to check
+ @type commit: C{str}
+ @param remote: whether to check remote instead of local branches
+ @type remote: C{bool}
+ """
+ args = GitArgs('--contains')
+ args.add_true(remote, '-r')
+ args.add(commit)
+
+ out, ret = self.__git_getoutput('branch', args.args)
+ for line in out:
+ if line.strip() == branch:
+ return True
+ return False
+
#{ Tags
def create_tag(self, name, msg=None, commit=None, sign=False, keyid=None):
diff --git a/tests/test_GitRepository.py b/tests/test_GitRepository.py
index 01b96da8..684ea7bb 100644
--- a/tests/test_GitRepository.py
+++ b/tests/test_GitRepository.py
@@ -110,10 +110,13 @@ def test_create_branch():
Methods tested:
- L{gbp.git.GitRepository.create_branch}
+ - L{gbp.git.GitRepository.branch_contains}
>>> import gbp.git, shutil
>>> repo = gbp.git.GitRepository(repo_dir)
>>> repo.create_branch("foo")
+ >>> repo.branch_contains("foo", 'HEAD')
+ True
"""
def test_delete_branch():