36
36
37
37
# typing-------------------------------------------------------
38
38
39
- from typing import Any ,Callable ,Dict ,Iterator ,List ,Optional ,Sequence ,TYPE_CHECKING ,Union ,overload
39
+ from typing import (Any ,Callable ,Dict ,Iterator ,List ,NoReturn ,Optional ,Sequence ,# NOQA[TC002]
40
+ TYPE_CHECKING ,Type ,Union ,overload )
40
41
41
- from git .types import PathLike ,Literal ,TBD ,TypeGuard ,Commit_ish
42
+ from git .types import PathLike ,Literal ,TBD ,TypeGuard ,Commit_ish # NOQA[TC002]
42
43
43
44
if TYPE_CHECKING :
44
45
from git .repo .base import Repo
@@ -83,17 +84,17 @@ def add_progress(kwargs: Any, git: Git,
83
84
#} END utilities
84
85
85
86
86
- @overload
87
+ @overload
87
88
def to_progress_instance (progress :None )-> RemoteProgress :
88
89
...
89
90
90
91
91
- @overload
92
+ @overload
92
93
def to_progress_instance (progress :Callable [...,Any ])-> CallableRemoteProgress :
93
94
...
94
95
95
96
96
- @overload
97
+ @overload
97
98
def to_progress_instance (progress :RemoteProgress )-> RemoteProgress :
98
99
...
99
100
@@ -155,11 +156,11 @@ def __init__(self, flags: int, local_ref: Union[SymbolicReference, None], remote
155
156
self ._old_commit_sha = old_commit
156
157
self .summary = summary
157
158
158
- @property
159
- def old_commit (self )-> Union [str ,SymbolicReference ,' Commit_ish' ,None ]:
159
+ @property
160
+ def old_commit (self )-> Union [str ,SymbolicReference ,Commit_ish ,None ]:
160
161
return self ._old_commit_sha and self ._remote .repo .commit (self ._old_commit_sha )or None
161
162
162
- @property
163
+ @property
163
164
def remote_ref (self )-> Union [RemoteReference ,TagReference ]:
164
165
"""
165
166
:return:
@@ -175,7 +176,7 @@ def remote_ref(self) -> Union[RemoteReference, TagReference]:
175
176
raise ValueError ("Could not handle remote ref: %r" % self .remote_ref_string )
176
177
# END
177
178
178
- @classmethod
179
+ @classmethod
179
180
def _from_line (cls ,remote :'Remote' ,line :str )-> 'PushInfo' :
180
181
"""Create a new PushInfo instance as parsed from line which is expected to be like
181
182
refs/heads/master:refs/heads/master 05d2687..1d0568e as bytes"""
@@ -228,6 +229,11 @@ def _from_line(cls, remote: 'Remote', line: str) -> 'PushInfo':
228
229
229
230
return PushInfo (flags ,from_ref ,to_ref_string ,remote ,old_commit ,summary )
230
231
232
+ @classmethod
233
+ def iter_items (cls ,repo :'Repo' ,* args :Any ,** kwargs :Any
234
+ )-> NoReturn :# -> Iterator['PushInfo']:
235
+ raise NotImplementedError
236
+
231
237
232
238
class FetchInfo (IterableObj ,object ):
233
239
@@ -262,7 +268,7 @@ class FetchInfo(IterableObj, object):
262
268
'-' :TAG_UPDATE ,
263
269
}# type: Dict[flagKeyLiteral, int]
264
270
265
- @classmethod
271
+ @classmethod
266
272
def refresh (cls )-> Literal [True ]:
267
273
"""This gets called by the refresh function (see the top level
268
274
__init__).
@@ -301,25 +307,25 @@ def __init__(self, ref: SymbolicReference, flags: int, note: str = '',
301
307
def __str__ (self )-> str :
302
308
return self .name
303
309
304
- @property
310
+ @property
305
311
def name (self )-> str :
306
312
""":return: Name of our remote ref"""
307
313
return self .ref .name
308
314
309
- @property
315
+ @property
310
316
def commit (self )-> Commit_ish :
311
317
""":return: Commit of our remote ref"""
312
318
return self .ref .commit
313
319
314
- @classmethod
320
+ @classmethod
315
321
def _from_line (cls ,repo :'Repo' ,line :str ,fetch_line :str )-> 'FetchInfo' :
316
322
"""Parse information from the given line as returned by git-fetch -v
317
323
and return a new FetchInfo object representing this information.
318
324
319
- We can handle a line as follows
320
- "%c %-*s %-*s -> %s%s"
325
+ We can handle a line as follows:
326
+ "%c %-\\ *s %-\\ *s -> %s%s"
321
327
322
- Where c is either ' ', !, +, -, *, or =
328
+ Where c is either ' ', !, +, -,\\ *, or =
323
329
! means error
324
330
+ means success forcing update
325
331
- means a tag was updated
@@ -334,6 +340,7 @@ def _from_line(cls, repo: 'Repo', line: str, fetch_line: str) -> 'FetchInfo':
334
340
raise ValueError ("Failed to parse line: %r" % line )
335
341
336
342
# parse lines
343
+ remote_local_ref_str :str
337
344
control_character ,operation ,local_remote_ref ,remote_local_ref_str ,note = match .groups ()
338
345
assert is_flagKeyLiteral (control_character ),f"{ control_character } "
339
346
@@ -375,7 +382,7 @@ def _from_line(cls, repo: 'Repo', line: str, fetch_line: str) -> 'FetchInfo':
375
382
# If we do not specify a target branch like master:refs/remotes/origin/master,
376
383
# the fetch result is stored in FETCH_HEAD which destroys the rule we usually
377
384
# have. In that case we use a symbolic reference which is detached
378
- ref_type = None
385
+ ref_type : Optional [ Type [ SymbolicReference ]] = None
379
386
if remote_local_ref_str == "FETCH_HEAD" :
380
387
ref_type = SymbolicReference
381
388
elif ref_type_name == "tag" or is_tag_operation :
@@ -404,14 +411,15 @@ def _from_line(cls, repo: 'Repo', line: str, fetch_line: str) -> 'FetchInfo':
404
411
# by the 'ref/' prefix. Otherwise even a tag could be in refs/remotes, which is when it will have the
405
412
# 'tags/' subdirectory in its path.
406
413
# We don't want to test for actual existence, but try to figure everything out analytically.
407
- ref_path = None # type : Optional[PathLike]
414
+ ref_path :Optional [PathLike ]= None
408
415
remote_local_ref_str = remote_local_ref_str .strip ()
416
+
409
417
if remote_local_ref_str .startswith (Reference ._common_path_default + "/" ):
410
418
# always use actual type if we get absolute paths
411
419
# Will always be the case if something is fetched outside of refs/remotes (if its not a tag)
412
420
ref_path = remote_local_ref_str
413
421
if ref_type is not TagReference and not \
414
- remote_local_ref_str .startswith (RemoteReference ._common_path_default + "/" ):
422
+ remote_local_ref_str .startswith (RemoteReference ._common_path_default + "/" ):
415
423
ref_type = Reference
416
424
# END downgrade remote reference
417
425
elif ref_type is TagReference and 'tags/' in remote_local_ref_str :
@@ -430,6 +438,11 @@ def _from_line(cls, repo: 'Repo', line: str, fetch_line: str) -> 'FetchInfo':
430
438
431
439
return cls (remote_local_ref ,flags ,note ,old_commit ,local_remote_ref )
432
440
441
+ @classmethod
442
+ def iter_items (cls ,repo :'Repo' ,* args :Any ,** kwargs :Any
443
+ )-> NoReturn :# -> Iterator['FetchInfo']:
444
+ raise NotImplementedError
445
+
433
446
434
447
class Remote (LazyMixin ,IterableObj ):
435
448
@@ -507,7 +520,7 @@ def exists(self) -> bool:
507
520
return False
508
521
# end
509
522
510
- @classmethod
523
+ @classmethod
511
524
def iter_items (cls ,repo :'Repo' ,* args :Any ,** kwargs :Any )-> Iterator ['Remote' ]:
512
525
""":return: Iterator yielding Remote objects of the given repository"""
513
526
for section in repo .config_reader ("repository" ).sections ():
@@ -897,7 +910,7 @@ def push(self, refspec: Union[str, List[str], None] = None,
897
910
universal_newlines = True ,** kwargs )
898
911
return self ._get_push_info (proc ,progress )
899
912
900
- @property
913
+ @property
901
914
def config_reader (self )-> SectionConstraint :
902
915
"""
903
916
:return:
@@ -912,7 +925,7 @@ def _clear_cache(self) -> None:
912
925
pass
913
926
# END handle exception
914
927
915
- @property
928
+ @property
916
929
def config_writer (self )-> SectionConstraint :
917
930
"""
918
931
:return: GitConfigParser compatible object able to write options for this remote.