external_repo: do not try too hard to fix upstream (#3512)

* tests: importing from bare repo

* external_repo: don't try too hard to set upstream repo especially if url is not a dvc repo.

* Update tests/func/test_import.py

* Add a comment regarding bare-repo clone
This commit is contained in:
Saugat Pachhai
2020-03-20 15:54:47 +02:00
committed by GitHub
parent 8f546f253b
commit 205a605887
2 changed files with 27 additions and 2 deletions
+10 -2
View File
@@ -127,9 +127,17 @@ class ExternalRepo(Repo):
if not os.path.isdir(self.url):
return
remote_name = self.config["core"].get("remote")
src_repo = Repo(self.url)
try:
src_repo = Repo(self.url)
except NotDvcRepoError:
# If ExternalRepo does not throw NotDvcRepoError and Repo does,
# the self.url might be a bare git repo.
# NOTE: This will fail to resolve remote with relative path,
# same as if it was a remote DVC repo.
return
try:
remote_name = self.config["core"].get("remote")
if remote_name:
self._fix_local_remote(src_repo, remote_name)
else:
+17
View File
@@ -305,3 +305,20 @@ def test_pull_no_rev_lock(erepo_dir, tmp_dir, dvc):
assert (tmp_dir / "foo_imported").is_file()
assert (tmp_dir / "foo_imported").read_text() == "contents"
def test_import_from_bare_git_repo(tmp_dir, make_tmp_dir, erepo_dir):
import git
git.Repo.init(fspath(tmp_dir), bare=True)
with erepo_dir.chdir():
erepo_dir.dvc_gen({"foo": "foo"}, commit="initial")
erepo_dir.dvc.push()
erepo_dir.scm.repo.create_remote("origin", fspath(tmp_dir))
erepo_dir.scm.repo.remote("origin").push("master")
dvc_repo = make_tmp_dir("dvc-repo", scm=True, dvc=True)
with dvc_repo.chdir():
dvc_repo.dvc.imp(fspath(tmp_dir), "foo")