incorporated feedback

This commit is contained in:
Mayur Kularni
2019-12-08 14:02:44 +05:30
parent 0dd310d387
commit 9e24be14f0
2 changed files with 17 additions and 36 deletions
+17 -30
View File
@@ -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
-6
View File
@@ -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"])