From c098ff44c34a039d99c471559bdf0b9f1a167518 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saugat=20Pachhai=20=28=E0=A4=B8=E0=A5=8C=E0=A4=97=E0=A4=BE?= =?UTF-8?q?=E0=A4=A4=29?= Date: Thu, 7 Aug 2025 19:39:24 +0545 Subject: [PATCH] exp run: add test for running inside a linked worktree --- tests/func/experiments/test_experiments.py | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/func/experiments/test_experiments.py b/tests/func/experiments/test_experiments.py index 2782319563..220a6411e1 100644 --- a/tests/func/experiments/test_experiments.py +++ b/tests/func/experiments/test_experiments.py @@ -19,6 +19,7 @@ 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 +809,25 @@ 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() + + +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"