Skip to content

Commit 91f3036

Browse files
authored
output: local: use repo tree if possible (#4125)
1 parent e4dafb8 commit 91f3036

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

dvc/output/local.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from dvc.exceptions import DvcException
66
from dvc.istextfile import istextfile
77
from dvc.output.base import BaseOutput
8+
from dvc.scm.tree import is_working_tree
89
from dvc.utils import relpath
910
from dvc.utils.fs import path_isin
1011

@@ -22,6 +23,8 @@ def __init__(self, stage, path, *args, **kwargs):
2223
path = relpath(path, stage.wdir)
2324

2425
super().__init__(stage, path, *args, **kwargs)
26+
if self.is_in_repo and self.repo and is_working_tree(self.repo.tree):
27+
self.tree = self.repo.tree
2528

2629
def _parse_path(self, tree, path):
2730
parsed = urlparse(path)

tests/func/test_ignore.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,3 +364,28 @@ def test_pattern_trie_tree(tmp_dir, dvc):
364364
)
365365
== ignore_pattern_bottom
366366
)
367+
368+
369+
def test_ignore_in_added_dir(tmp_dir, dvc):
370+
tmp_dir.gen(
371+
{
372+
"dir": {
373+
"sub": {
374+
"ignored": {"content": "ignored content"},
375+
"not_ignored": "not ignored content",
376+
}
377+
},
378+
".dvcignore": "**/ignored",
379+
}
380+
)
381+
dvc.tree.__dict__.pop("dvcignore", None)
382+
383+
ignored_path = tmp_dir / "dir" / "sub" / "ignored"
384+
assert not dvc.tree.exists(PathInfo(ignored_path))
385+
assert ignored_path.exists()
386+
387+
dvc.add("dir")
388+
shutil.rmtree(ignored_path)
389+
dvc.checkout()
390+
391+
assert not ignored_path.exists()

0 commit comments

Comments
 (0)