summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--git/diff.py2
-rw-r--r--git/objects/submodule/base.py12
-rw-r--r--git/repo/base.py2
-rw-r--r--git/types.py10
4 files changed, 17 insertions, 9 deletions
diff --git a/git/diff.py b/git/diff.py
index 611194a8..c5e231b2 100644
--- a/git/diff.py
+++ b/git/diff.py
@@ -512,7 +512,7 @@ class Diff(object):
# R: status letter
# 100: score (in case of copy and rename)
- assert is_change_type(_change_type[0])
+ assert is_change_type(_change_type[0]), "Unexpected _change_type recieved in Diff"
change_type: Lit_change_type = _change_type[0]
score_str = ''.join(_change_type[1:])
score = int(score_str) if score_str.isdigit() else None
diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py
index 53e89dba..3df2b41a 100644
--- a/git/objects/submodule/base.py
+++ b/git/objects/submodule/base.py
@@ -474,8 +474,8 @@ class Submodule(IndexObject, TraversableIterableObj):
sm._branch_path = br.path
# we deliberately assume that our head matches our index !
- if mrepo is not None:
- sm.binsha = mrepo.head.commit.binsha
+ mrepo = cast('Repo', mrepo)
+ sm.binsha = mrepo.head.commit.binsha
index.add([sm], write=True)
return sm
@@ -652,7 +652,7 @@ class Submodule(IndexObject, TraversableIterableObj):
may_reset = True
if mrepo.head.commit.binsha != self.NULL_BIN_SHA:
base_commit = mrepo.merge_base(mrepo.head.commit, hexsha)
- if len(base_commit) == 0 or (base_commit[0] is not None and base_commit[0].hexsha == hexsha):
+ if len(base_commit) == 0 or base_commit[0].hexsha == hexsha: # type: ignore
if force:
msg = "Will force checkout or reset on local branch that is possibly in the future of"
msg += "the commit it will be checked out to, effectively 'forgetting' new commits"
@@ -927,7 +927,7 @@ class Submodule(IndexObject, TraversableIterableObj):
import gc
gc.collect()
try:
- rmtree(str(wtd))
+ rmtree(wtd) # type: ignore ## str()?
except Exception as ex:
if HIDE_WINDOWS_KNOWN_ERRORS:
raise SkipTest("FIXME: fails with: PermissionError\n {}".format(ex)) from ex
@@ -1015,7 +1015,7 @@ class Submodule(IndexObject, TraversableIterableObj):
# If check is False, we might see a parent-commit that doesn't even contain the submodule anymore.
# in that case, mark our sha as being NULL
try:
- self.binsha = pctree[str(self.path)].binsha
+ self.binsha = pctree[self.path].binsha # type: ignore # str()?
except KeyError:
self.binsha = self.NULL_BIN_SHA
# end
@@ -1080,7 +1080,7 @@ class Submodule(IndexObject, TraversableIterableObj):
destination_module_abspath = self._module_abspath(self.repo, self.path, new_name)
source_dir = mod.git_dir
# Let's be sure the submodule name is not so obviously tied to a directory
- if str(destination_module_abspath).startswith(str(mod.git_dir)):
+ if destination_module_abspath.startswith(str(mod.git_dir)): # type: ignore # str()?
tmp_dir = self._module_abspath(self.repo, self.path, str(uuid.uuid4()))
os.renames(source_dir, tmp_dir)
source_dir = tmp_dir
diff --git a/git/repo/base.py b/git/repo/base.py
index ea86139b..a6f91aee 100644
--- a/git/repo/base.py
+++ b/git/repo/base.py
@@ -1016,7 +1016,7 @@ class Repo(object):
@classmethod
def _clone(cls, git: 'Git', url: PathLike, path: PathLike, odb_default_type: Type[GitCmdObjectDB],
- progress: Union['RemoteProgress', 'UpdateProgress', Callable[..., 'RemoteProgress'], None],
+ progress: Union['RemoteProgress', 'UpdateProgress', Callable[..., 'RemoteProgress'], None] = None,
multi_options: Optional[List[str]] = None, **kwargs: Any
) -> 'Repo':
odbt = kwargs.pop('odbt', odb_default_type)
diff --git a/git/types.py b/git/types.py
index 36ebbb31..0e085075 100644
--- a/git/types.py
+++ b/git/types.py
@@ -5,7 +5,7 @@
import os
import sys
from typing import (Callable, Dict, NoReturn, Tuple, Union, Any, Iterator, # noqa: F401
- NamedTuple, TYPE_CHECKING, TypeVar) # noqa: F401
+ NamedTuple, TYPE_CHECKING, TypeVar, runtime_checkable) # noqa: F401
if sys.version_info[:2] >= (3, 8):
@@ -78,3 +78,11 @@ class Total_TD(TypedDict):
class HSH_TD(TypedDict):
total: Total_TD
files: Dict[PathLike, Files_TD]
+
+
+@runtime_checkable
+class RepoLike(Protocol):
+ """Protocol class to allow structural type-checking of Repo
+ e.g. when cannot import due to circular imports"""
+
+ def remotes(self): ... # NOQA: E704