mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
exp: fail fast in empty git repo (#8840)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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": {}}
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user