summaryrefslogtreecommitdiff
path: root/lib/git/refs.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2009-11-03 18:04:40 +0100
committerSebastian Thiel <byronimo@gmail.com>2009-11-03 18:04:40 +0100
commit9b426893ce331f71165c82b1a86252cd104ae3db (patch)
tree5df94563c0243fa8bffa9e8c909dcef79ad69acd /lib/git/refs.py
parent572ace094208c28ab1a8641aedb038456d13f70b (diff)
downloadgitpython-9b426893ce331f71165c82b1a86252cd104ae3db.tar.gz
Reference.from_path now only creates references, not symbolic refs. SymbolicReference.from_path creates only symbolic refs. This change was not detected by a test, hence there is room for improvement on the testing field
Diffstat (limited to 'lib/git/refs.py')
-rw-r--r--lib/git/refs.py28
1 files changed, 21 insertions, 7 deletions
diff --git a/lib/git/refs.py b/lib/git/refs.py
index cd36a052..9c88c5a1 100644
--- a/lib/git/refs.py
+++ b/lib/git/refs.py
@@ -151,18 +151,12 @@ class Reference(LazyMixin, Iterable):
def from_path(cls, repo, path):
"""
Return
- Instance of type Reference, Head, Tag, SymbolicReference or HEAD
+ Instance of type Reference, Head, or Tag
depending on the given path
"""
if not path:
raise ValueError("Cannot create Reference from %r" % path)
- if path == 'HEAD':
- return HEAD(repo, path)
-
- if '/' not in path:
- return SymbolicReference(repo, path)
-
for ref_type in (Head, RemoteReference, TagReference, Reference):
try:
return ref_type(repo, path)
@@ -218,7 +212,10 @@ class SymbolicReference(object):
def __init__(self, repo, name):
if '/' in name:
+ # NOTE: Actually they can be looking like ordinary refs. Theoretically we handle this
+ # case incorrectly
raise ValueError("SymbolicReferences are not located within a directory, got %s" % name)
+ # END error handling
self.repo = repo
self.name = name
@@ -348,6 +345,23 @@ class SymbolicReference(object):
except TypeError:
return True
+ @classmethod
+ def from_path(cls, repo, path):
+ """
+ Return
+ Instance of SymbolicReference or HEAD
+ depending on the given path
+ """
+ if not path:
+ raise ValueError("Cannot create Symbolic Reference from %r" % path)
+
+ if path == 'HEAD':
+ return HEAD(repo, path)
+
+ if '/' not in path:
+ return SymbolicReference(repo, path)
+
+ raise ValueError("Could not find symbolic reference type suitable to handle path %r" % path)
class HEAD(SymbolicReference):
"""