From 9b426893ce331f71165c82b1a86252cd104ae3db Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 3 Nov 2009 18:04:40 +0100 Subject: 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 --- lib/git/refs.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'lib/git/refs.py') 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): """ -- cgit v1.2.1