summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--git/refs/symbolic.py7
-rw-r--r--git/remote.py4
2 files changed, 6 insertions, 5 deletions
diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py
index 238be839..0c0fa404 100644
--- a/git/refs/symbolic.py
+++ b/git/refs/symbolic.py
@@ -285,7 +285,7 @@ class SymbolicReference(object):
commit = property(_get_commit, set_commit, doc="Query or set commits directly") # type: ignore
object = property(_get_object, set_object, doc="Return the object our ref currently refers to") # type: ignore
- def _get_reference(self) -> 'Reference':
+ def _get_reference(self) -> 'SymbolicReference':
""":return: Reference Object we point to
:raise TypeError: If this symbolic reference is detached, hence it doesn't point
to a reference, but to a commit"""
@@ -683,7 +683,7 @@ class SymbolicReference(object):
return (r for r in cls._iter_items(repo, common_path) if r.__class__ == SymbolicReference or not r.is_detached)
@classmethod
- def from_path(cls, repo: 'Repo', path: PathLike) -> Union['Head', 'TagReference', 'Reference']:
+ def from_path(cls: Type[T_References], repo: 'Repo', path: PathLike) -> T_References:
"""
:param path: full .git-directory-relative path name to the Reference to instantiate
:note: use to_full_path() if you only have a partial path of a known Reference Type
@@ -698,12 +698,13 @@ class SymbolicReference(object):
from . import HEAD, Head, RemoteReference, TagReference, Reference
for ref_type in (HEAD, Head, RemoteReference, TagReference, Reference, SymbolicReference):
try:
+ instance: T_References
instance = ref_type(repo, path)
if instance.__class__ == SymbolicReference and instance.is_detached:
raise ValueError("SymbolRef was detached, we drop it")
else:
- assert isinstance(instance, Reference), "instance should be Reference or subtype"
return instance
+
except ValueError:
pass
# END exception handling
diff --git a/git/remote.py b/git/remote.py
index c141519a..3888506f 100644
--- a/git/remote.py
+++ b/git/remote.py
@@ -632,7 +632,7 @@ class Remote(LazyMixin, IterableObj):
as well. This is a fix for the issue described here:
https://github.com/gitpython-developers/GitPython/issues/260
"""
- out_refs: IterableList[RemoteReference] = IterableList(RemoteReference._id_attribute_, "%s/" % self.name)
+ out_refs: IterableList[Reference] = IterableList(RemoteReference._id_attribute_, "%s/" % self.name)
for line in self.repo.git.remote("prune", "--dry-run", self).splitlines()[2:]:
# expecting
# * [would prune] origin/new_branch
@@ -642,7 +642,7 @@ class Remote(LazyMixin, IterableObj):
ref_name = line.replace(token, "")
# sometimes, paths start with a full ref name, like refs/tags/foo, see #260
if ref_name.startswith(Reference._common_path_default + '/'):
- out_refs.append(SymbolicReference.from_path(self.repo, ref_name))
+ out_refs.append(Reference.from_path(self.repo, ref_name))
else:
fqhn = "%s/%s" % (RemoteReference._common_path_default, ref_name)
out_refs.append(RemoteReference(self.repo, fqhn))