Skip to content

Commit eeffaf8

Browse files
authored
dulwich: handle invalid revisions in diff (#62)
1 parent 021a056 commit eeffaf8

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

scmrepo/git/backend/dulwich/__init__.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@
1919

2020
from funcy import cached_property
2121

22-
from scmrepo.exceptions import AuthError, CloneError, InvalidRemote, SCMError
22+
from scmrepo.exceptions import (
23+
AuthError,
24+
CloneError,
25+
InvalidRemote,
26+
RevError,
27+
SCMError,
28+
)
2329
from scmrepo.progress import GitProgressReporter
2430
from scmrepo.utils import relpath
2531

@@ -721,8 +727,11 @@ def _describe(
721727
def diff(self, rev_a: str, rev_b: str, binary=False) -> str:
722728
from dulwich.patch import write_tree_diff
723729

724-
commit_a = self.repo[os.fsencode(rev_a)]
725-
commit_b = self.repo[os.fsencode(rev_b)]
730+
try:
731+
commit_a = self.repo[os.fsencode(rev_a)]
732+
commit_b = self.repo[os.fsencode(rev_b)]
733+
except KeyError as exc:
734+
raise RevError("Invalid revision") from exc
726735

727736
buf = BytesIO()
728737
write_tree_diff(

0 commit comments

Comments
 (0)