7
7
from unittest import SkipTest
8
8
import uuid
9
9
10
+ from git import IndexFile
11
+
10
12
import git
11
13
from git .cmd import Git
12
14
from git .compat import (
49
51
50
52
51
53
# typing ----------------------------------------------------------------------
52
- from typing import Dict , TYPE_CHECKING
54
+ from typing import Callable , Dict , TYPE_CHECKING
53
55
from typing import Any , Iterator , Union
54
56
55
57
from git .types import Commit_ish , PathLike
@@ -131,14 +133,14 @@ def __init__(self, repo: 'Repo', binsha: bytes,
131
133
if url is not None :
132
134
self ._url = url
133
135
if branch_path is not None :
134
- assert isinstance (branch_path , str )
136
+ # assert isinstance(branch_path, str)
135
137
self ._branch_path = branch_path
136
138
if name is not None :
137
139
self ._name = name
138
140
139
141
def _set_cache_ (self , attr : str ) -> None :
140
142
if attr in ('path' , '_url' , '_branch_path' ):
141
- reader = self .config_reader ()
143
+ reader : SectionConstraint = self .config_reader ()
142
144
# default submodule values
143
145
try :
144
146
self .path = reader .get ('path' )
@@ -807,7 +809,8 @@ def move(self, module_path, configuration=True, module=True):
807
809
return self
808
810
809
811
@unbare_repo
810
- def remove (self , module = True , force = False , configuration = True , dry_run = False ):
812
+ def remove (self , module : bool = True , force : bool = False ,
813
+ configuration : bool = True , dry_run : bool = False ) -> 'Submodule' :
811
814
"""Remove this submodule from the repository. This will remove our entry
812
815
from the .gitmodules file and the entry in the .git / config file.
813
816
@@ -861,7 +864,7 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
861
864
# TODO: If we run into permission problems, we have a highly inconsistent
862
865
# state. Delete the .git folders last, start with the submodules first
863
866
mp = self .abspath
864
- method = None
867
+ method : Union [ None , Callable [[ PathLike ], None ]] = None
865
868
if osp .islink (mp ):
866
869
method = os .remove
867
870
elif osp .isdir (mp ):
@@ -928,7 +931,7 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
928
931
rmtree (git_dir )
929
932
except Exception as ex :
930
933
if HIDE_WINDOWS_KNOWN_ERRORS :
931
- raise SkipTest ("FIXME: fails with: PermissionError\n %s" , ex ) from ex
934
+ raise SkipTest (f "FIXME: fails with: PermissionError\n { ex } " ) from ex
932
935
else :
933
936
raise
934
937
# end handle separate bare repository
@@ -961,7 +964,7 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
961
964
962
965
return self
963
966
964
- def set_parent_commit (self , commit : Union [Commit_ish , None ], check = True ):
967
+ def set_parent_commit (self , commit : Union [Commit_ish , None ], check : bool = True ) -> 'Submodule' :
965
968
"""Set this instance to use the given commit whose tree is supposed to
966
969
contain the .gitmodules blob.
967
970
@@ -1009,7 +1012,7 @@ def set_parent_commit(self, commit: Union[Commit_ish, None], check=True):
10000
1009
1012
return self
1010
1013
1011
1014
@unbare_repo
1012
- def config_writer (self , index = None , write = True ):
1015
+ def config_writer (self , index : Union [ IndexFile , None ] = None , write : bool = True ) -> SectionConstraint :
1013
1016
""":return: a config writer instance allowing you to read and write the data
1014
1017
belonging to this submodule into the .gitmodules file.
1015
1018
@@ -1030,7 +1033,7 @@ def config_writer(self, index=None, write=True):
1030
1033
return writer
1031
1034
1032
1035
@unbare_repo
1033
- def rename (self , new_name ) :
1036
+ def rename (self , new_name : str ) -> 'Submodule' :
1034
1037
"""Rename this submodule
1035
1038
:note: This method takes care of renaming the submodule in various places, such as
1036
1039
@@ -1081,7 +1084,7 @@ def rename(self, new_name):
1081
1084
#{ Query Interface
1082
1085
1083
1086
@unbare_repo
1084
- def module (self ):
1087
+ def module (self ) -> 'Repo' :
1085
1088
""":return: Repo instance initialized from the repository at our submodule path
1086
1089
:raise InvalidGitRepositoryError: if a repository was not available. This could
1087
1090
also mean that it was not yet initialized"""
@@ -1098,7 +1101,7 @@ def module(self):
1098
1101
raise InvalidGitRepositoryError ("Repository at %r was not yet checked out" % module_checkout_abspath )
1099
1102
# END handle exceptions
1100
1103
1101
- def module_exists (self ):
1104
+ def module_exists (self ) -> bool :
1102
1105
""":return: True if our module exists and is a valid git repository. See module() method"""
1103
1106
try :
1104
1107
self .module ()
@@ -1107,7 +1110,7 @@ def module_exists(self):
1107
1110
return False
1108
1111
# END handle exception
1109
1112
1110
- def exists (self ):
1113
+ def exists (self ) -> bool :
1111
1114
"""
1112
1115
:return: True if the submodule exists, False otherwise. Please note that
1113
1116
a submodule may exist ( in the .gitmodules file) even though its module
0 commit comments