output: local: use repo tree if possible (#4125)

This commit is contained in:
Paweł Redzyński
2020-07-16 23:03:47 +03:00
committed by GitHub
parent e4dafb8552
commit 91f3036cf1
2 changed files with 28 additions and 0 deletions
+3
View File
@@ -5,6 +5,7 @@ from urllib.parse import urlparse
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
@@ -22,6 +23,8 @@ class LocalOutput(BaseOutput):
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)
+25
View File
@@ -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()