From fa8fe4cad336a7bdd8fb315b1ce445669138830c Mon Sep 17 00:00:00 2001 From: Kai Lautaportti Date: Fri, 12 Sep 2008 22:45:43 +0300 Subject: Added a read-only Repo.active_branch property which returns the name of the currently active branch. --- lib/git/repo.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lib/git/repo.py') 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 '' % self.path -- cgit v1.2.1