summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2011-10-25 13:01:49 +0200
committerGuido Günther <agx@sigxcpu.org>2011-10-26 10:00:54 +0200
commitf337b8a649b003c9fcc9d8aa3677c290fa0d8859 (patch)
tree45bc7372552a4d0c8f2cd5d0aba3bfd31be0c1f6
parent054d3f574559ae199469a07a1c17931610590dcb (diff)
GitRepository: Allow to list local branches
-rw-r--r--gbp/git.py32
1 files changed, 29 insertions, 3 deletions
diff --git a/gbp/git.py b/gbp/git.py
index 8c0debf..98f23f1 100644
--- a/gbp/git.py
+++ b/gbp/git.py
@@ -711,12 +711,38 @@ class GitRepository(object):
name = os.getenv("GIT_AUTHOR_NAME", name)
return (name, email)
- def get_remote_branches(self):
- """Get all remote branches"""
- args = [ '--format=%(refname:short)', 'refs/remotes/' ]
+ def get_branches(self, remote=False):
+ """
+ Get list of branches
+
+ @param remote: whether to list local or remote branches
+ @type remote: bool
+ @return: local or remote branches
+ @rtype: list
+ """
+ args = [ '--format=%(refname:short)' ]
+ args += [ 'refs/remotes/' ] if remote else [ 'refs/heads/' ]
out = self.__git_getoutput('for-each-ref', args)[0]
return [ ref.strip() for ref in out ]
+ def get_remote_branches(self):
+ """
+ Get list of remote branches
+
+ @return: remote branches
+ @rtype: list
+ """
+ return self.get_branches(remote=True)
+
+ def get_local_branches(self):
+ """
+ Get list of local branches
+
+ @return: local branches
+ @rtype: list
+ """
+ return self.get_branches(remote=False)
+
def get_remote_repos(self):
"""Get all remote repositories"""
out = self.__git_getoutput('remote')[0]