Repository: iterative/dvc

Issue:
Dvc checkout for an empty dir should create the dir itself

Discussion:

Patch:
diff --git a/dvc/remote/local.py b/dvc/remote/local.py
index 75602ae0a..9c98d493a 100644
--- a/dvc/remote/local.py
+++ b/dvc/remote/local.py
@@ -160,6 +160,11 @@ class RemoteLOCAL(RemoteBase):
         msg = u'Checking out directory \'{}\' with cache \'{}\''
         Logger.debug(msg.format(os.path.relpath(path), os.path.relpath(cache)))
 
+        # Create dir separately so that dir is created
+        # even if there are no files in it
+        if not os.path.exists(path):
+            os.makedirs(path)
+
         dir_cache = self.dir_cache(cache)
         for relpath, c in dir_cache.items():
             p = os.path.join(path, relpath)


Test patch:
diff --git a/tests/test_checkout.py b/tests/test_checkout.py
index f39263ac2..95a0b807b 100644
--- a/tests/test_checkout.py
+++ b/tests/test_checkout.py
@@ -170,3 +170,20 @@ class TestCheckoutMissingMd5InStageFile(TestRepro):
             yaml.dump(d, fd)
 
         self.dvc.checkout()
+
+
+class TestCheckoutEmptyDir(TestDvc):
+    def test(self):
+        dname = 'empty_dir'
+        os.mkdir(dname)
+
+        stage = self.dvc.add(dname)
+        self.assertEqual(len(stage.outs), 1)
+
+        stage.outs[0].remove()
+        self.assertFalse(os.path.exists(dname))
+
+        self.dvc.checkout()
+
+        self.assertTrue(os.path.isdir(dname))
+        self.assertEqual(len(os.listdir(dname)), 0)