diff options
author | Kai Lautaportti <kai.lautaportti@hexagonit.fi> | 2008-09-12 22:45:43 +0300 |
---|---|---|
committer | Kai Lautaportti <kai.lautaportti@hexagonit.fi> | 2008-09-12 22:45:43 +0300 |
commit | fa8fe4cad336a7bdd8fb315b1ce445669138830c (patch) | |
tree | 316d7948f2a3a62d7c39fb2c646b332e4ba359d8 /lib/git/repo.py | |
parent | d7781e1056c672d5212f1aaf4b81ba6f18e8dd8b (diff) | |
download | gitpython-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.py | 14 |
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 |