mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
exp run: add test for running inside a linked worktree (#10834)
This commit is contained in:
@@ -4,6 +4,7 @@ import os
|
||||
import stat
|
||||
from textwrap import dedent
|
||||
|
||||
import dulwich
|
||||
import pytest
|
||||
from configobj import ConfigObj
|
||||
from funcy import first
|
||||
@@ -19,6 +20,7 @@ from dvc.env import (
|
||||
DVC_STUDIO_URL,
|
||||
)
|
||||
from dvc.exceptions import DvcException, ReproductionError
|
||||
from dvc.repo import Repo
|
||||
from dvc.repo.experiments.exceptions import ExperimentExistsError
|
||||
from dvc.repo.experiments.queue.base import BaseStashQueue
|
||||
from dvc.repo.experiments.refs import CELERY_STASH
|
||||
@@ -808,3 +810,26 @@ def test_experiments_run_with_submodule_dependencies(dvc, scm, make_tmp_dir, dep
|
||||
dvc.stage.add(cmd="echo foo", deps=[dep], name="foo")
|
||||
|
||||
assert dvc.experiments.run()
|
||||
|
||||
|
||||
@pytest.mark.skipif(dulwich.__version__ < (0, 24, 2), reason="requires dulwich>=0.24.2")
|
||||
def test_experiments_run_in_linked_git_worktree(
|
||||
dvc, scm, tmp_path_factory: pytest.TempPathFactory, monkeypatch
|
||||
):
|
||||
from dulwich.worktree import add_worktree
|
||||
|
||||
wt = tmp_path_factory.mktemp("worktrees") / "worktree"
|
||||
add_worktree(scm.dulwich.repo, wt, branch="wt-main")
|
||||
|
||||
monkeypatch.chdir(wt)
|
||||
|
||||
wt_dvc = Repo(os.fspath(wt))
|
||||
(wt / "foo").write_bytes(b"foo")
|
||||
wt_dvc.stage.add(cmd="cp foo bar", deps=["foo"], outs=["bar"], name="cp")
|
||||
|
||||
results = wt_dvc.experiments.run(name="my-exp")
|
||||
assert results
|
||||
rev = first(results)
|
||||
assert rev
|
||||
# If `bar` exists, we know that the stage was run.
|
||||
assert (wt / "bar").read_bytes() == b"foo"
|
||||
|
||||
Reference in New Issue
Block a user