Skip to content

Commit

Permalink
Allow references to hidden file paths
Browse files Browse the repository at this point in the history
Doorstop excludes hidden files from paths included in its
representation of the version control system files, but this
means that e.g. CI config files in a hidden folder cannot be
included in the references of an item.

This patch allows users to specify file patterns that should not
be hidden in a file (default name: .doorstop_unhidden)
  • Loading branch information
reiterative committed Sep 4, 2024
1 parent f87943e commit 870d9c6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
28 changes: 28 additions & 0 deletions doorstop/core/vcs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class BaseWorkingCopy(metaclass=ABCMeta):
def __init__(self, path):
self.path = path
self._ignores_cache: Optional[List[str]] = None
self._unhidden_cache: Optional[List[str]] = None
self._path_cache: Optional[List[Tuple[str, str, str]]] = None

@staticmethod
Expand Down Expand Up @@ -81,6 +82,21 @@ def ignores(self):
self._ignores_cache.append(pattern + "*")
yield from self._ignores_cache

@property
def unhidden(self):
"""Yield glob expressions for paths that should not be hidden."""
if self._unhidden_cache is None:
self._unhidden_cache = []
log.debug("reading and caching the unhidden patterns...")
path = os.path.join(self.path, settings.UNHIDDEN_FILEPATH)
if os.path.isfile(path):
for line in common.read_lines(path):
log.debug(f"unhiding {line}")
pattern = line.strip(" @\\/*\n")
if pattern and not pattern.startswith("#"):
self._unhidden_cache.append("*" + pattern + "*")
yield from self._unhidden_cache

@property
def paths(self):
"""Yield non-ignored paths in the working copy."""
Expand All @@ -94,6 +110,11 @@ def paths(self):
# Skip ignored paths
if self.ignored(relpath):
continue
# Don't skip unhidden paths
if self.is_unhidden(relpath):
log.debug(f"not skipping: {relpath}")
self._path_cache.append((path, filename, relpath))
continue
# Skip hidden paths
if os.path.sep + "." in os.path.sep + relpath:
continue
Expand All @@ -106,3 +127,10 @@ def ignored(self, path):
if fnmatch.fnmatch(path, pattern):
return True
return False

def is_unhidden(self, path):
"""Determine if a path matches a pattern that should not hidden."""
for pattern in self.unhidden:
if fnmatch.fnmatch(path, pattern):
return True
return False
3 changes: 3 additions & 0 deletions doorstop/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,6 @@
# Server settings
SERVER_HOST = None # '' = server not specified, None = no server in use
SERVER_PORT = 7867

# Unhidden file
UNHIDDEN_FILEPATH = ".doorstop_unhidden" # list of paths that should not be hidden

0 comments on commit 870d9c6

Please sign in to comment.