From 38d666d77d4e2209776d91e07670c67ee1bb0f95 Mon Sep 17 00:00:00 2001 From: "Mr. Outis" Date: Wed, 28 Nov 2018 15:35:37 -0600 Subject: [PATCH] import: Output as on optional argument (#1351) (#1378) * import: Output as on optional argument Close #1335 * Use tempfile to prevent circular dependencies --- dvc/remote/local.py | 12 ++++++++---- tests/test_checkout.py | 13 +++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/dvc/remote/local.py b/dvc/remote/local.py index b59db25f3..b6c4b35d3 100644 --- a/dvc/remote/local.py +++ b/dvc/remote/local.py @@ -326,10 +326,11 @@ class RemoteLOCAL(RemoteBase): entry_checksum_info = {self.PARAM_MD5: m} if self.changed(entry_info, entry_checksum_info): - if force or self._already_cached(p): - remove(p) - else: - self._safe_remove(p) + if os.path.exists(p): + if force or self._already_cached(p): + remove(p) + else: + self._safe_remove(p) self.link(c, p) @@ -346,6 +347,9 @@ class RemoteLOCAL(RemoteBase): def _already_cached(self, path): current_md5 = self.state.update(path) + if not current_md5: + return False + return not self.changed_cache(current_md5) def _discard_working_directory_changes(self, path, dir_info, force=False): diff --git a/tests/test_checkout.py b/tests/test_checkout.py index 72473b40b..3684263ed 100644 --- a/tests/test_checkout.py +++ b/tests/test_checkout.py @@ -359,3 +359,16 @@ class TestCheckoutWithDeps(TestRepro): self.assertTrue(os.path.exists(self.FOO)) self.assertTrue(os.path.exists(self.file1)) + + +class TestCheckoutDirectory(TestRepro): + def test(self): + stage = self.dvc.add(self.DATA_DIR)[0] + + shutil.rmtree(self.DATA_DIR) + self.assertFalse(os.path.exists(self.DATA_DIR)) + + ret = main(['checkout', stage.path]) + self.assertEqual(ret, 0) + + self.assertTrue(os.path.exists(self.DATA_DIR))