diff options
Diffstat (limited to 'git')
-rw-r--r-- | git/objects/submodule/base.py | 8 | ||||
-rw-r--r-- | git/refs/symbolic.py | 41 | ||||
-rw-r--r-- | git/refs/tag.py | 6 | ||||
-rw-r--r-- | git/repo/base.py | 3 |
4 files changed, 36 insertions, 22 deletions
diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py index 29212167..14351190 100644 --- a/git/objects/submodule/base.py +++ b/git/objects/submodule/base.py @@ -563,6 +563,7 @@ class Submodule(IndexObject, TraversableIterableObj): progress.update(op, i, len_rmts, prefix + "Done fetching remote of submodule %r" % self.name) # END fetch new data except InvalidGitRepositoryError: + mrepo = None if not init: return self # END early abort if init is not allowed @@ -603,7 +604,7 @@ class Submodule(IndexObject, TraversableIterableObj): # make sure HEAD is not detached mrepo.head.set_reference(local_branch, logmsg="submodule: attaching head to %s" % local_branch) - mrepo.head.ref.set_tracking_branch(remote_branch) + mrepo.head.reference.set_tracking_branch(remote_branch) except (IndexError, InvalidGitRepositoryError): log.warning("Failed to checkout tracking branch %s", self.branch_path) # END handle tracking branch @@ -629,13 +630,14 @@ class Submodule(IndexObject, TraversableIterableObj): if mrepo is not None and to_latest_revision: msg_base = "Cannot update to latest revision in repository at %r as " % mrepo.working_dir if not is_detached: - rref = mrepo.head.ref.tracking_branch() + rref = mrepo.head.reference.tracking_branch() if rref is not None: rcommit = rref.commit binsha = rcommit.binsha hexsha = rcommit.hexsha else: - log.error("%s a tracking branch was not set for local branch '%s'", msg_base, mrepo.head.ref) + log.error("%s a tracking branch was not set for local branch '%s'", + msg_base, mrepo.head.reference) # END handle remote ref else: log.error("%s there was no local tracking branch", msg_base) diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index d5dc87c6..4ae7a9d1 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -25,7 +25,7 @@ from git.types import Commit_ish, PathLike, TBD, Literal if TYPE_CHECKING: from git.repo import Repo - from git.refs import Reference, Head, HEAD, TagReference, RemoteReference + from git.refs import Reference, Head, TagReference, RemoteReference T_References = TypeVar('T_References', bound='SymbolicReference') @@ -60,6 +60,7 @@ class SymbolicReference(object): def __init__(self, repo: 'Repo', path: PathLike, check_path: bool = False) -> None: self.repo = repo self.path = str(path) + self.ref = self._get_reference() def __str__(self) -> str: return self.path @@ -279,7 +280,7 @@ class SymbolicReference(object): object = property(_get_object, set_object, doc="Return the object our ref currently refers to") def _get_reference(self - ) -> Union['HEAD', 'Head', 'RemoteReference', 'TagReference', 'Reference', 'SymbolicReference']: + ) -> Union['Head', 'RemoteReference', 'TagReference', 'Reference']: """: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""" @@ -288,7 +289,8 @@ class SymbolicReference(object): raise TypeError("%s is a detached symbolic reference as it points to %r" % (self, sha)) return self.from_path(self.repo, target_ref_path) - def set_reference(self, ref, logmsg=None): + def set_reference(self, ref: Union[str, Commit_ish, 'SymbolicReference'], logmsg: Union[str, None] = None + ) -> None: """Set ourselves to the given ref. It will stay a symbol if the ref is a Reference. Otherwise an Object, given as Object instance or refspec, is assumed and if valid, will be set which effectively detaches the refererence if it was a purely @@ -355,12 +357,16 @@ class SymbolicReference(object): if logmsg is not None: self.log_append(oldbinsha, logmsg) - return self + return None - # aliased reference - reference: Union[Commit_ish, 'Head', 'Reference'] = property( # type: ignore - _get_reference, set_reference, doc="Returns the Reference we point to") - ref = reference + @ property + def reference(self) -> Union['Head', 'RemoteReference', 'TagReference', 'Reference']: + return self._get_reference() + + @ reference.setter + def reference(self, ref: Union[str, Commit_ish, 'SymbolicReference'], logmsg: Union[str, None] = None + ) -> None: + return self.set_reference(ref=ref, logmsg=logmsg) def is_valid(self) -> bool: """ @@ -374,7 +380,7 @@ class SymbolicReference(object): else: return True - @property + @ property def is_detached(self): """ :return: @@ -424,7 +430,7 @@ class SymbolicReference(object): In that case, it will be faster than the ``log()`` method""" return RefLog.entry_at(RefLog.path(self), index) - @classmethod + @ classmethod def to_full_path(cls, path: Union[PathLike, 'SymbolicReference']) -> str: """ :return: string with a full repository-relative path which can be used to initialize @@ -439,7 +445,7 @@ class SymbolicReference(object): full_ref_path = '%s/%s' % (cls._common_path_default, path) return full_ref_path - @classmethod + @ classmethod def delete(cls, repo: 'Repo', path: PathLike) -> None: """Delete the reference at the given path @@ -497,8 +503,10 @@ class SymbolicReference(object): os.remove(reflog_path) # END remove reflog - @classmethod - def _create(cls, repo, path, resolve, reference, force, logmsg=None): + @ classmethod + def _create(cls: Type[T_References], repo: 'Repo', path: PathLike, resolve: bool, + reference: Union[str, 'SymbolicReference'], + force: bool, logmsg: Union[str, None] = None) -> T_References: """internal method used to create a new symbolic reference. If resolve is False, the reference will be taken as is, creating a proper symbolic reference. Otherwise it will be resolved to the @@ -531,8 +539,9 @@ class SymbolicReference(object): return ref @classmethod - def create(cls, repo: 'Repo', path: PathLike, reference: Union[Commit_ish, str] = 'SymbolicReference', - logmsg: Union[str, None] = None, force: bool = False, **kwargs: Any): + def create(cls: Type[T_References], repo: 'Repo', path: PathLike, + reference: Union[Commit_ish, str, 'SymbolicReference'] = 'SymbolicReference', + logmsg: Union[str, None] = None, force: bool = False, **kwargs: Any) -> T_References: """Create a new symbolic reference, hence a reference pointing , to another reference. :param repo: @@ -669,7 +678,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, path): + def from_path(cls, repo: 'Repo', path: PathLike) -> Union['Head', 'RemoteReference', 'TagReference', 'Reference']: """ :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 diff --git a/git/refs/tag.py b/git/refs/tag.py index 4cbea5ea..ce2a58a0 100644 --- a/git/refs/tag.py +++ b/git/refs/tag.py @@ -4,13 +4,14 @@ __all__ = ["TagReference", "Tag"] # typing ------------------------------------------------------------------ -from typing import Any, Union, TYPE_CHECKING +from typing import Any, Type, Union, TYPE_CHECKING from git.types import Commit_ish, PathLike if TYPE_CHECKING: from git.repo import Repo from git.objects import Commit from git.objects import TagObject + from git.refs import SymbolicReference # ------------------------------------------------------------------------------ @@ -68,7 +69,8 @@ class TagReference(Reference): return Reference._get_object(self) @classmethod - def create(cls, repo: 'Repo', path: PathLike, reference: Union[Commit_ish, str] = 'HEAD', + def create(cls: Type['TagReference'], repo: 'Repo', path: PathLike, + reference: Union[Commit_ish, str, 'SymbolicReference'] = 'HEAD', logmsg: Union[str, None] = None, force: bool = False, **kwargs: Any) -> 'TagReference': """Create a new tag reference. diff --git a/git/repo/base.py b/git/repo/base.py index 12efe9c6..355f9399 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -788,9 +788,10 @@ class Repo(object): return proc.replace("\\\\", "\\").replace('"', "").split("\n") @property - def active_branch(self) -> 'HEAD': + def active_branch(self) -> Head: """The name of the currently active branch. :return: Head to the active branch""" + # reveal_type(self.head.reference) # => Reference return self.head.reference def blame_incremental(self, rev: TBD, file: TBD, **kwargs: Any) -> Optional[Iterator['BlameEntry']]: |