Skip to content

check-ignore: .dvcignore doesn't handle directory ignores properly #10722

@BlueDrink9

Description

@BlueDrink9

Bug Report

Description

Ignore patterns with a trailing slash should only apply to directories. However, (at least when paired with **), they also match to files. This does not match git behavior.

This is important for repos with a large amount of junk or derived outputs, where we want to ignore everything except very specific input folders.

Reproduce

mkdir -p /tmp/test
cd /tmp/test
git init
dvc init
mkdir -p 1/2/3
touch 1/2/shouldIgnore.txt
touch 1/2/3/shouldKeep.txt
cat <<EOF | tee .gitignore .dvcignore
# Ignore everything
1/**
# Except directories (leaves all files ignored)
!1/**/
# Don't ignore files in 3
!seq/**/3/**
EOF

dvc check-ignore -d 1/2/*
git check-ignore -v 1/2/*
dvc check-ignore -d 1/2/3/*

Expected

First check should ignore shouldIgnore.txt, but instead it is included under the rule !1/**/:

dvc check-ignore -d 1/2/*
.dvcignore:4:!1/**/	1/2/3
.dvcignore:4:!1/**/	1/2/shouldIgnore.txt

Git ignores it as expected.

git check-ignore -v 1/2/*
.gitignore:4:!1/**/	1/2/3
.gitignore:2:1/**	1/2/shouldIgnore.txt

2nd dvc check correctly includes shouldKeep.txt under the last rule.

Environment information

Output of dvc doctor:

DVC version: 3.56.0
-------------------
Platform: Python 3.12.8 on Linux-6.6.78-x86_64-with-glibc2.40
Subprojects:
	dvc_data = 3.16.7
	dvc_objects = 5.1.0
	dvc_render = 1.0.2
	dvc_task = 0.40.2
	scmrepo = 3.3.8
Supports:
	http (aiohttp = 3.10.10, aiohttp-retry = 2.8.3),
	https (aiohttp = 3.10.10, aiohttp-retry = 2.8.3)
Config:
	Global: /root/.config/dvc
	System: /root/.config/kdedefaults/dvc
Cache types: <https://error.dvc.org/no-dvc-cache>
Caches: local
Remotes: None
Workspace directory: ext4 on /dev/mapper/luks-59bb1234-ec63-4d49-a38a-f6adaef20fee
Repo: dvc, git
Repo.site_cache_dir: /var/cache/dvc/repo/35a50912b07ad0907dc968426d9e9409

Additional Information (if any):

Metadata

Metadata

Assignees

Labels

triageNeeds to be triaged

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions