Skip to content

Commit

Permalink
exp save: Include LOCK_FILE
Browse files Browse the repository at this point in the history
  • Loading branch information
daavoo committed Apr 3, 2023
1 parent 649ee67 commit 3a22598
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions dvc/repo/experiments/executor/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ def save(
force: bool = False,
include_untracked: Optional[List[str]] = None,
) -> ExecutorResult:
from dvc.dvcfile import LOCK_FILE
from dvc.repo import Repo

exp_hash: Optional[str] = None
Expand All @@ -283,6 +284,10 @@ def save(
include_untracked.extend(
dvc.index._plot_sources # pylint: disable=protected-access
)
# dvc repro automatically stages dvc.lock. Running redundant `git add`
# on it causes an error when exiting the detached head context.
if LOCK_FILE in dvc.scm.untracked_files():
include_untracked.append(LOCK_FILE)

try:
stages = dvc.commit([], force=True, relink=False)
Expand Down
19 changes: 18 additions & 1 deletion tests/func/experiments/test_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,22 @@ def test_untracked_top_level_files_are_included_in_exp(tmp_dir, scm, dvc):
dvc.reproduce(stage.addressing)
exp = dvc.experiments.save()
fs = scm.get_fs(exp)
for file in ["metrics.json", "params.yaml", "plots.csv"]:
for file in ["metrics.json", "params.yaml", "plots.csv", "dvc.lock"]:
assert fs.exists(file)


def test_untracked_dvclock_is_included_in_exp(tmp_dir, scm, dvc):
stage = dvc.stage.add(
cmd="echo foo",
name="foo",
)
scm.add_commit(["dvc.yaml"], message="add dvc.yaml")
dvc.reproduce(stage.addressing)

# dvc.reproduce automatically stages `dvc.lock`
# force it to be untracked
scm.reset()

exp = dvc.experiments.save()
fs = scm.get_fs(exp)
assert fs.exists("dvc.lock")

0 comments on commit 3a22598

Please sign in to comment.