22
33__all__ = ["TagReference" ,"Tag" ]
44
5+ # typing ------------------------------------------------------------------
6+
7+ from typing import Any ,Union ,TYPE_CHECKING
8+ from git .types import Commit_ish ,PathLike
9+
10+ if TYPE_CHECKING :
11+ from git .repo import Repo
12+ from git .objects import Commit
13+ from git .objects import TagObject
14+
15+
16+ # ------------------------------------------------------------------------------
17+
518
619class TagReference (Reference ):
720
@@ -22,9 +35,9 @@ class TagReference(Reference):
2235_common_path_default = Reference ._common_path_default + "/" + _common_default
2336
2437@property
25- def commit (self ):
38+ def commit (self )-> 'Commit' : # type: ignore[override] # LazyMixin has unrelated
2639""":return: Commit object the tag ref points to
27-
40+
2841 :raise ValueError: if the tag points to a tree or blob"""
2942obj = self .object
3043while obj .type != 'commit' :
@@ -37,7 +50,7 @@ def commit(self):
3750return obj
3851
3952@property
40- def tag (self ):
53+ def tag (self )-> Union [ 'TagObject' , None ] :
4154"""
4255 :return: Tag object this tag ref points to or None in case
4356 we are a light weight tag"""
@@ -48,10 +61,16 @@ def tag(self):
4861
4962# make object read-only
5063# It should be reasonably hard to adjust an existing tag
51- object = property (Reference ._get_object )
64+
65+ # object = property(Reference._get_object)
66+ @property
67+ def object (self )-> Commit_ish :# type: ignore[override]
68+ return Reference ._get_object (self )
5269
5370@classmethod
54- def create (cls ,repo ,path ,ref = 'HEAD' ,message = None ,force = False ,** kwargs ):
71+ def create (cls ,repo :'Repo' ,path :PathLike ,reference :Union [Commit_ish ,str ]= 'HEAD' ,
72+ logmsg :Union [str ,None ]= None ,
73+ force :bool = False ,** kwargs :Any )-> 'TagReference' :
5574"""Create a new tag reference.
5675
5776 :param path:
@@ -62,30 +81,37 @@ def create(cls, repo, path, ref='HEAD', message=None, force=False, **kwargs):
6281 A reference to the object you want to tag. It can be a commit, tree or
6382 blob.
6483
65- :parammessage :
84+ :paramlogmsg :
6685 If not None, the message will be used in your tag object. This will also
6786 create an additional tag object that allows to obtain that information, i.e.::
6887
6988 tagref.tag.message
7089
90+ :param message:
91+ Synonym for :param logmsg:
92+ Included for backwards compatability. :param logmsg is used in preference if both given.
93+
7194 :param force:
7295 If True, to force creation of a tag even though that tag already exists.
7396
7497 :param kwargs:
7598 Additional keyword arguments to be passed to git-tag
7699
77100 :return: A new TagReference"""
78- args = (path ,ref )
79- if message :
80- kwargs ['m' ]= message
101+ args = (path ,reference )
102+ if logmsg :
103+ kwargs ['m' ]= logmsg
104+ elif 'message' in kwargs and kwargs ['message' ]:
105+ kwargs ['m' ]= kwargs ['message' ]
106+
81107if force :
82108kwargs ['f' ]= True
83109
84110repo .git .tag (* args ,** kwargs )
85111return TagReference (repo ,"%s/%s" % (cls ._common_path_default ,path ))
86112
87113@classmethod
88- def delete (cls ,repo ,* tags ) :
114+ def delete (cls ,repo : 'Repo' ,* tags : 'TagReference' ) -> None :
89115"""Delete the given existing tag or tags"""
90116repo .git .tag ("-d" ,* tags )
91117