diff --git a/dvc/repo/experiments/__init__.py b/dvc/repo/experiments/__init__.py index c90447cb2..6d836a02a 100644 --- a/dvc/repo/experiments/__init__.py +++ b/dvc/repo/experiments/__init__.py @@ -96,19 +96,9 @@ class Experiments: def reproduce_one( self, tmp_dir: bool = False, - machine: Optional[str] = None, **kwargs, ): """Reproduce and checkout a single (standalone) experiment.""" - if not (tmp_dir or machine): - staged, _, _ = self.scm.status(untracked_files="no") - if staged: - logger.warning( - "Your workspace contains staged Git changes which will be " - "unstaged before running this experiment." - ) - self.scm.reset() - exp_queue: "BaseStashQueue" = ( self.tempdir_queue if tmp_dir else self.workspace_queue ) diff --git a/dvc/repo/experiments/queue/base.py b/dvc/repo/experiments/queue/base.py index 3aef018e2..114aab63e 100644 --- a/dvc/repo/experiments/queue/base.py +++ b/dvc/repo/experiments/queue/base.py @@ -323,12 +323,12 @@ class BaseStashQueue(ABC): .. _Hydra Override: https://hydra.cc/docs/next/advanced/override_grammar/basic/ """ - with self.scm.detach_head(client="dvc") as orig_head: - stash_head = orig_head - if baseline_rev is None: - baseline_rev = orig_head + with self.scm.stash_workspace(reinstate_index=True) as workspace: + with self.scm.detach_head(client="dvc") as orig_head: + stash_head = orig_head + if baseline_rev is None: + baseline_rev = orig_head - with self.scm.stash_workspace() as workspace: try: if workspace: self.stash.apply(workspace) diff --git a/tests/func/experiments/test_stash_exp.py b/tests/func/experiments/test_stash_exp.py index 0a3fe3dae..1123af646 100644 --- a/tests/func/experiments/test_stash_exp.py +++ b/tests/func/experiments/test_stash_exp.py @@ -3,11 +3,15 @@ import logging import pytest from funcy import first +from dvc.exceptions import ReproductionError + -@pytest.mark.xfail(reason="TODO: https://github.com/iterative/dvc/issues/6297") @pytest.mark.parametrize("tmp", [True, False]) @pytest.mark.parametrize("staged", [True, False]) def test_deleted(tmp_dir, scm, dvc, caplog, tmp, staged): + if not tmp: + pytest.xfail("TODO: https://github.com/iterative/dvc/issues/6297") + tmp_dir.scm_gen("file", "file", commit="commit file") stage = dvc.stage.add( cmd="cat file", @@ -21,9 +25,9 @@ def test_deleted(tmp_dir, scm, dvc, caplog, tmp, staged): scm.add(["file"]) with caplog.at_level(logging.ERROR): - results = dvc.experiments.run(stage.addressing, tmp_dir=tmp) - assert "Failed to reproduce experiment" in caplog.text - assert not results + with pytest.raises(ReproductionError): + dvc.experiments.run(stage.addressing, tmp_dir=tmp) + assert "failed to reproduce 'foo'" in caplog.text assert not file.exists() @@ -51,8 +55,6 @@ def test_modified(tmp_dir, scm, dvc, caplog, tmp, staged): @pytest.mark.parametrize("tmp", [True, False]) def test_staged_new_file(tmp_dir, scm, dvc, tmp): - if not tmp: - pytest.xfail("TODO: https://github.com/iterative/dvc/issues/8998") stage = dvc.stage.add( cmd="cat file", name="foo",