Skip to content

Commit

Permalink
external_repo: do not try too hard to fix upstream (iterative#3512)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
skshetry authored Mar 20, 2020
1 parent 8f546f2 commit 205a605
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
12 changes: 10 additions & 2 deletions dvc/external_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,17 @@ def _fix_upstream(self):
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:
Expand Down
17 changes: 17 additions & 0 deletions tests/func/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit 205a605

Please sign in to comment.