Skip to content

Commit

Permalink
repo: don't try to gitignore custom cache locations (#9883)
Browse files Browse the repository at this point in the history
If user uses some custom cache location, there is really no reason for us
to try to gitignore it, as we have no idea what he is planning to do with
that and overall it often might be sign of this being misused. Maybe we could
also have some warnings/errors, but that's out of scope for this PR.

Fixes https://github.com/iterative/studio/issues/7405
  • Loading branch information
efiop authored Aug 29, 2023
1 parent 3c2c1fe commit c290d5c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 8 additions & 4 deletions dvc/cachemgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@ def __init__(self, repo):
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}
Expand Down Expand Up @@ -103,6 +100,13 @@ def local_cache_dir(self) -> str:
"""
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.
Expand Down
6 changes: 3 additions & 3 deletions dvc/repo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

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:
Expand Down Expand Up @@ -455,8 +454,9 @@ def _ignore(self):
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)
Expand Down

0 comments on commit c290d5c

Please sign in to comment.