2
2
3
3
__all__ = ["TagReference" , "Tag" ]
4
4
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
+
5
18
6
19
class TagReference (Reference ):
7
20
@@ -22,9 +35,9 @@ class TagReference(Reference):
22
35
_common_path_default = Reference ._common_path_default + "/" + _common_default
23
36
24
37
@property
25
- def commit (self ):
38
+ def commit (self ) -> 'Commit' : # type: ignore[override] # LazyMixin has unrelated
26
39
""":return: Commit object the tag ref points to
27
-
40
+
28
41
:raise ValueError: if the tag points to a tree or blob"""
29
42
obj = self .object
30
43
while obj .type != 'commit' :
@@ -37,7 +50,7 @@ def commit(self):
37
50
return obj
38
51
39
52
@property
40
- def tag (self ):
53
+ def tag (self ) -> Union [ 'TagObject' , None ] :
41
54
"""
42
55
:return: Tag object this tag ref points to or None in case
43
56
we are a light weight tag"""
@@ -48,10 +61,16 @@ def tag(self):
48
61
49
62
# make object read-only
50
63
# 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 )
52
69
53
70
@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' :
55
74
"""Create a new tag reference.
56
75
57
76
:param path:
@@ -62,30 +81,37 @@ def create(cls, repo, path, ref='HEAD', message=None, force=False, **kwargs):
62
81
A reference to the object you want to tag. It can be a commit, tree or
63
82
blob.
64
83
65
- :param message :
84
+ :param logmsg :
66
85
If not None, the message will be used in your tag object. This will also
67
86
create an additional tag object that allows to obtain that information, i.e.::
68
87
69
88
tagref.tag.message
70
89
90
+ :param message:
91
+ Synonym for :param logmsg:
92
+ Included for backwards compatability. :param logmsg is used in preference if both given.
93
+
71
94
:param force:
72
95
If True, to force creation of a tag even though that tag already exists.
73
96
74
97
:param kwargs:
75
98
Additional keyword arguments to be passed to git-tag
76
99
77
100
: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
+
81
107
if force :
82
108
kwargs ['f' ] = True
83
109
84
110
repo .git .tag (* args , ** kwargs )
85
111
return TagReference (repo , "%s/%s" % (cls ._common_path_default , path ))
86
112
87
113
@classmethod
88
- def delete (cls , repo , * tags ) :
114
+ def delete (cls , repo : 'Repo' , * tags : 'TagReference' ) -> None :
89
115
"""Delete the given existing tag or tags"""
90
116
repo .git .tag ("-d" , * tags )
91
117
0 commit comments