summaryrefslogtreecommitdiff
path: root/git/refs/head.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2016-09-11 18:30:21 +0200
committerSebastian Thiel <byronimo@gmail.com>2016-09-11 18:30:21 +0200
commit06c9c919707ba4116442ca53ac7cf035540981f2 (patch)
tree7a5207918e9e05ae059019f1945f84813d60cf90 /git/refs/head.py
parent2ba897b12024fd20681b7c2f1b40bdbbccd5df59 (diff)
downloadgitpython-06c9c919707ba4116442ca53ac7cf035540981f2.tar.gz
fix(Head): checkout() handles detached head
It's not optimal, as we can now return one of two types which are only compatible in the most basic ways. However, it is better than before, I presume. Fixes #510
Diffstat (limited to 'git/refs/head.py')
-rw-r--r--git/refs/head.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/git/refs/head.py b/git/refs/head.py
index 06207e0a..fe820b10 100644
--- a/git/refs/head.py
+++ b/git/refs/head.py
@@ -202,6 +202,8 @@ class Head(Reference):
:return:
The active branch after the checkout operation, usually self unless
a new branch has been created.
+ If there is no active branch, as the HEAD is now detached, the HEAD
+ reference will be returned instead.
:note:
By default it is only allowed to checkout heads - everything else
@@ -212,7 +214,10 @@ class Head(Reference):
kwargs.pop('f')
self.repo.git.checkout(self, **kwargs)
- return self.repo.active_branch
+ if self.repo.head.is_detached:
+ return self.repo.head
+ else:
+ return self.repo.active_branch
#{ Configruation