mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-10 15:28:34 +01:00
checkout: Suggest git checkout when dcv checkout fails (#1580)
This commit is contained in:
committed by
Ruslan Kuprieiev
parent
f6535183a4
commit
2c67b59fc0
+12
-2
@@ -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
@@ -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)
|
||||
)
|
||||
)
|
||||
|
||||
@@ -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,6 +1,5 @@
|
||||
import mock
|
||||
from unittest import TestCase
|
||||
|
||||
from dvc.stage import Stage
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user