Skip to content

Commit

Permalink
exp run: git add param files that will be modified.
Browse files Browse the repository at this point in the history
Only if they are currently untracked and `--temp` or `--queue` is passed.

Closes #7842
  • Loading branch information
daavoo committed Apr 5, 2023
1 parent df09e52 commit 3564813
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
14 changes: 13 additions & 1 deletion dvc/repo/experiments/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


@locked
def run( # noqa: C901
def run( # noqa: C901, PLR0912
repo,
targets: Optional[Iterable[str]] = None,
params: Optional[Iterable[str]] = None,
Expand All @@ -36,6 +36,18 @@ def run( # noqa: C901
from dvc.utils.hydra import to_hydra_overrides

path_overrides = to_path_overrides(params)

if tmp_dir or queue:
untracked = repo.scm.untracked_files()
for path in path_overrides:
if path in untracked:
logger.debug(
"'%s' is currently untracked but will be modified by DVC. "
"Adding it to git.",
path,
)
repo.scm.add([path])

hydra_sweep = any(
x.is_sweep_override()
for param_file in path_overrides
Expand Down
16 changes: 16 additions & 0 deletions tests/func/experiments/test_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,19 @@ def test_queue_remove_done(
assert set(celery_queue.clear(success=True)) == set(success_tasks[:2])

assert celery_queue.status() == []


def test_queue_doesnt_remove_untracked_params_file(tmp_dir, dvc, scm):
"""Regression test for https://github.com/iterative/dvc/issues/7842"""
tmp_dir.gen("params.yaml", "foo: 1")
stage = dvc.run(cmd="echo ${foo}", params=["foo"], name="echo-foo")
scm.add(
[
"dvc.yaml",
"dvc.lock",
".gitignore",
]
)
scm.commit("init")
dvc.experiments.run(stage.addressing, params=["foo=2"], queue=True)
assert (tmp_dir / "params.yaml").exists()

0 comments on commit 3564813

Please sign in to comment.