From 9e24be14f0cfa588db1fa1b18085581d742958cd Mon Sep 17 00:00:00 2001 From: Mayur Kularni Date: Sun, 8 Dec 2019 14:02:44 +0530 Subject: [PATCH] incorporated feedback --- dvc/external_repo.py | 47 ++++++++++++++++---------------------------- tests/conftest.py | 6 ------ 2 files changed, 17 insertions(+), 36 deletions(-) diff --git a/dvc/external_repo.py b/dvc/external_repo.py index cbd33b250..1216e836c 100644 --- a/dvc/external_repo.py +++ b/dvc/external_repo.py @@ -63,21 +63,24 @@ def _external_repo(url=None, rev=None, cache_dir=None): # Adjust new clone/copy to fit rev and cache_dir repo = Repo(new_path) - # Adjust original repo for pointing remote towards its' cache - original_repo = Repo(url) - rconfig = RemoteConfig(original_repo.config) + original_repo = None try: if rev is not None: repo.scm.checkout(rev) - - if not _is_local(url) and not _remote_config_exists(rconfig): - # check if the URL is local and no default remote - # add default remote pointing to the original repo's cache location - rconfig.add("upstream", - original_repo.cache.local.cache_dir, - default=True) - original_repo.scm.add([original_repo.config.config_file]) - original_repo.scm.commit("add remote") + # check if the URL is local and no default remote + # add default remote pointing to the original repo's cache location + if not os.path.isdir(url): + # Adjust original repo for pointing remote towards its' cache + original_repo = Repo(url) + rconfig = RemoteConfig(original_repo.config) + if not _remote_config_exists(rconfig): + rconfig.add( + "upstream", + original_repo.cache.local.cache_dir, + default=True, + ) + original_repo.scm.add([original_repo.config.config_file]) + original_repo.scm.commit("add remote") if cache_dir is not None: cache_config = CacheConfig(repo.config) @@ -85,7 +88,8 @@ def _external_repo(url=None, rev=None, cache_dir=None): finally: # Need to close/reopen repo to force config reread repo.close() - original_repo.close() + if original_repo: + original_repo.close() REPO_CACHE[key] = new_path return new_path @@ -130,20 +134,3 @@ def _remote_config_exists(rconfig): except ConfigError: default = None return True if default else False - - -def _is_local(url): - """ - Checks if the URL is local or not. - Args: - url: url - - Returns: - True, if the URL is local else False - """ - remote_urls = {"azure://", "gs://", "http://", "https://", - "oss://", "s3://", "hdfs://"} - for remote_url in remote_urls: - if url.startswith(remote_url): - return False - return True diff --git a/tests/conftest.py b/tests/conftest.py index 0cdb204b8..730b6d32d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -10,7 +10,6 @@ from git.exc import GitCommandNotFound from .basic_env import TestDirFixture from .basic_env import TestDvcGitFixture from .basic_env import TestGitFixture -from dvc.remote.config import RemoteConfig from dvc.remote.ssh.connection import SSHConnection from dvc.repo import Repo as DvcRepo from dvc.utils.compat import cast_bytes_py2 @@ -148,11 +147,6 @@ def erepo(repo_dir): repo.dvc.scm.add([stage_foo.path, stage_bar.path, stage_data_dir.path]) repo.dvc.scm.commit("init repo") - rconfig = RemoteConfig(repo.dvc.config) - rconfig.add("upstream", repo.dvc.cache.local.cache_dir, default=True) - repo.dvc.scm.add([repo.dvc.config.config_file]) - repo.dvc.scm.commit("add remote") - repo.create("version", "master") repo.dvc.add("version") repo.dvc.scm.add([".gitignore", "version.dvc"])