checkout: Suggest git checkout when dcv checkout fails (#1580)

This commit is contained in:
Thibault de Boissiere
2019-02-05 23:46:13 +02:00
committed by Ruslan Kuprieiev
parent f6535183a4
commit 2c67b59fc0
4 changed files with 42 additions and 4 deletions
+12 -2
View File
@@ -566,10 +566,20 @@ class Project(object):
def checkout(
self, target=None, with_deps=False, force=False, recursive=False
):
if target and not recursive:
from dvc.stage import (
StageFileDoesNotExistError,
StageFileBadNameError,
)
all_stages = self.active_stages()
stages = self._collect(target, with_deps=with_deps)
try:
stages = self._collect(target, with_deps=with_deps)
except (StageFileDoesNotExistError, StageFileBadNameError) as exc:
raise DvcException(
str(exc)
+ " Did you mean 'git checkout {}'?".format(target)
)
else:
all_stages = self.active_stages(target)
stages = all_stages
+1 -1
View File
@@ -415,7 +415,7 @@ class Stage(object):
if not Stage.is_valid_filename(fname):
raise StageFileBadNameError(
"bad stage filename '{}'. Stage files should be named"
" 'Dvcfile' or have a '.dvc' suffix(e.g. '{}.dvc').".format(
" 'Dvcfile' or have a '.dvc' suffix (e.g. '{}.dvc').".format(
os.path.relpath(fname), os.path.basename(fname)
)
)
+29
View File
@@ -370,3 +370,32 @@ class TestCheckoutHook(TestDvc):
with self.assertRaises(ConfirmRemoveError):
self.dvc.checkout()
class TestCheckoutSuggestGit(TestRepro):
def test(self):
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'?",
)
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
)
),
)
-1
View File
@@ -1,6 +1,5 @@
import mock
from unittest import TestCase
from dvc.stage import Stage