Skip to content

Commit b6ecdb0

Browse files
Revert "fix: dvc ignore from scm root dir.\nSCM dvcignore is not required."
This reverts commit 6b36379.
1 parent 6b36379 commit b6ecdb0

2 files changed

Lines changed: 30 additions & 7 deletions

File tree

dvc/dependency/base.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
from typing import Optional
2+
13
from dvc.exceptions import DvcException
24
from dvc.fs import download as fs_download
5+
from dvc.ignore import DvcIgnoreFilter
36
from dvc.output import Output
7+
from dvc_objects.fs.scheme import Schemes
48

59

610
class DependencyDoesNotExistError(DvcException):
@@ -27,6 +31,26 @@ class Dependency(Output):
2731
IsNotFileOrDirError: type[DvcException] = DependencyIsNotFileOrDirError
2832
IsStageFileError: type[DvcException] = DependencyIsStageFileError
2933

34+
@property
35+
def dvcignore(self) -> Optional[DvcIgnoreFilter]:
36+
"""
37+
For dependencies we override the dvcignore to be part of
38+
SCM root as well. Outputs cannot be saved outside the DVC repo.
39+
However, you can have dependency for subdir DVC repos.
40+
41+
Returns:
42+
Optional[DvcIgnoreFilter]: DVC repo root or SCM root dvcignore.
43+
"""
44+
if self.fs.protocol != Schemes.LOCAL:
45+
return None
46+
47+
assert self.repo
48+
if self.fs.isin_or_eq(self.fs_path, self.repo.root_dir):
49+
return self.repo.dvcignore
50+
if self.fs.isin_or_eq(self.fs_path, self.repo.scm.root_dir):
51+
return self.repo.scm_dvcignore
52+
return None
53+
3054
def workspace_status(self) -> dict[str, str]:
3155
if self.fs.version_aware:
3256
old_fs_path = self.fs_path

dvc/repo/__init__.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,13 @@ def scm_context(self) -> "SCMContext":
330330

331331
@cached_property
332332
def dvcignore(self) -> DvcIgnoreFilter:
333-
from dvc.scm import NoSCM
333+
return DvcIgnoreFilter(self.fs, self.root_dir)
334334

335-
if isinstance(self.scm, NoSCM):
336-
root_dir = self.root_dir
337-
else:
338-
root_dir = self.scm.root_dir
339-
340-
return DvcIgnoreFilter(self.fs, root_dir)
335+
@cached_property
336+
def scm_dvcignore(self) -> DvcIgnoreFilter:
337+
if self.root_dir == self.scm.root_dir:
338+
return self.dvcignore
339+
return DvcIgnoreFilter(self.fs, self.scm.root_dir)
341340

342341
def get_rev(self):
343342
from dvc.fs import GitFileSystem, LocalFileSystem

0 commit comments

Comments
 (0)