Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines 127 to 128
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is redundant here as it should be covered by below try/except block. But, I think, this makes the intention clearer, so, keeping it for now. :)


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
Comment thread
skshetry marked this conversation as resolved.

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")