diff --git a/dvc/repo/destroy.py b/dvc/repo/destroy.py index 399d29a51..330cc7097 100644 --- a/dvc/repo/destroy.py +++ b/dvc/repo/destroy.py @@ -3,6 +3,6 @@ import shutil def destroy(self): for stage in self.stages(): - stage.remove() + stage.remove(remove_outs=False) shutil.rmtree(self.dvc_dir) diff --git a/dvc/stage.py b/dvc/stage.py index 772b0d906..1f217b84b 100644 --- a/dvc/stage.py +++ b/dvc/stage.py @@ -296,8 +296,11 @@ class Stage(object): for out in self.outs: out.unprotect() - def remove(self, force=False): - self.remove_outs(ignore_remove=True, force=force) + def remove(self, force=False, remove_outs=True): + if remove_outs: + self.remove_outs(ignore_remove=True, force=force) + else: + self.unprotect_outs() os.unlink(self.path) def reproduce( diff --git a/tests/func/test_destroy.py b/tests/func/test_destroy.py index 8ec3f0ac6..3535c9d7a 100644 --- a/tests/func/test_destroy.py +++ b/tests/func/test_destroy.py @@ -1,21 +1,28 @@ import os -from dvc.main import main - -from tests.func.test_repro import TestRepro +from dvc.system import System -class TestDestroyNoConfirmation(TestRepro): - def test(self): - ret = main(["destroy"]) - self.assertNotEqual(ret, 0) +def test_destroy(repo_dir, dvc_repo): + # NOTE: using symlink to ensure that data was unprotected after `destroy` + dvc_repo.config.set("cache", "type", "symlink") + foo_stage, = dvc_repo.add(repo_dir.FOO) + data_dir_stage, = dvc_repo.add(repo_dir.DATA_DIR) -class TestDestroyForce(TestRepro): - def test(self): - ret = main(["destroy", "-f"]) - self.assertEqual(ret, 0) + dvc_repo.destroy() - self.assertFalse(os.path.exists(self.dvc.dvc_dir)) - self.assertFalse(os.path.exists(self.file1_stage)) - self.assertFalse(os.path.exists(self.file1)) + assert not os.path.exists(dvc_repo.dvc_dir) + assert not os.path.exists(foo_stage.path) + assert not os.path.exists(data_dir_stage.path) + + assert os.path.isfile(repo_dir.FOO) + assert os.path.isdir(repo_dir.DATA_DIR) + assert os.path.isfile(repo_dir.DATA) + assert os.path.isdir(repo_dir.DATA_SUB_DIR) + assert os.path.isfile(repo_dir.DATA_SUB) + + assert not System.is_symlink(repo_dir.FOO) + assert not System.is_symlink(repo_dir.DATA_DIR) + assert not System.is_symlink(repo_dir.DATA) + assert not System.is_symlink(repo_dir.DATA_SUB)