Skip to content

Commit

Permalink
output: local: use repo tree if possible (#4125)
Browse files Browse the repository at this point in the history
  • Loading branch information
pared authored Jul 16, 2020
1 parent e4dafb8 commit 91f3036
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dvc/output/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from dvc.exceptions import DvcException
from dvc.istextfile import istextfile
from dvc.output.base import BaseOutput
from dvc.scm.tree import is_working_tree
from dvc.utils import relpath
from dvc.utils.fs import path_isin

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

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

def _parse_path(self, tree, path):
parsed = urlparse(path)
Expand Down
25 changes: 25 additions & 0 deletions tests/func/test_ignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,28 @@ def test_pattern_trie_tree(tmp_dir, dvc):
)
== ignore_pattern_bottom
)


def test_ignore_in_added_dir(tmp_dir, dvc):
tmp_dir.gen(
{
"dir": {
"sub": {
"ignored": {"content": "ignored content"},
"not_ignored": "not ignored content",
}
},
".dvcignore": "**/ignored",
}
)
dvc.tree.__dict__.pop("dvcignore", None)

ignored_path = tmp_dir / "dir" / "sub" / "ignored"
assert not dvc.tree.exists(PathInfo(ignored_path))
assert ignored_path.exists()

dvc.add("dir")
shutil.rmtree(ignored_path)
dvc.checkout()

assert not ignored_path.exists()

0 comments on commit 91f3036

Please sign in to comment.