From 232ae661a5b7ab60cd963a6e7a8ca7ea63c2432b Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Thu, 28 Dec 2017 13:10:13 +0200 Subject: [PATCH] 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 --- dvc/command/common/base.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/dvc/command/common/base.py b/dvc/command/common/base.py index c5fcea2c1..805474e4b 100644 --- a/dvc/command/common/base.py +++ b/dvc/command/common/base.py @@ -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):