diff options
-rw-r--r-- | lib/git/refs.py | 6 | ||||
-rw-r--r-- | test/git/test_refs.py | 14 |
2 files changed, 14 insertions, 6 deletions
diff --git a/lib/git/refs.py b/lib/git/refs.py index 45e6dcfb..96c30cd2 100644 --- a/lib/git/refs.py +++ b/lib/git/refs.py @@ -119,7 +119,7 @@ class SymbolicReference(object): # Otherwise it would have detached it if tokens[0] != "ref:": raise ValueError("Failed to parse symbolic refernce: wanted 'ref: <hexsha>', got %r" % value) - return Head(self.repo, tokens[1]).commit + return Reference.from_path(self.repo, tokens[1]).commit def _set_commit(self, commit): """ @@ -149,13 +149,13 @@ class SymbolicReference(object): def _set_reference(self, ref): """ - Set ourselves to the given ref. It will stay a symbol if the ref is a Head. + Set ourselves to the given ref. It will stay a symbol if the ref is a Reference. Otherwise we try to get a commit from it using our interface. Strings are allowed but will be checked to be sure we have a commit """ write_value = None - if isinstance(ref, Head): + if isinstance(ref, SymbolicReference): write_value = "ref: %s" % ref.path elif isinstance(ref, Commit): write_value = ref.sha diff --git a/test/git/test_refs.py b/test/git/test_refs.py index 97617c1b..544a1b8c 100644 --- a/test/git/test_refs.py +++ b/test/git/test_refs.py @@ -89,20 +89,28 @@ class TestRefs(TestBase): for head in heads: cur_head.reference = head assert cur_head.reference == head + assert isinstance(cur_head.reference, Head) assert cur_head.commit == head.commit assert not cur_head.is_detached # END for each head # detach - cur_head.reference = heads[0].commit - assert cur_head.commit == heads[0].commit + active_head = heads[0] + curhead_commit = active_head.commit + cur_head.reference = curhead_commit + assert cur_head.commit == curhead_commit assert cur_head.is_detached self.failUnlessRaises(TypeError, getattr, cur_head, "reference") + # tags are references, hence we can point to them some_tag = rw_repo.tags[0] cur_head.reference = some_tag - assert cur_head.is_detached + assert not cur_head.is_detached assert cur_head.commit == some_tag.commit + assert isinstance(cur_head.reference, TagReference) + + # put HEAD back to a real head, otherwise everything else fails + cur_head.reference = active_head # type check self.failUnlessRaises(ValueError, setattr, cur_head, "reference", "that") |