Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit94c2ae4

Browse files
committed
Readd submodule.base.py types
1 parent215abfd commit94c2ae4

File tree

2 files changed

+54
-39
lines changed

2 files changed

+54
-39
lines changed

‎git/diff.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828

2929

3030
defis_change_type(inp:str)->TypeGuard[Lit_change_type]:
31-
returninpin ['A','D','C','M','R','T']
31+
returnTrue
32+
# return inp in ['A', 'D', 'C', 'M', 'R', 'T']
3233

3334
# ------------------------------------------------------------------------
3435

@@ -511,7 +512,7 @@ def _handle_diff_line(lines_bytes: bytes, repo: 'Repo', index: DiffIndex) -> Non
511512
# Change type can be R100
512513
# R: status letter
513514
# 100: score (in case of copy and rename)
514-
assertis_change_type(_change_type[0])
515+
assertis_change_type(_change_type[0]),f"Unexpected value for change_type received:{_change_type[0]}"
515516
change_type:Lit_change_type=_change_type[0]
516517
score_str=''.join(_change_type[1:])
517518
score=int(score_str)ifscore_str.isdigit()elseNone

‎git/objects/submodule/base.py‎

Lines changed: 51 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,16 @@
4747
find_first_remote_branch
4848
)
4949

50+
fromgit.repoimportRepo
5051

5152
# typing ----------------------------------------------------------------------
52-
fromtypingimportDict,TYPE_CHECKING
53+
fromtypingimportCallable,Dict,Mapping,Sequence,TYPE_CHECKING
5354
fromtypingimportAny,Iterator,Union
5455

55-
fromgit.typesimportCommit_ish,PathLike
56+
fromgit.typesimportCommit_ish,PathLike,TBD
5657

5758
ifTYPE_CHECKING:
58-
fromgit.repoimportRepo
59+
fromgit.indeximportIndexFile
5960

6061

6162
# -----------------------------------------------------------------------------
@@ -131,14 +132,14 @@ def __init__(self, repo: 'Repo', binsha: bytes,
131132
ifurlisnotNone:
132133
self._url=url
133134
ifbranch_pathisnotNone:
134-
assertisinstance(branch_path,str)
135+
#assert isinstance(branch_path, str)
135136
self._branch_path=branch_path
136137
ifnameisnotNone:
137138
self._name=name
138139

139140
def_set_cache_(self,attr:str)->None:
140141
ifattrin ('path','_url','_branch_path'):
141-
reader=self.config_reader()
142+
reader:SectionConstraint=self.config_reader()
142143
# default submodule values
143144
try:
144145
self.path=reader.get('path')
@@ -226,7 +227,7 @@ def _config_parser(cls, repo: 'Repo',
226227

227228
returnSubmoduleConfigParser(fp_module,read_only=read_only)
228229

229-
def_clear_cache(self):
230+
def_clear_cache(self)->None:
230231
# clear the possibly changed values
231232
fornameinself._cache_attrs:
232233
try:
@@ -246,7 +247,7 @@ def _sio_modules(cls, parent_commit: Commit_ish) -> BytesIO:
246247
def_config_parser_constrained(self,read_only:bool)->SectionConstraint:
247248
""":return: Config Parser constrained to our submodule in read or write mode"""
248249
try:
249-
pc=self.parent_commit
250+
pc:Union['Commit_ish',None]=self.parent_commit
250251
exceptValueError:
251252
pc=None
252253
# end handle empty parent repository
@@ -255,10 +256,12 @@ def _config_parser_constrained(self, read_only: bool) -> SectionConstraint:
255256
returnSectionConstraint(parser,sm_section(self.name))
256257

257258
@classmethod
258-
def_module_abspath(cls,parent_repo,path,name):
259+
def_module_abspath(cls,parent_repo:'Repo',path:PathLike,name:str)->PathLike:
259260
ifcls._need_gitfile_submodules(parent_repo.git):
260261
returnosp.join(parent_repo.git_dir,'modules',name)
261-
returnosp.join(parent_repo.working_tree_dir,path)
262+
ifparent_repo.working_tree_dir:
263+
returnosp.join(parent_repo.working_tree_dir,path)
264+
raiseNotADirectoryError()
262265
# end
263266

264267
@classmethod
@@ -286,15 +289,15 @@ def _clone_repo(cls, repo, url, path, name, **kwargs):
286289
returnclone
287290

288291
@classmethod
289-
def_to_relative_path(cls,parent_repo,path):
292+
def_to_relative_path(cls,parent_repo:'Repo',path:PathLike)->PathLike:
290293
""":return: a path guaranteed to be relative to the given parent - repository
291294
:raise ValueError: if path is not contained in the parent repository's working tree"""
292295
path=to_native_path_linux(path)
293296
ifpath.endswith('/'):
294297
path=path[:-1]
295298
# END handle trailing slash
296299

297-
ifosp.isabs(path):
300+
ifosp.isabs(path)andparent_repo.working_tree_dir:
298301
working_tree_linux=to_native_path_linux(parent_repo.working_tree_dir)
299302
ifnotpath.startswith(working_tree_linux):
300303
raiseValueError("Submodule checkout path '%s' needs to be within the parents repository at '%s'"
@@ -308,7 +311,7 @@ def _to_relative_path(cls, parent_repo, path):
308311
returnpath
309312

310313
@classmethod
311-
def_write_git_file_and_module_config(cls,working_tree_dir,module_abspath):
314+
def_write_git_file_and_module_config(cls,working_tree_dir:PathLike,module_abspath:PathLike)->None:
312315
"""Writes a .git file containing a(preferably) relative path to the actual git module repository.
313316
It is an error if the module_abspath cannot be made into a relative path, relative to the working_tree_dir
314317
:note: will overwrite existing files !
@@ -335,7 +338,8 @@ def _write_git_file_and_module_config(cls, working_tree_dir, module_abspath):
335338

336339
@classmethod
337340
defadd(cls,repo:'Repo',name:str,path:PathLike,url:Union[str,None]=None,
338-
branch=None,no_checkout:bool=False,depth=None,env=None,clone_multi_options=None
341+
branch:Union[str,None]=None,no_checkout:bool=False,depth:Union[int,None]=None,
342+
env:Mapping[str,str]=None,clone_multi_options:Union[Sequence[TBD],None]=None
339343
)->'Submodule':
340344
"""Add a new submodule to the given repository. This will alter the index
341345
as well as the .gitmodules file, but will not create a new commit.
@@ -391,7 +395,7 @@ def add(cls, repo: 'Repo', name: str, path: PathLike, url: Union[str, None] = No
391395
ifsm.exists():
392396
# reretrieve submodule from tree
393397
try:
394-
sm=repo.head.commit.tree[path]# type: ignore
398+
sm=repo.head.commit.tree[str(path)]
395399
sm._name=name
396400
returnsm
397401
exceptKeyError:
@@ -414,7 +418,8 @@ def add(cls, repo: 'Repo', name: str, path: PathLike, url: Union[str, None] = No
414418
# END check url
415419
# END verify urls match
416420

417-
mrepo=None
421+
mrepo:Union[Repo,None]=None
422+
418423
ifurlisNone:
419424
ifnothas_module:
420425
raiseValueError("A URL was not given and a repository did not exist at %s"%path)
@@ -427,7 +432,7 @@ def add(cls, repo: 'Repo', name: str, path: PathLike, url: Union[str, None] = No
427432
url=urls[0]
428433
else:
429434
# clone new repo
430-
kwargs:Dict[str,Union[bool,int]]= {'n':no_checkout}
435+
kwargs:Dict[str,Union[bool,int,Sequence[TBD]]]= {'n':no_checkout}
431436
ifnotbranch_is_default:
432437
kwargs['b']=br.name
433438
# END setup checkout-branch
@@ -451,6 +456,8 @@ def add(cls, repo: 'Repo', name: str, path: PathLike, url: Union[str, None] = No
451456
# otherwise there is a '-' character in front of the submodule listing
452457
# a38efa84daef914e4de58d1905a500d8d14aaf45 mymodule (v0.9.0-1-ga38efa8)
453458
# -a38efa84daef914e4de58d1905a500d8d14aaf45 submodules/intermediate/one
459+
writer:Union[GitConfigParser,SectionConstraint]
460+
454461
withsm.repo.config_writer()aswriter:
455462
writer.set_value(sm_section(name),'url',url)
456463

@@ -467,13 +474,15 @@ def add(cls, repo: 'Repo', name: str, path: PathLike, url: Union[str, None] = No
467474
sm._branch_path=br.path
468475

469476
# we deliberately assume that our head matches our index !
470-
sm.binsha=mrepo.head.commit.binsha
477+
sm.binsha=mrepo.head.commit.binsha# type: ignore
471478
index.add([sm],write=True)
472479

473480
returnsm
474481

475-
defupdate(self,recursive=False,init=True,to_latest_revision=False,progress=None,dry_run=False,
476-
force=False,keep_going=False,env=None,clone_multi_options=None):
482+
defupdate(self,recursive:bool=False,init:bool=True,to_latest_revision:bool=False,
483+
progress:Union['UpdateProgress',None]=None,dry_run:bool=False,
484+
force:bool=False,keep_going:bool=False,env:Mapping[str,str]=None,
485+
clone_multi_options:Union[Sequence[TBD],None]=None):
477486
"""Update the repository of this submodule to point to the checkout
478487
we point at with the binsha of this instance.
479488
@@ -580,6 +589,7 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress=
580589
ifnotdry_run:
581590
# see whether we have a valid branch to checkout
582591
try:
592+
assertisinstance(mrepo,Repo)
583593
# find a remote which has our branch - we try to be flexible
584594
remote_branch=find_first_remote_branch(mrepo.remotes,self.branch_name)
585595
local_branch=mkhead(mrepo,self.branch_path)
@@ -640,7 +650,7 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress=
640650
may_reset=True
641651
ifmrepo.head.commit.binsha!=self.NULL_BIN_SHA:
642652
base_commit=mrepo.merge_base(mrepo.head.commit,hexsha)
643-
iflen(base_commit)==0orbase_commit[0].hexsha==hexsha:
653+
iflen(base_commit)==0or(base_commit[0]isnotNoneandbase_commit[0].hexsha==hexsha):
644654
ifforce:
645655
msg="Will force checkout or reset on local branch that is possibly in the future of"
646656
msg+="the commit it will be checked out to, effectively 'forgetting' new commits"
@@ -807,7 +817,8 @@ def move(self, module_path, configuration=True, module=True):
807817
returnself
808818

809819
@unbare_repo
810-
defremove(self,module=True,force=False,configuration=True,dry_run=False):
820+
defremove(self,module:bool=True,force:bool=False,
821+
configuration:bool=True,dry_run:bool=False)->'Submodule':
811822
"""Remove this submodule from the repository. This will remove our entry
812823
from the .gitmodules file and the entry in the .git / config file.
813824
@@ -861,7 +872,7 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
861872
# TODO: If we run into permission problems, we have a highly inconsistent
862873
# state. Delete the .git folders last, start with the submodules first
863874
mp=self.abspath
864-
method=None
875+
method:Union[None,Callable[[PathLike],None]]=None
865876
ifosp.islink(mp):
866877
method=os.remove
867878
elifosp.isdir(mp):
@@ -914,7 +925,7 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
914925
importgc
915926
gc.collect()
916927
try:
917-
rmtree(wtd)
928+
rmtree(str(wtd))
918929
exceptExceptionasex:
919930
ifHIDE_WINDOWS_KNOWN_ERRORS:
920931
raiseSkipTest("FIXME: fails with: PermissionError\n {}".format(ex))fromex
@@ -928,7 +939,7 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
928939
rmtree(git_dir)
929940
exceptExceptionasex:
930941
ifHIDE_WINDOWS_KNOWN_ERRORS:
931-
raiseSkipTest("FIXME: fails with: PermissionError\n%s",ex)fromex
942+
raiseSkipTest(f"FIXME: fails with: PermissionError\n{ex}")fromex
932943
else:
933944
raise
934945
# end handle separate bare repository
@@ -952,6 +963,8 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
952963

953964
# now git config - need the config intact, otherwise we can't query
954965
# information anymore
966+
writer:Union[GitConfigParser,SectionConstraint]
967+
955968
withself.repo.config_writer()aswriter:
956969
writer.remove_section(sm_section(self.name))
957970

@@ -961,7 +974,7 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
961974

962975
returnself
963976

964-
defset_parent_commit(self,commit:Union[Commit_ish,None],check=True):
977+
defset_parent_commit(self,commit:Union[Commit_ish,None],check:bool=True)->'Submodule':
965978
"""Set this instance to use the given commit whose tree is supposed to
966979
contain the .gitmodules blob.
967980
@@ -1009,7 +1022,7 @@ def set_parent_commit(self, commit: Union[Commit_ish, None], check=True):
10091022
returnself
10101023

10111024
@unbare_repo
1012-
defconfig_writer(self,index=None,write=True):
1025+
defconfig_writer(self,index:Union['IndexFile',None]=None,write:bool=True)->SectionConstraint:
10131026
""":return: a config writer instance allowing you to read and write the data
10141027
belonging to this submodule into the .gitmodules file.
10151028
@@ -1030,7 +1043,7 @@ def config_writer(self, index=None, write=True):
10301043
returnwriter
10311044

10321045
@unbare_repo
1033-
defrename(self,new_name):
1046+
defrename(self,new_name:str)->'Submodule':
10341047
"""Rename this submodule
10351048
:note: This method takes care of renaming the submodule in various places, such as
10361049
@@ -1065,13 +1078,14 @@ def rename(self, new_name):
10651078
destination_module_abspath=self._module_abspath(self.repo,self.path,new_name)
10661079
source_dir=mod.git_dir
10671080
# Let's be sure the submodule name is not so obviously tied to a directory
1068-
ifdestination_module_abspath.startswith(mod.git_dir):
1081+
ifstr(destination_module_abspath).startswith(str(mod.git_dir)):
10691082
tmp_dir=self._module_abspath(self.repo,self.path,str(uuid.uuid4()))
10701083
os.renames(source_dir,tmp_dir)
10711084
source_dir=tmp_dir
10721085
# end handle self-containment
10731086
os.renames(source_dir,destination_module_abspath)
1074-
self._write_git_file_and_module_config(mod.working_tree_dir,destination_module_abspath)
1087+
ifmod.working_tree_dir:
1088+
self._write_git_file_and_module_config(mod.working_tree_dir,destination_module_abspath)
10751089
# end move separate git repository
10761090

10771091
returnself
@@ -1081,7 +1095,7 @@ def rename(self, new_name):
10811095
#{ Query Interface
10821096

10831097
@unbare_repo
1084-
defmodule(self):
1098+
defmodule(self)->'Repo':
10851099
""":return: Repo instance initialized from the repository at our submodule path
10861100
:raise InvalidGitRepositoryError: if a repository was not available. This could
10871101
also mean that it was not yet initialized"""
@@ -1098,7 +1112,7 @@ def module(self):
10981112
raiseInvalidGitRepositoryError("Repository at %r was not yet checked out"%module_checkout_abspath)
10991113
# END handle exceptions
11001114

1101-
defmodule_exists(self):
1115+
defmodule_exists(self)->bool:
11021116
""":return: True if our module exists and is a valid git repository. See module() method"""
11031117
try:
11041118
self.module()
@@ -1107,7 +1121,7 @@ def module_exists(self):
11071121
returnFalse
11081122
# END handle exception
11091123

1110-
defexists(self):
1124+
defexists(self)->bool:
11111125
"""
11121126
:return: True if the submodule exists, False otherwise. Please note that
11131127
a submodule may exist ( in the .gitmodules file) even though its module
@@ -1148,34 +1162,34 @@ def branch(self):
11481162
returnmkhead(self.module(),self._branch_path)
11491163

11501164
@property
1151-
defbranch_path(self):
1165+
defbranch_path(self)->PathLike:
11521166
"""
11531167
:return: full(relative) path as string to the branch we would checkout
11541168
from the remote and track"""
11551169
returnself._branch_path
11561170

11571171
@property
1158-
defbranch_name(self):
1172+
defbranch_name(self)->str:
11591173
""":return: the name of the branch, which is the shortest possible branch name"""
11601174
# use an instance method, for this we create a temporary Head instance
11611175
# which uses a repository that is available at least ( it makes no difference )
11621176
returngit.Head(self.repo,self._branch_path).name
11631177

11641178
@property
1165-
defurl(self):
1179+
defurl(self)->str:
11661180
""":return: The url to the repository which our module - repository refers to"""
11671181
returnself._url
11681182

11691183
@property
1170-
defparent_commit(self):
1184+
defparent_commit(self)->'Commit_ish':
11711185
""":return: Commit instance with the tree containing the .gitmodules file
11721186
:note: will always point to the current head's commit if it was not set explicitly"""
11731187
ifself._parent_commitisNone:
11741188
returnself.repo.commit()
11751189
returnself._parent_commit
11761190

11771191
@property
1178-
defname(self):
1192+
defname(self)->str:
11791193
""":return: The name of this submodule. It is used to identify it within the
11801194
.gitmodules file.
11811195
:note: by default, the name is the path at which to find the submodule, but

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp