dvc: find dvc root

For now we were able to work only in root dvc directory.
This patch emulates git behaviour by walking up the tree
to find repository root.

Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
Ruslan Kuprieiev
2017-12-28 13:10:13 +02:00
parent fbdb447d76
commit 232ae661a5
+13 -1
View File
@@ -1,9 +1,11 @@
import os
from dvc.project import Project
class CmdBase(object):
def __init__(self, args):
self.project = Project('.')
self.project = Project(self._find_root())
self.args = args
if args.quiet and not args.verbose:
@@ -11,6 +13,16 @@ class CmdBase(object):
elif not args.quiet and args.verbose:
self.project.logger.be_verbose()
def _find_root(self):
root = os.getcwd()
while not os.path.ismount(root):
dvc_dir = os.path.join(root, Project.DVC_DIR)
if os.path.isdir(dvc_dir):
return root
root = os.path.dirname(root)
msg = "Not a dvc repository (or any parent up to mount point {})"
Logger.error(msg.format(root))
def run_cmd(self):
with self.project.lock:
with self.project.scm.brancher(self.args.branch, self.args.new_branch):