From 38bed227c65463550e3fd624d6ff2f60cb6606ef Mon Sep 17 00:00:00 2001 From: Dani Hodovic Date: Wed, 4 Dec 2019 17:28:01 +0100 Subject: [PATCH] fixup --- dvc/exceptions.py | 6 +++--- dvc/repo/get.py | 7 ++++--- tests/func/test_get.py | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/dvc/exceptions.py b/dvc/exceptions.py index 6909bcea0..237b0d2e5 100644 --- a/dvc/exceptions.py +++ b/dvc/exceptions.py @@ -268,9 +268,9 @@ class FileMissingError(DvcException): ) -class FileOutsideRepoError(DvcException): - def __init__(self, path, cause=None): - super(FileOutsideRepoError, self).__init__( +class PathOutsideRepoError(DvcException): + def __init__(self, path): + super(PathOutsideRepoError, self).__init__( "The path '{}' is outside the target repository.".format(path) ) diff --git a/dvc/repo/get.py b/dvc/repo/get.py index 7ea599844..f986b31d1 100644 --- a/dvc/repo/get.py +++ b/dvc/repo/get.py @@ -9,13 +9,14 @@ from dvc.exceptions import NotDvcRepoError from dvc.exceptions import OutputNotFoundError from dvc.exceptions import UrlNotDvcRepoError from dvc.exceptions import NoOutputInExternalRepoError -from dvc.exceptions import FileOutsideRepoError +from dvc.exceptions import PathOutsideRepoError from dvc.external_repo import external_repo from dvc.path_info import PathInfo from dvc.stage import Stage from dvc.state import StateNoop from dvc.utils import resolve_output from dvc.utils.fs import remove +from dvc.utils.fs import path_isin logger = logging.getLogger(__name__) @@ -24,8 +25,8 @@ def _copy_git_file(repo, src, dst): src_full_path = os.path.join(repo.root_dir, src) dst_full_path = os.path.abspath(dst) - if repo.root_dir not in src_full_path: - raise FileOutsideRepoError(src) + if not path_isin(src_full_path, repo.root_dir): + raise PathOutsideRepoError(src) if os.path.isdir(src_full_path): shutil.copytree(src_full_path, dst_full_path) diff --git a/tests/func/test_get.py b/tests/func/test_get.py index cf35f4bc5..5d519194d 100644 --- a/tests/func/test_get.py +++ b/tests/func/test_get.py @@ -9,7 +9,7 @@ import pytest from dvc.config import Config from dvc.exceptions import GetDVCFileError from dvc.exceptions import UrlNotDvcRepoError -from dvc.exceptions import FileOutsideRepoError +from dvc.exceptions import PathOutsideRepoError from dvc.repo import Repo from dvc.system import System from dvc.utils import makedirs @@ -129,7 +129,7 @@ def test_get_full_dvc_path(erepo): # https://github.com/iterative/dvc/pull/2837#discussion_r352123053 def test_fails_with_non_git_files(erepo): - with pytest.raises(FileOutsideRepoError): + with pytest.raises(PathOutsideRepoError): Repo.get(erepo.root_dir, "/root/")