1+ from typing import Optional
2+
13from dvc .exceptions import DvcException
24from dvc .fs import download as fs_download
5+ from dvc .ignore import DvcIgnoreFilter
36from dvc .output import Output
7+ from dvc_objects .fs .scheme import Schemes
48
59
610class 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
0 commit comments