Skip to content

Commit

Permalink
feat: make it possible to disable the cache gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
vberlier committed Jun 10, 2021
1 parent b4346c5 commit ecea21b
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions beet/core/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,18 @@ class MultiCache(MatchMixin, Container[str, Cache]):

path: Path
default_cache: str
gitignore: bool

def __init__(self, directory: FileSystemPath, default_cache: str = "default"):
def __init__(
self,
directory: FileSystemPath,
default_cache: str = "default",
gitignore: bool = True,
):
super().__init__()
self.path = Path(directory).resolve()
self.default_cache = default_cache
self.gitignore = gitignore

def missing(self, key: str) -> Cache:
cache = Cache(self.path / key)
Expand Down Expand Up @@ -240,7 +247,11 @@ def flush(self):
"""Flush the modifications to the filesystem."""
for cache in self.values():
cache.flush()
if self.path.is_dir() and not (ignore := self.path / ".gitignore").is_file():
if (
self.gitignore
and self.path.is_dir()
and not (ignore := self.path / ".gitignore").is_file()
):
ignore.write_text("# Automatically created by beet\n*\n")

def __repr__(self) -> str:
Expand Down

0 comments on commit ecea21b

Please sign in to comment.