diff --git a/dvc/exceptions.py b/dvc/exceptions.py index e489a45a2..552326428 100644 --- a/dvc/exceptions.py +++ b/dvc/exceptions.py @@ -29,3 +29,12 @@ class OutputDuplicationError(DvcException): for stage in stages: s += "\n " + stage super(OutputDuplicationError, self).__init__(msg.format(output, s)) + + +class MoveNotDataSourceError(DvcException): + def __init__(self, path): + msg = "Move is not permitted for stages that are not data sources. " \ + "You need to either move '{path}' to a new location and edit " \ + "it by hand, or remove '{path}' and create a new one at the " \ + "desired location." + super(MoveNotDataSourceError, self).__init__(msg.format(path=path)) diff --git a/dvc/project.py b/dvc/project.py index 10691e1eb..e1fbb2f0c 100644 --- a/dvc/project.py +++ b/dvc/project.py @@ -1,6 +1,6 @@ import os -from dvc.exceptions import DvcException +from dvc.exceptions import DvcException, MoveNotDataSourceError from dvc.stage import Stage @@ -209,8 +209,7 @@ class Project(object): continue if not stage.is_data_source: - msg = 'Dvcfile \'{}\' is not a data source.' - raise DvcException(msg.format(stage.rel_path)) + raise MoveNotDataSourceError(stage.relpath) found = True to_out = Output.loads_from(out.stage, diff --git a/tests/test_move.py b/tests/test_move.py index 9b81b7bb6..d12440068 100644 --- a/tests/test_move.py +++ b/tests/test_move.py @@ -1,9 +1,10 @@ import os from dvc.main import main -from dvc.exceptions import DvcException +from dvc.exceptions import DvcException, MoveNotDataSourceError from tests.basic_env import TestDvc +from tests.test_repro import TestRepro class TestMove(TestDvc): @@ -39,3 +40,15 @@ class TestCmdMove(TestDvc): ret = main(['move', 'non-existing-file', 'dst']) self.assertNotEqual(ret, 0) + + +class TestMoveNotDataSource(TestRepro): + def test(self): + from dvc.project import Project + + self.dvc = Project(self._root_dir) + with self.assertRaises(MoveNotDataSourceError): + self.dvc.move(self.file1, 'dst') + + ret = main(['move', self.file1, 'dst']) + self.assertNotEqual(ret, 0)