incorporated feedback

This commit is contained in:
Mayur Kularni
2019-12-08 18:56:38 +05:30
parent e1c5f6c5c0
commit ca20a1c93a
2 changed files with 14 additions and 35 deletions
+14 -29
View File
@@ -70,18 +70,21 @@ def _external_repo(url=None, rev=None, cache_dir=None):
_git_checkout(new_path, rev)
repo = Repo(new_path)
# Adjust original repo for pointing remote towards its' cache
original_repo = Repo(url)
rconfig = RemoteConfig(original_repo.config)
try:
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)
@@ -89,7 +92,6 @@ 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()
REPO_CACHE[key] = new_path
return new_path
@@ -144,20 +146,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
-6
View File
@@ -7,7 +7,6 @@ import pytest
from git import Repo
from git.exc import GitCommandNotFound
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"])