diff --git a/dvc/repo/experiments/apply.py b/dvc/repo/experiments/apply.py index af4f42671..584517c90 100644 --- a/dvc/repo/experiments/apply.py +++ b/dvc/repo/experiments/apply.py @@ -46,7 +46,12 @@ def apply(repo, rev, force=True, **kwargs): else: workspace = None - repo.scm.merge(exp_rev, commit=False) + from dvc.scm.exceptions import SCMError as _SCMError + + try: + repo.scm.merge(exp_rev, commit=False) + except _SCMError as exc: + raise SCMError(str(exc)) if workspace: try: @@ -61,7 +66,7 @@ def apply(repo, rev, force=True, **kwargs): repo.scm.reset(hard=True) repo.scm.stash.pop() raise ApplyConflictError(rev) from exc - except SCMError as exc: + except _SCMError as exc: raise ApplyConflictError(rev) from exc repo.scm.stash.drop() repo.scm.reset() diff --git a/dvc/scm/__init__.py b/dvc/scm/__init__.py index b3942b9ae..a62b0185f 100644 --- a/dvc/scm/__init__.py +++ b/dvc/scm/__init__.py @@ -26,11 +26,17 @@ def SCM( Returns: dvc.scm.base.Base: SCM instance. """ + from dvc.scm.base import SCMError + from dvc.scm.exceptions import SCMError as InternalSCMError - if no_scm: - return NoSCM(root_dir) - - return Git(root_dir, search_parent_directories=search_parent_directories) + try: + if no_scm: + return NoSCM(root_dir) + return Git( + root_dir, search_parent_directories=search_parent_directories + ) + except InternalSCMError as exc: + raise SCMError(str(exc)) def clone(url: str, to_path: str, **kwargs): diff --git a/dvc/scm/git/backend/base.py b/dvc/scm/git/backend/base.py index cbc571255..9f9ae91bc 100644 --- a/dvc/scm/git/backend/base.py +++ b/dvc/scm/git/backend/base.py @@ -10,7 +10,7 @@ from typing import ( Union, ) -from dvc.scm.base import SCMError +from dvc.scm.exceptions import SCMError from ..objects import GitObject diff --git a/dvc/scm/git/backend/dulwich/__init__.py b/dvc/scm/git/backend/dulwich/__init__.py index c479740ac..6a7176160 100644 --- a/dvc/scm/git/backend/dulwich/__init__.py +++ b/dvc/scm/git/backend/dulwich/__init__.py @@ -19,8 +19,7 @@ from typing import ( from funcy import cached_property from dvc.progress import Tqdm -from dvc.scm.base import SCMError -from dvc.scm.exceptions import AuthError, InvalidRemote +from dvc.scm.exceptions import AuthError, InvalidRemote, SCMError from dvc.utils import relpath from ...objects import GitObject diff --git a/dvc/scm/git/backend/gitpython.py b/dvc/scm/git/backend/gitpython.py index 4cc3ba60c..430538758 100644 --- a/dvc/scm/git/backend/gitpython.py +++ b/dvc/scm/git/backend/gitpython.py @@ -17,8 +17,12 @@ from typing import ( from funcy import ignore from dvc.progress import Tqdm -from dvc.scm.base import SCMError -from dvc.scm.exceptions import CloneError, MergeConflictError, RevError +from dvc.scm.exceptions import ( + CloneError, + MergeConflictError, + RevError, + SCMError, +) from dvc.utils import fix_env, is_binary, relpath from ..objects import GitCommit, GitObject diff --git a/dvc/scm/git/backend/pygit2.py b/dvc/scm/git/backend/pygit2.py index 284fe1c5c..a973da176 100644 --- a/dvc/scm/git/backend/pygit2.py +++ b/dvc/scm/git/backend/pygit2.py @@ -17,8 +17,7 @@ from typing import ( from funcy import cached_property -from dvc.scm.base import SCMError -from dvc.scm.exceptions import MergeConflictError, RevError +from dvc.scm.exceptions import MergeConflictError, RevError, SCMError from dvc.utils import relpath from ..objects import GitCommit, GitObject diff --git a/dvc/scm/git/stash.py b/dvc/scm/git/stash.py index 05213a596..4563db0fe 100644 --- a/dvc/scm/git/stash.py +++ b/dvc/scm/git/stash.py @@ -3,7 +3,7 @@ import logging from typing import Optional -from dvc.scm.base import SCMError +from dvc.scm.exceptions import SCMError logger = logging.getLogger(__name__) diff --git a/tests/unit/scm/test_git.py b/tests/unit/scm/test_git.py index 3cbae66d0..75bce3e17 100644 --- a/tests/unit/scm/test_git.py +++ b/tests/unit/scm/test_git.py @@ -2,7 +2,7 @@ import os import pytest -from dvc.scm.base import SCMError +from dvc.scm.exceptions import SCMError # Behaves the same as SCM but will test against all supported Git backends.