mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
exp: Preserve staged changes after experiments.
- Detach head after stashing workspace. - Use reinstate_index.
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user