diff options
-rw-r--r-- | git/refs/tag.py | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/git/refs/tag.py b/git/refs/tag.py index 4d84239e..aa3b82a2 100644 --- a/git/refs/tag.py +++ b/git/refs/tag.py @@ -2,6 +2,19 @@ from .reference import Reference __all__ = ["TagReference", "Tag"] +# typing ------------------------------------------------------------------ + +from typing import Any, 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 + + +# ------------------------------------------------------------------------------ + class TagReference(Reference): @@ -22,9 +35,9 @@ class TagReference(Reference): _common_path_default = Reference._common_path_default + "/" + _common_default @property - def commit(self): + def commit(self) -> 'Commit': # type: ignore[override] # LazyMixin has unrelated """:return: Commit object the tag ref points to - + :raise ValueError: if the tag points to a tree or blob""" obj = self.object while obj.type != 'commit': @@ -37,7 +50,7 @@ class TagReference(Reference): return obj @property - def tag(self): + def tag(self) -> Union['TagObject', None]: """ :return: Tag object this tag ref points to or None in case we are a light weight tag""" @@ -48,10 +61,16 @@ class TagReference(Reference): # make object read-only # It should be reasonably hard to adjust an existing tag - object = property(Reference._get_object) + + # object = property(Reference._get_object) + @property + def object(self) -> Commit_ish: # type: ignore[override] + return Reference._get_object(self) @classmethod - def create(cls, repo, path, ref='HEAD', message=None, force=False, **kwargs): + def create(cls, repo: 'Repo', path: PathLike, reference: Union[Commit_ish, str] = 'HEAD', + logmsg: Union[str, None] = None, + force: bool = False, **kwargs: Any) -> 'TagReference': """Create a new tag reference. :param path: @@ -62,12 +81,16 @@ class TagReference(Reference): A reference to the object you want to tag. It can be a commit, tree or blob. - :param message: + :param logmsg: If not None, the message will be used in your tag object. This will also create an additional tag object that allows to obtain that information, i.e.:: tagref.tag.message + :param message: + Synonym for :param logmsg: + Included for backwards compatability. :param logmsg is used in preference if both given. + :param force: If True, to force creation of a tag even though that tag already exists. @@ -75,9 +98,12 @@ class TagReference(Reference): Additional keyword arguments to be passed to git-tag :return: A new TagReference""" - args = (path, ref) - if message: - kwargs['m'] = message + args = (path, reference) + if logmsg: + kwargs['m'] = logmsg + elif 'message' in kwargs and kwargs['message']: + kwargs['m'] = kwargs['message'] + if force: kwargs['f'] = True @@ -85,7 +111,7 @@ class TagReference(Reference): return TagReference(repo, "%s/%s" % (cls._common_path_default, path)) @classmethod - def delete(cls, repo, *tags): + def delete(cls, repo: 'Repo', *tags: 'TagReference') -> None: """Delete the given existing tag or tags""" repo.git.tag("-d", *tags) |