exp: fail fast in empty git repo (#8840)

This commit is contained in:
Dave Berenbaum
2023-03-14 17:16:17 +00:00
committed by GitHub
parent e73cc9b40a
commit 12955da3c3
5 changed files with 27 additions and 22 deletions
+5
View File
@@ -65,6 +65,11 @@ class Experiments:
@property
def scm(self):
from dvc.scm import SCMError
if self.repo.scm.no_commits:
raise SCMError("Empty Git repo. Add a commit to use experiments.")
return self.repo.scm
@cached_property
+4
View File
@@ -205,6 +205,7 @@ module = [
"celery.*",
"configobj.*",
"dpath.*",
"distro",
"dvc_http",
"dvc_render.*",
"dvc_ssh",
@@ -219,9 +220,12 @@ module = [
"networkx.*", # https://github.com/networkx/networkx/issues/3988
"pygtrie.*",
"pyinstrument",
"pyparsing",
"pytest_docker.plugin",
"ruamel.*",
"ruamel.yaml.*",
"shortuuid",
"shtab",
"tpi.*",
"viztracer",
"voluptuous",
-10
View File
@@ -1,16 +1,6 @@
from funcy import first
def test_diff_no_commits(tmp_dir):
from dvc.repo import Repo
from dvc.scm import Git
git = Git.init(tmp_dir.fs_path)
assert git.no_commits
assert Repo.init().experiments.diff() == {}
def test_diff_empty(tmp_dir, scm, dvc, exp_stage):
assert dvc.experiments.diff() == {"params": {}, "metrics": {}}
+18 -1
View File
@@ -13,7 +13,7 @@ from dvc.repo.experiments.exceptions import ExperimentExistsError
from dvc.repo.experiments.queue.base import BaseStashQueue
from dvc.repo.experiments.refs import CELERY_STASH
from dvc.repo.experiments.utils import exp_refs_by_rev
from dvc.scm import resolve_rev
from dvc.scm import SCMError, resolve_rev
from dvc.stage.exceptions import StageFileDoesNotExistError
from dvc.utils.serialize import PythonFileCorruptedError
from tests.scripts import COPY_SCRIPT
@@ -646,3 +646,20 @@ def test_clean(tmp_dir, scm, dvc, mocker):
clean = mocker.spy(dvc.experiments.celery_queue.celery, "clean")
dvc.experiments.clean()
clean.assert_called_once_with()
def test_experiment_no_commit(tmp_dir):
from scmrepo.git import Git
from dvc.repo import Repo
Git.init(tmp_dir.fs_path).close()
repo = Repo.init()
assert repo.scm.no_commits
try:
with pytest.raises(SCMError): # noqa: PT011
repo.experiments.ls()
finally:
repo.close()
-11
View File
@@ -41,17 +41,6 @@ def make_executor_info(**kwargs):
return ExecutorInfo(**kwargs)
@pytest.mark.vscode
def test_show_no_commits(tmp_dir):
from dvc.repo import Repo
from dvc.scm import Git
git = Git.init(tmp_dir.fs_path)
assert git.no_commits
assert Repo.init().experiments.show() == {}
@pytest.mark.vscode
def test_show_branch_and_tag_name(tmp_dir, scm, dvc, exp_stage):
with tmp_dir.branch("new/branch", new=True):