exp save: Use pathspec to handle include_untracked.

Closes #9061
This commit is contained in:
David de la Iglesia Castro
2023-02-21 09:43:25 +01:00
parent 47208533a2
commit 3043b6588f
2 changed files with 18 additions and 1 deletions
+4 -1
View File
@@ -2,6 +2,8 @@ import logging
import os
from typing import TYPE_CHECKING, List, Optional
from pathspec import PathSpec
from dvc.scm import Git
from .exceptions import ExperimentExistsError
@@ -59,7 +61,8 @@ def save(
_, _, untracked = repo.scm.status()
if include_untracked:
untracked = [file for file in untracked if file not in include_untracked]
spec = PathSpec.from_lines("gitwildmatch", include_untracked)
untracked = [file for file in untracked if not spec.match_file(file)]
if untracked:
logger.warning(
(
+14
View File
@@ -1,3 +1,5 @@
import logging
import pytest
from funcy import first
@@ -91,3 +93,15 @@ def test_exp_save_include_untracked(tmp_dir, dvc, scm, exp_stage):
dvc.experiments.apply("exp-0")
assert new_file.read_text() == "exp-0"
def test_exp_save_include_untracked_warning(tmp_dir, dvc, scm, caplog, exp_stage):
"""Regression test for https://github.com/iterative/dvc/issues/9061"""
new_dir = tmp_dir / "new_dir"
new_dir.mkdir()
(new_dir / "foo").write_text("foo")
(new_dir / "bar").write_text("bar")
with caplog.at_level(logging.WARNING, logger="dvc.repo.experiments.save"):
dvc.experiments.save(name="exp", include_untracked=["new_dir"])
assert not caplog.records