repo: handle rev without scm (#5822)

This part of logic used to be only used by external repo for cloned
repos, but since we now handle local repos without cloning, we don't
always pass scm instance. This PR automatically creates scm instance
for such cases.

Fixes #5590
This commit is contained in:
Ruslan Kuprieiev
2021-04-15 23:16:01 +03:00
committed by GitHub
parent 3143975437
commit 853d304ce2
2 changed files with 13 additions and 0 deletions
+4
View File
@@ -141,6 +141,7 @@ class Repo:
from dvc.repo.params import Params
from dvc.repo.plots import Plots
from dvc.repo.stage import StageLoad
from dvc.scm import SCM
from dvc.stage.cache import StageCache
from dvc.state import State, StateNoop
@@ -149,6 +150,9 @@ class Repo:
"repo_factory": repo_factory,
}
if rev and not scm:
scm = SCM(root_dir or os.curdir)
self.root_dir, self.dvc_dir, self.tmp_dir = self._get_repo_dirs(
root_dir=root_dir, scm=scm, rev=rev, uninitialized=uninitialized
)
+9
View File
@@ -182,6 +182,15 @@ def test_open_not_cached(dvc):
api.read(metric_file)
def test_open_rev(tmp_dir, scm, dvc):
tmp_dir.scm_gen("foo", "foo", commit="foo")
(tmp_dir / "foo").write_text("bar")
with api.open("foo", rev="master") as fobj:
assert fobj.read() == "foo"
@pytest.mark.parametrize("as_external", [True, False])
@pytest.mark.parametrize("remote", [pytest.lazy_fixture("ssh")], indirect=True)
@pytest.mark.parametrize(