diff --git a/dvc/cachemgr.py b/dvc/cachemgr.py index e94bc110f..1473c5961 100644 --- a/dvc/cachemgr.py +++ b/dvc/cachemgr.py @@ -42,11 +42,8 @@ class CacheManager: self.config = config = repo.config["cache"] self._odb = {} - default = None - if repo and repo.local_dvc_dir: - default = os.path.join(repo.local_dvc_dir, self.CACHE_DIR) - local = config.get("local") + default = self.default_local_cache_dir if local: settings = {"name": local} @@ -103,6 +100,13 @@ class CacheManager: """ return self.legacy.path + @property + def default_local_cache_dir(self) -> Optional[str]: + repo = self._repo + if repo and repo.local_dvc_dir: + return os.path.join(repo.local_dvc_dir, self.CACHE_DIR) + return None + def migrate_2_to_3(repo: "Repo", dry: bool = False): """Migrate legacy 2.x objects to 3.x cache. diff --git a/dvc/repo/__init__.py b/dvc/repo/__init__.py index fbdf98201..68fbdf22a 100644 --- a/dvc/repo/__init__.py +++ b/dvc/repo/__init__.py @@ -15,7 +15,6 @@ from typing import ( from dvc.exceptions import NotDvcRepoError, OutputNotFoundError from dvc.ignore import DvcIgnoreFilter -from dvc.utils.fs import path_isin from dvc.utils.objects import cached_property if TYPE_CHECKING: @@ -455,8 +454,9 @@ class Repo: flist = [self.config.files["local"]] if tmp_dir := self.tmp_dir: flist.append(tmp_dir) - if path_isin(self.cache.legacy.path, self.root_dir): - flist.append(self.cache.legacy.path) + + if cache_dir := self.cache.default_local_cache_dir: + flist.append(cache_dir) for file in flist: self.scm_context.ignore(file)