44
55# typing ------------------------------------------------------------------
66
7- from typing import Any , Union , TYPE_CHECKING
7+ from typing import Any , Type , Union , TYPE_CHECKING
88from git .types import Commit_ish , PathLike
99
1010if TYPE_CHECKING :
1111 from git .repo import Repo
1212 from git .objects import Commit
1313 from git .objects import TagObject
14+ from git .refs import SymbolicReference
1415
1516
1617# ------------------------------------------------------------------------------
@@ -68,7 +69,8 @@ def object(self) -> Commit_ish: # type: ignore[override]
6869 return Reference ._get_object (self )
6970
7071 @classmethod
71- def create (cls , repo : 'Repo' , path : PathLike , reference : Union [Commit_ish , str ] = 'HEAD' ,
72+ def create (cls : Type ['TagReference' ], repo : 'Repo' , path : PathLike ,
73+ reference : Union [str , 'SymbolicReference' ] = 'HEAD' ,
7274 logmsg : Union [str , None ] = None ,
7375 force : bool = False , ** kwargs : Any ) -> 'TagReference' :
7476 """Create a new tag reference.
@@ -78,7 +80,7 @@ def create(cls, repo: 'Repo', path: PathLike, reference: Union[Commit_ish, str]
7880 The prefix refs/tags is implied
7981
8082 :param ref:
81- A reference to the object you want to tag. It can be a commit, tree or
83+ A reference to the Object you want to tag. The Object can be a commit, tree or
8284 blob.
8385
8486 :param logmsg:
@@ -98,7 +100,9 @@ def create(cls, repo: 'Repo', path: PathLike, reference: Union[Commit_ish, str]
98100 Additional keyword arguments to be passed to git-tag
99101
100102 :return: A new TagReference"""
101- args = (path , reference )
103+ if 'ref' in kwargs and kwargs ['ref' ]:
104+ reference = kwargs ['ref' ]
105+
102106 if logmsg :
103107 kwargs ['m' ] = logmsg
104108 elif 'message' in kwargs and kwargs ['message' ]:
@@ -107,11 +111,13 @@ def create(cls, repo: 'Repo', path: PathLike, reference: Union[Commit_ish, str]
107111 if force :
108112 kwargs ['f' ] = True
109113
114+ args = (path , reference )
115+
110116 repo .git .tag (* args , ** kwargs )
111117 return TagReference (repo , "%s/%s" % (cls ._common_path_default , path ))
112118
113119 @classmethod
114- def delete (cls , repo : 'Repo' , * tags : 'TagReference' ) -> None :
120+ def delete (cls , repo : 'Repo' , * tags : 'TagReference' ) -> None : # type: ignore[override]
115121 """Delete the given existing tag or tags"""
116122 repo .git .tag ("-d" , * tags )
117123
0 commit comments