5
5
from .symbolic import SymbolicReference
6
6
from .reference import Reference
7
7
8
- from typing import Union , TYPE_CHECKING
8
+ # typinng ---------------------------------------------------
9
9
10
- from git .types import Commit_ish
10
+ from typing import Any , Sequence , Union , TYPE_CHECKING
11
+
12
+ from git .types import PathLike , Commit_ish
11
13
12
14
if TYPE_CHECKING :
13
15
from git .repo import Repo
16
+ from git .objects import Commit
17
+ from git .refs import RemoteReference
18
+
19
+ # -------------------------------------------------------------------
14
20
15
21
__all__ = ["HEAD" , "Head" ]
16
22
@@ -29,20 +35,21 @@ class HEAD(SymbolicReference):
29
35
_ORIG_HEAD_NAME = 'ORIG_HEAD'
30
36
__slots__ = ()
31
37
32
- def __init__ (self , repo : 'Repo' , path = _HEAD_NAME ):
38
+ def __init__ (self , repo : 'Repo' , path : PathLike = _HEAD_NAME ):
33
39
if path != self ._HEAD_NAME :
34
40
raise ValueError ("HEAD instance must point to %r, got %r" % (self ._HEAD_NAME , path ))
35
41
super (HEAD , self ).__init__ (repo , path )
36
- self .commit : 'Commit_ish '
42
+ self .commit : 'Commit '
37
43
38
- def orig_head (self ) -> ' SymbolicReference' :
44
+ def orig_head (self ) -> SymbolicReference :
39
45
"""
40
46
:return: SymbolicReference pointing at the ORIG_HEAD, which is maintained
41
47
to contain the previous value of HEAD"""
42
48
return SymbolicReference (self .repo , self ._ORIG_HEAD_NAME )
43
49
44
- def reset (self , commit : Union [Commit_ish , SymbolicReference , str ] = 'HEAD' , index = True , working_tree = False ,
45
- paths = None , ** kwargs ):
50
+ def reset (self , commit : Union [Commit_ish , SymbolicReference , str ] = 'HEAD' ,
51
+ index : bool = True , working_tree : bool = False ,
52
+ paths : Union [PathLike , Sequence [PathLike ], None ] = None , ** kwargs : Any ) -> 'HEAD' :
46
53
"""Reset our HEAD to the given commit optionally synchronizing
47
54
the index and working tree. The reference we refer to will be set to
48
55
commit as well.
@@ -122,7 +129,7 @@ class Head(Reference):
122
129
k_config_remote_ref = "merge" # branch to merge from remote
123
130
124
131
@classmethod
125
- def delete (cls , repo , * heads , ** kwargs ):
132
+ def delete (cls , repo : 'Repo' , * heads : 'Head' , ** kwargs : Any ):
126
133
"""Delete the given heads
127
134
128
135
:param force:
@@ -135,7 +142,7 @@ def delete(cls, repo, *heads, **kwargs):
135
142
flag = "-D"
136
143
repo .git .branch (flag , * heads )
137
144
138
- def set_tracking_branch (self , remote_reference ) :
145
+ def set_tracking_branch (self , remote_reference : 'RemoteReference' ) -> 'Head' :
139
146
"""
140
147
Configure this branch to track the given remote reference. This will alter
141
148
this branch's configuration accordingly.
@@ -160,7 +167,7 @@ def set_tracking_branch(self, remote_reference):
160
167
161
168
return self
162
169
163
- def tracking_branch (self ):
170
+ def tracking_branch (self ) -> Union [ 'RemoteReference' , None ] :
164
171
"""
165
172
:return: The remote_reference we are tracking, or None if we are
166
173
not a tracking branch"""
@@ -175,7 +182,7 @@ def tracking_branch(self):
175
182
# we are not a tracking branch
176
183
return None
177
184
178
- def rename (self , new_path , force = False ):
185
+ def rename (self , new_path : PathLike , force : bool = False ) -> 'Head' :
179
186
"""Rename self to a new path
180
187
181
188
:param new_path:
@@ -196,7 +203,7 @@ def rename(self, new_path, force=False):
196
203
self .path = "%s/%s" % (self ._common_path_default , new_path )
197
204
return self
198
205
199
- def checkout (self , force = False , ** kwargs ):
206
+ def checkout (self , force : bool = False , ** kwargs : Any ):
200
207
"""Checkout this head by setting the HEAD to this reference, by updating the index
201
208
to reflect the tree we point to and by updating the working tree to reflect
202
209
the latest index.
@@ -231,7 +238,7 @@ def checkout(self, force=False, **kwargs):
231
238
return self .repo .active_branch
232
239
233
240
#{ Configuration
234
- def _config_parser (self , read_only ) :
241
+ def _config_parser (self , read_only : bool ) -> SectionConstraint :
235
242
if read_only :
236
243
parser = self .repo .config_reader ()
237
244
else :
@@ -240,13 +247,13 @@ def _config_parser(self, read_only):
240
247
241
248
return SectionConstraint (parser , 'branch "%s"' % self .name )
242
249
243
- def config_reader (self ):
250
+ def config_reader (self ) -> SectionConstraint :
244
251
"""
245
252
:return: A configuration parser instance constrained to only read
246
253
this instance's values"""
247
254
return self ._config_parser (read_only = True )
248
255
249
- def config_writer (self ):
256
+ def config_writer (self ) -> SectionConstraint :
250
257
"""
251
258
:return: A configuration writer instance with read-and write access
252
259
to options of this head"""
0 commit comments