Skip to content

Commit 2b19c72

Browse files
authored
exp run: add test for running inside a linked worktree (#10834)
1 parent 28b92c8 commit 2b19c72

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/func/experiments/test_experiments.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import stat
55
from textwrap import dedent
66

7+
import dulwich
78
import pytest
89
from configobj import ConfigObj
910
from funcy import first
@@ -19,6 +20,7 @@
1920
DVC_STUDIO_URL,
2021
)
2122
from dvc.exceptions import DvcException, ReproductionError
23+
from dvc.repo import Repo
2224
from dvc.repo.experiments.exceptions import ExperimentExistsError
2325
from dvc.repo.experiments.queue.base import BaseStashQueue
2426
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
808810
dvc.stage.add(cmd="echo foo", deps=[dep], name="foo")
809811

810812
assert dvc.experiments.run()
813+
814+
815+
@pytest.mark.skipif(dulwich.__version__ < (0, 24, 2), reason="requires dulwich>=0.24.2")
816+
def test_experiments_run_in_linked_git_worktree(
817+
dvc, scm, tmp_path_factory: pytest.TempPathFactory, monkeypatch
818+
):
819+
from dulwich.worktree import add_worktree
820+
821+
wt = tmp_path_factory.mktemp("worktrees") / "worktree"
822+
add_worktree(scm.dulwich.repo, wt, branch="wt-main")
823+
824+
monkeypatch.chdir(wt)
825+
826+
wt_dvc = Repo(os.fspath(wt))
827+
(wt / "foo").write_bytes(b"foo")
828+
wt_dvc.stage.add(cmd="cp foo bar", deps=["foo"], outs=["bar"], name="cp")
829+
830+
results = wt_dvc.experiments.run(name="my-exp")
831+
assert results
832+
rev = first(results)
833+
assert rev
834+
# If `bar` exists, we know that the stage was run.
835+
assert (wt / "bar").read_bytes() == b"foo"

0 commit comments

Comments
 (0)