Skip to content

Commit 2849379

Browse files
committed
exp run: add test for running inside a linked worktree
1 parent 5485e56 commit 2849379

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/func/experiments/test_experiments.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
DVC_STUDIO_URL,
2020
)
2121
from dvc.exceptions import DvcException, ReproductionError
22+
from dvc.repo import Repo
2223
from dvc.repo.experiments.exceptions import ExperimentExistsError
2324
from dvc.repo.experiments.queue.base import BaseStashQueue
2425
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
808809
dvc.stage.add(cmd="echo foo", deps=[dep], name="foo")
809810

810811
assert dvc.experiments.run()
812+
813+
814+
def test_experiments_run_in_linked_git_worktree(
815+
dvc, scm, tmp_path_factory: pytest.TempPathFactory, monkeypatch
816+
):
817+
from dulwich.worktree import add_worktree
818+
819+
baseline = scm.get_rev()
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+
832+
assert wt_dvc.experiments.ls() == {baseline: [("my-exp", first(results))]}
833+
assert dvc.experiments.ls() == {baseline: [("my-exp", first(results))]}

0 commit comments

Comments
 (0)