summaryrefslogtreecommitdiff
path: root/git/diff.py
diff options
context:
space:
mode:
authorYobmod <yobmod@gmail.com>2021-07-09 11:40:32 +0100
committerYobmod <yobmod@gmail.com>2021-07-09 11:40:32 +0100
commit937746291cfdaa40938de03db305b1137c391907 (patch)
tree6f28d6c757cc33f5dadec2635d4d0e63856e2942 /git/diff.py
parent5eea8910b2e07d424a2e33299149d13392a80a54 (diff)
downloadgitpython-937746291cfdaa40938de03db305b1137c391907.tar.gz
Make has_repo protocol runtime checkable and use in Diffable
Diffstat (limited to 'git/diff.py')
-rw-r--r--git/diff.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/git/diff.py b/git/diff.py
index d3b18652..cb216299 100644
--- a/git/diff.py
+++ b/git/diff.py
@@ -16,7 +16,7 @@ from .objects.util import mode_str_to_int
# typing ------------------------------------------------------------------
from typing import Any, Iterator, List, Match, Optional, Tuple, Type, TypeVar, Union, TYPE_CHECKING
-from git.types import PathLike, TBD, Literal, TypeGuard
+from git.types import Has_Repo, PathLike, TBD, Literal, TypeGuard
if TYPE_CHECKING:
from .objects.tree import Tree
@@ -141,8 +141,10 @@ class Diffable(object):
if paths is not None and not isinstance(paths, (tuple, list)):
paths = [paths]
- if hasattr(self, 'repo'): # else raise Error?
- self.repo = self.repo # type: 'Repo'
+ if isinstance(self, Has_Repo):
+ self.repo: Repo = self.repo
+ else:
+ raise AttributeError("No repo member found, cannot create DiffIndex")
diff_cmd = self.repo.git.diff
if other is self.Index: