mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-19 15:28:28 +01:00
checkout: reorganize "git checkout hint" exception
Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
@@ -248,3 +248,10 @@ class TargetNotDirectoryError(DvcException):
|
||||
super(TargetNotDirectoryError, self).__init__(
|
||||
"Target: {} is not a directory".format(path)
|
||||
)
|
||||
|
||||
|
||||
class CheckoutErrorSuggestGit(DvcException):
|
||||
def __init__(self, target, cause):
|
||||
super(CheckoutErrorSuggestGit, self).__init__(
|
||||
"Did you mean 'git checkout {}'?".format(target), cause=cause
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import dvc.logger as logger
|
||||
from dvc.exceptions import DvcException
|
||||
from dvc.exceptions import CheckoutErrorSuggestGit
|
||||
from dvc.progress import ProgressCallback
|
||||
|
||||
|
||||
@@ -34,9 +34,7 @@ def checkout(self, target=None, with_deps=False, force=False, recursive=False):
|
||||
except (StageFileDoesNotExistError, StageFileBadNameError) as exc:
|
||||
if not target:
|
||||
raise
|
||||
raise DvcException(
|
||||
str(exc) + " Did you mean 'git checkout {}'?".format(target)
|
||||
)
|
||||
raise CheckoutErrorSuggestGit(target, exc)
|
||||
|
||||
with self.state:
|
||||
_cleanup_unused_links(self, all_stages)
|
||||
|
||||
+8
-21
@@ -15,12 +15,13 @@ from dvc.system import System
|
||||
from dvc.utils import walk_files
|
||||
from tests.basic_env import TestDvc
|
||||
from tests.test_repro import TestRepro
|
||||
from dvc.stage import Stage
|
||||
from dvc.stage import Stage, StageFileBadNameError, StageFileDoesNotExistError
|
||||
from dvc.remote.local import RemoteLOCAL
|
||||
from dvc.exceptions import (
|
||||
DvcException,
|
||||
ConfirmRemoveError,
|
||||
TargetNotDirectoryError,
|
||||
CheckoutErrorSuggestGit,
|
||||
)
|
||||
|
||||
from mock import patch
|
||||
@@ -385,30 +386,16 @@ class TestCheckoutSuggestGit(TestRepro):
|
||||
try:
|
||||
self.dvc.checkout(target="gitbranch")
|
||||
except DvcException as exc:
|
||||
msg = str(exc)
|
||||
self.assertEqual(
|
||||
msg,
|
||||
(
|
||||
"'gitbranch' does not exist. "
|
||||
"Did you mean 'git checkout gitbranch'?"
|
||||
),
|
||||
)
|
||||
self.assertIsInstance(exc, CheckoutErrorSuggestGit)
|
||||
self.assertIsInstance(exc.cause, StageFileDoesNotExistError)
|
||||
self.assertIsNone(exc.cause.cause)
|
||||
|
||||
try:
|
||||
self.dvc.checkout(target=self.FOO)
|
||||
except DvcException as exc:
|
||||
msg = str(exc)
|
||||
self.assertEqual(
|
||||
msg,
|
||||
(
|
||||
"bad stage filename '{}'."
|
||||
" Stage files should be named 'Dvcfile'"
|
||||
" or have a '.dvc' suffix (e.g. '{}.dvc')."
|
||||
" Did you mean 'git checkout {}'?".format(
|
||||
self.FOO, self.FOO, self.FOO
|
||||
)
|
||||
),
|
||||
)
|
||||
self.assertIsInstance(exc, CheckoutErrorSuggestGit)
|
||||
self.assertIsInstance(exc.cause, StageFileBadNameError)
|
||||
self.assertIsNone(exc.cause.cause)
|
||||
|
||||
|
||||
class TestCheckoutShouldHaveSelfClearingProgressBar(TestDvc):
|
||||
|
||||
Reference in New Issue
Block a user