mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-10 15:28:34 +01:00
diff: handle exceptions
This commit is contained in:
+1
-1
@@ -69,7 +69,7 @@ class CmdDiff(CmdBase):
|
||||
print(self._format(diff))
|
||||
|
||||
except DvcException:
|
||||
logger.exception("failed to get 'diff {}'")
|
||||
logger.exception("failed to get diff")
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import collections
|
||||
import os
|
||||
|
||||
from dvc.exceptions import DvcException
|
||||
from dvc.repo import locked
|
||||
from dvc.scm.git import Git
|
||||
|
||||
|
||||
Diffable = collections.namedtuple("Diffable", "filename, checksum")
|
||||
@@ -54,6 +56,9 @@ def diff(self, a_ref="HEAD", b_ref=None, *, target=None):
|
||||
the concept of `index`, but it keeps the same interface, thus,
|
||||
`dvc diff` would be the same as `dvc diff HEAD`.
|
||||
"""
|
||||
if type(self.scm) is not Git:
|
||||
raise DvcException("only supported for Git repositories")
|
||||
|
||||
outs = {}
|
||||
|
||||
for branch in self.brancher(revs=[a_ref, b_ref]):
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ class CloneError(SCMError):
|
||||
class RevError(SCMError):
|
||||
def __init__(self, url, rev):
|
||||
super().__init__(
|
||||
"Failed to access revision '{}' for repo '{}'".format(rev, url)
|
||||
"failed to access revision '{}' for repo '{}'".format(rev, url)
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -363,7 +363,12 @@ class Git(Base):
|
||||
return self.repo.git.rev_parse("HEAD")
|
||||
|
||||
def resolve_rev(self, rev):
|
||||
return self.repo.git.rev_parse(rev)
|
||||
from git.exc import GitCommandError
|
||||
|
||||
try:
|
||||
return self.repo.git.rev_parse(rev)
|
||||
except GitCommandError as exc:
|
||||
raise RevError(url=self.root_dir, rev=rev) from exc
|
||||
|
||||
def close(self):
|
||||
self.repo.close()
|
||||
|
||||
@@ -6,6 +6,7 @@ import pytest
|
||||
import colorama
|
||||
|
||||
from dvc.main import main
|
||||
from dvc.exceptions import DvcException
|
||||
|
||||
|
||||
def digest(text):
|
||||
@@ -15,7 +16,8 @@ def digest(text):
|
||||
def test_no_scm(tmp_dir, dvc):
|
||||
tmp_dir.dvc_gen("file", "text")
|
||||
|
||||
pytest.skip("TODO: define behavior, should it fail?")
|
||||
with pytest.raises(DvcException, match=r"only supported for Git repos"):
|
||||
dvc.diff()
|
||||
|
||||
|
||||
def test_added(tmp_dir, scm, dvc):
|
||||
@@ -86,7 +88,10 @@ def test_refs(tmp_dir, scm, dvc):
|
||||
],
|
||||
}
|
||||
|
||||
pytest.skip('TODO: test dvc.diff("missing")')
|
||||
with pytest.raises(
|
||||
DvcException, match=r"failed to access revision 'missing'"
|
||||
):
|
||||
dvc.diff("missing")
|
||||
|
||||
|
||||
def test_target(tmp_dir, scm, dvc):
|
||||
|
||||
Reference in New Issue
Block a user