summaryrefslogtreecommitdiff
path: root/lib/git/repo.py
diff options
context:
space:
mode:
authorKai Lautaportti <kai.lautaportti@hexagonit.fi>2008-09-12 22:45:43 +0300
committerKai Lautaportti <kai.lautaportti@hexagonit.fi>2008-09-12 22:45:43 +0300
commitfa8fe4cad336a7bdd8fb315b1ce445669138830c (patch)
tree316d7948f2a3a62d7c39fb2c646b332e4ba359d8 /lib/git/repo.py
parentd7781e1056c672d5212f1aaf4b81ba6f18e8dd8b (diff)
downloadgitpython-fa8fe4cad336a7bdd8fb315b1ce445669138830c.tar.gz
Added a read-only Repo.active_branch property which returns the name of the currently active branch.
Diffstat (limited to 'lib/git/repo.py')
-rw-r--r--lib/git/repo.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/git/repo.py b/lib/git/repo.py
index aaa7cecc..55f73f66 100644
--- a/lib/git/repo.py
+++ b/lib/git/repo.py
@@ -458,5 +458,19 @@ class Repo(object):
return len(self.git.diff('HEAD').strip()) > 0
+ @property
+ def active_branch(self):
+ """
+ The name of the currently active branch.
+
+ Returns
+ str (the branch name)
+ """
+ branch = self.git.symbolic_ref('HEAD').strip()
+ if branch.startswith('refs/heads/'):
+ branch = branch[len('refs/heads/'):]
+
+ return branch
+
def __repr__(self):
return '<GitPython.Repo "%s">' % self.path