Skip to content

Solve ! started ignore patterns errors #5070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion dvc/ignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ def _outside_repo(self, path):
return False

def check_ignore(self, target):
# NOTE: can only be used in `dvc check-ignore`, see
# https://github.com/iterative/dvc/issues/5046
full_target = os.path.abspath(target)
if not self._outside_repo(full_target):
dirname, basename = os.path.split(os.path.normpath(full_target))
Expand All @@ -340,7 +342,11 @@ def check_ignore(self, target):
def is_ignored(self, path):
# NOTE: can't use self.check_ignore(path).match for now, see
# https://github.com/iterative/dvc/issues/4555
return self.is_ignored_dir(path) or self.is_ignored_file(path)
if os.path.isfile(path):
return self.is_ignored_file(path)
if os.path.isdir(path):
return self.is_ignored_dir(path)
return self.is_ignored_file(path) or self.is_ignored_dir(path)


def init(path):
Expand Down
4 changes: 2 additions & 2 deletions dvc/output/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,8 @@ def _validate_output_path(cls, path, stage=None):
raise cls.IsStageFileError(path)

if stage:
check = stage.repo.tree.dvcignore.check_ignore(path)
if check.match:
if stage.repo.tree.dvcignore.is_ignored(path):
check = stage.repo.tree.dvcignore.check_ignore(path)
raise cls.IsIgnoredError(check)

def _check_can_merge(self, out):
Expand Down
15 changes: 12 additions & 3 deletions tests/func/test_ignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,17 @@ def test_ignore_in_added_dir(tmp_dir, dvc):
assert not ignored_path.exists()


def test_ignored_output(tmp_dir, scm, dvc, run_copy):
tmp_dir.gen({".dvcignore": "*.log", "foo": "foo content"})
@pytest.mark.parametrize(
"ignore_patterns,raise_error",
[("*.log", True), ("*.log\n!foo.log", False)],
)
def test_ignored_output(
tmp_dir, scm, dvc, run_copy, ignore_patterns, raise_error
):
tmp_dir.gen({".dvcignore": ignore_patterns, "foo": "foo content"})

with pytest.raises(OutputIsIgnoredError):
if raise_error:
with pytest.raises(OutputIsIgnoredError):
run_copy("foo", "foo.log", name="copy")
else:
run_copy("foo", "foo.log", name="copy")
3 changes: 3 additions & 0 deletions tests/unit/output/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ def test_get_used_cache(exists, expected_message, mocker, caplog):
stage = mocker.MagicMock()
mocker.patch.object(stage, "__str__", return_value="stage: 'stage.dvc'")
mocker.patch.object(stage, "addressing", "stage.dvc")
mocker.patch.object(
stage.repo.tree.dvcignore, "is_ignored", return_value=False,
)
mocker.patch.object(
stage.repo.tree.dvcignore,
"check_ignore",
Expand Down