mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
fix error message for git files
This commit is contained in:
+20
-6
@@ -8,6 +8,7 @@ from dvc.exceptions import GetDVCFileError
|
||||
from dvc.exceptions import NotDvcRepoError
|
||||
from dvc.exceptions import OutputNotFoundError
|
||||
from dvc.exceptions import UrlNotDvcRepoError
|
||||
from dvc.exceptions import FileMissingError
|
||||
from dvc.external_repo import external_repo
|
||||
from dvc.path_info import PathInfo
|
||||
from dvc.stage import Stage
|
||||
@@ -18,14 +19,28 @@ from dvc.utils.fs import remove
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _is_git_file(repo, path):
|
||||
if not os.path.isabs(path):
|
||||
try:
|
||||
output = repo.find_out_by_relpath(path)
|
||||
if not output.use_cache:
|
||||
return True
|
||||
except OutputNotFoundError:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
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 os.path.isdir(src_full_path):
|
||||
shutil.copytree(src_full_path, dst_full_path)
|
||||
else:
|
||||
shutil.copy2(src_full_path, dst_full_path)
|
||||
try:
|
||||
if os.path.isdir(src_full_path):
|
||||
shutil.copytree(src_full_path, dst_full_path)
|
||||
else:
|
||||
shutil.copy2(src_full_path, dst_full_path)
|
||||
except FileNotFoundError:
|
||||
raise FileMissingError(src)
|
||||
|
||||
|
||||
@staticmethod
|
||||
@@ -44,8 +59,7 @@ def get(url, path, out=None, rev=None):
|
||||
tmp_dir = os.path.join(dpath, "." + str(shortuuid.uuid()))
|
||||
try:
|
||||
with external_repo(cache_dir=tmp_dir, url=url, rev=rev) as repo:
|
||||
full_path = os.path.join(repo.root_dir, path)
|
||||
if os.path.exists(full_path) and not os.path.isabs(path):
|
||||
if _is_git_file(repo, path):
|
||||
_copy_git_file(repo, path, out)
|
||||
return
|
||||
|
||||
|
||||
+11
-1
@@ -10,6 +10,7 @@ from dvc.config import Config
|
||||
from dvc.exceptions import GetDVCFileError
|
||||
from dvc.exceptions import UrlNotDvcRepoError
|
||||
from dvc.exceptions import NoOutputInExternalRepoError
|
||||
from dvc.exceptions import FileMissingError
|
||||
from dvc.repo import Repo
|
||||
from dvc.system import System
|
||||
from dvc.utils import makedirs
|
||||
@@ -143,11 +144,20 @@ def test_non_cached_output(tmp_path, erepo):
|
||||
|
||||
|
||||
# https://github.com/iterative/dvc/pull/2837#discussion_r352123053
|
||||
def test_fails_with_non_git_files(erepo):
|
||||
def test_fails_with_files_outside_repo(erepo):
|
||||
with pytest.raises(NoOutputInExternalRepoError):
|
||||
Repo.get(erepo.root_dir, "/root/")
|
||||
|
||||
|
||||
def test_fails_with_non_existing_files(erepo):
|
||||
fname = "file_does_not_exist"
|
||||
with pytest.raises(
|
||||
FileMissingError,
|
||||
match="Can't find '{}' neither locally nor on remote".format(fname),
|
||||
):
|
||||
Repo.get(erepo.root_dir, fname)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("dname", [".", "dir", "dir/subdir"])
|
||||
def test_get_to_dir(dname, erepo):
|
||||
src = erepo.FOO
|
||||
|
||||
Reference in New Issue
Block a user