Skip to content

Commit

Permalink
repo: get: intercept and convert NotDvcRepoErro to UrlNotDvcRepoError
Browse files Browse the repository at this point in the history
  • Loading branch information
pared committed Sep 3, 2019
1 parent 3a52732 commit 4236f18
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
7 changes: 7 additions & 0 deletions dvc/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,10 @@ def __init__(self, ignore_dirname):
".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)
)
7 changes: 7 additions & 0 deletions dvc/repo/get.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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)
11 changes: 9 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
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")
Expand Down Expand Up @@ -177,3 +176,11 @@ def _close_pools():

yield
close_pools()


@pytest.fixture
def git_erepo():
repo = TestGitFixture()
repo.setUp()
yield repo
repo.tearDown()
8 changes: 8 additions & 0 deletions tests/func/test_get.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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")

0 comments on commit 4236f18

Please sign in to comment.