2
2
3
3
from git .util import join_path
4
4
5
- import os .path as osp
6
-
7
5
from .head import Head
8
6
9
7
10
8
__all__ = ["RemoteReference" ]
11
9
10
+ # typing ------------------------------------------------------------------
11
+
12
+ from typing import Any , NoReturn , Union , TYPE_CHECKING
13
+ from git .types import PathLike
14
+
15
+
16
+ if TYPE_CHECKING :
17
+ from git .repo import Repo
18
+ from git import Remote
19
+
20
+ # ------------------------------------------------------------------------------
21
+
12
22
13
23
class RemoteReference (Head ):
14
24
15
25
"""Represents a reference pointing to a remote head."""
16
26
_common_path_default = Head ._remote_common_path_default
17
27
18
28
@classmethod
19
- def iter_items (cls , repo , common_path = None , remote = None ):
29
+ def iter_items (cls , repo : 'Repo' , common_path : Union [PathLike , None ] = None ,
30
+ remote : Union ['Remote' , None ] = None , * args : Any , ** kwargs : Any
31
+ ) -> 'RemoteReference' :
20
32
"""Iterate remote references, and if given, constrain them to the given remote"""
21
33
common_path = common_path or cls ._common_path_default
22
34
if remote is not None :
23
35
common_path = join_path (common_path , str (remote ))
24
36
# END handle remote constraint
37
+ # super is Reference
25
38
return super (RemoteReference , cls ).iter_items (repo , common_path )
26
39
27
- @classmethod
28
- def delete (cls , repo , * refs , ** kwargs ) :
40
+ @ classmethod
41
+ def delete (cls , repo : 'Repo' , * refs : 'RemoteReference' , ** kwargs : Any ) -> None :
29
42
"""Delete the given remote references
30
43
31
44
:note:
@@ -37,16 +50,16 @@ def delete(cls, repo, *refs, **kwargs):
37
50
# and delete remainders manually
38
51
for ref in refs :
39
52
try :
40
- os .remove (osp .join (repo .common_dir , ref .path ))
53
+ os .remove (os . path .join (repo .common_dir , ref .path ))
41
54
except OSError :
42
55
pass
43
56
try :
44
- os .remove (osp .join (repo .git_dir , ref .path ))
57
+ os .remove (os . path .join (repo .git_dir , ref .path ))
45
58
except OSError :
46
59
pass
47
60
# END for each ref
48
61
49
- @classmethod
50
- def create (cls , * args , ** kwargs ) :
62
+ @ classmethod
63
+ def create (cls , * args : Any , ** kwargs : Any ) -> NoReturn :
51
64
"""Used to disable this method"""
52
65
raise TypeError ("Cannot explicitly create remote references" )
0 commit comments