mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-18 15:28:28 +01:00
Merge pull request #2460 from pared/2430
repo: get: intercept and convert NotDvcRepoErro to UrlNotDvcRepoError
This commit is contained in:
@@ -279,3 +279,10 @@ class DvcIgnoreInCollectedDirError(DvcException):
|
||||
".dvcignore file should not be in collected dir path: "
|
||||
"'{}'".format(ignore_dirname)
|
||||
)
|
||||
|
||||
|
||||
class UrlNotDvcRepoError(DvcException):
|
||||
def __init__(self, url):
|
||||
super(UrlNotDvcRepoError, self).__init__(
|
||||
"URL '{}' is not a dvc repository.".format(url)
|
||||
)
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
import logging
|
||||
import os
|
||||
import shortuuid
|
||||
|
||||
from dvc.config import Config
|
||||
from dvc.exceptions import NotDvcRepoError, UrlNotDvcRepoError
|
||||
from dvc.path_info import PathInfo
|
||||
from dvc.external_repo import external_repo
|
||||
from dvc.state import StateNoop
|
||||
from dvc.utils import remove
|
||||
from dvc.utils.compat import urlparse
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get(url, path, out=None, rev=None):
|
||||
@@ -48,5 +52,8 @@ def get(url, path, out=None, rev=None):
|
||||
o.path_info = PathInfo(os.path.abspath(out))
|
||||
with o.repo.state:
|
||||
o.checkout()
|
||||
|
||||
except NotDvcRepoError:
|
||||
raise UrlNotDvcRepoError(url)
|
||||
finally:
|
||||
remove(tmp_dir)
|
||||
|
||||
+9
-2
@@ -9,8 +9,7 @@ from dvc.remote.config import RemoteConfig
|
||||
from dvc.utils.compat import cast_bytes_py2
|
||||
from dvc.remote.ssh.connection import SSHConnection
|
||||
from dvc.repo import Repo as DvcRepo
|
||||
from .basic_env import TestDirFixture, TestDvcGitFixture
|
||||
|
||||
from .basic_env import TestDirFixture, TestDvcGitFixture, TestGitFixture
|
||||
|
||||
# Prevent updater and analytics from running their processes
|
||||
os.environ[cast_bytes_py2("DVC_TEST")] = cast_bytes_py2("true")
|
||||
@@ -177,3 +176,11 @@ def _close_pools():
|
||||
|
||||
yield
|
||||
close_pools()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def git_erepo():
|
||||
repo = TestGitFixture()
|
||||
repo.setUp()
|
||||
yield repo
|
||||
repo.tearDown()
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import os
|
||||
import filecmp
|
||||
|
||||
import pytest
|
||||
|
||||
from dvc.exceptions import UrlNotDvcRepoError
|
||||
from dvc.repo import Repo
|
||||
|
||||
from tests.utils import trees_equal
|
||||
@@ -38,3 +41,8 @@ def test_get_repo_rev(repo_dir, erepo):
|
||||
assert os.path.isfile(dst)
|
||||
with open(dst, "r+") as fobj:
|
||||
assert fobj.read() == "branch"
|
||||
|
||||
|
||||
def test_get_from_non_dvc_repo(git_erepo):
|
||||
with pytest.raises(UrlNotDvcRepoError):
|
||||
Repo.get(git_erepo.root_dir, "some_file.zip")
|
||||
|
||||
Reference in New Issue
Block a user