diff --git a/dvc/external_repo.py b/dvc/external_repo.py index 068335ae32..ec48a43f80 100644 --- a/dvc/external_repo.py +++ b/dvc/external_repo.py @@ -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: diff --git a/tests/func/test_import.py b/tests/func/test_import.py index c4fa1dc179..65ca99b56d 100644 --- a/tests/func/test_import.py +++ b/tests/func/test_import.py @@ -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")