Skip to content

Commit

Permalink
dvc: find dvc root
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
efiop committed Dec 28, 2017
1 parent fbdb447 commit 232ae66
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion dvc/command/common/base.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
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:
self.project.logger.be_quiet()
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):
Expand Down

0 comments on commit 232ae66

Please sign in to comment.