@@ -418,7 +418,7 @@ def add(cls, repo: 'Repo', name: str, path: PathLike, url: Union[str, None] = No
418418 # END check url
419419 # END verify urls match
420420
421- # mrepo: Union[Repo, None] = None
421+ mrepo : Union [Repo , None ] = None
422422
423423 if url is None :
424424 if not has_module :
@@ -474,7 +474,8 @@ def add(cls, repo: 'Repo', name: str, path: PathLike, url: Union[str, None] = No
474474 sm ._branch_path = br .path
475475
476476 # we deliberately assume that our head matches our index !
477- sm .binsha = mrepo .head .commit .binsha
477+ if mrepo is not None :
478+ sm .binsha = mrepo .head .commit .binsha
478479 index .add ([sm ], write = True )
479480
480481 return sm
@@ -589,8 +590,8 @@ def update(self, recursive: bool = False, init: bool = True, to_latest_revision:
589590 if not dry_run :
590591 # see whether we have a valid branch to checkout
591592 try :
592- # assert isinstance(mrepo, Repo) # cant do this cos of circular import
593- mrepo = cast ('Repo' , mrepo ) # Try TypeGuard wirh hasattr?
593+ # assert isinstance(mrepo, Repo) # cant do this cos of circular import
594+ mrepo = cast ('Repo' , mrepo ) # Try TypeGuard wirh hasattr, or has_remotes&_head protocol ?
594595 # find a remote which has our branch - we try to be flexible
595596 remote_branch = find_first_remote_branch (mrepo .remotes , self .branch_name )
596597 local_branch = mkhead (mrepo , self .branch_path )
0 commit comments