Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(ingestion): re-include pruned directories via '!' negation rules (#3238) (#3563)

Rishabh Mishradb7c9434a9b1
diff --git a/docs/architecture/ARCHITECTURE.md b/docs/architecture/ARCHITECTURE.md
index e9b135f8e..e9b533717 100644
--- a/docs/architecture/ARCHITECTURE.md
+++ b/docs/architecture/ARCHITECTURE.md
@@ -399,7 +399,11 @@ priority order:
`dist` and `target` are pruned only when the directory itself holds no
hand-written source file (JavaScript, C/C++ and data formats do not count,
since builds emit them), so a source package with one of those names is
- indexed and a committed bundle is not
+ indexed and a committed bundle is not. Any directory that would be pruned
+ by the blocklist can be re-included by an explicit `!pattern` in root or
+ per-directory `.repowiseIgnore` or `exclude_patterns` (e.g. `!src/build/`).
+ Only explicitly named directories are re-included; sub-directories in the
+ blocklist (such as a nested `node_modules`) stay pruned unless also named.
6. Auto-detection of generated files (files with `// Code generated` headers)
7. Binary files (detected by null bytes in first 8KB)
8. Files over `max_file_size_kb` (default: 500KB)
diff --git a/packages/core/src/repowise/core/ingestion/git_indexer/indexer.py b/packages/core/src/repowise/core/ingestion/git_indexer/indexer.py
index 0dc0c8436..deaacf862 100644
--- a/packages/core/src/repowise/core/ingestion/git_indexer/indexer.py
+++ b/packages/core/src/repowise/core/ingestion/git_indexer/indexer.py
@@ -215,6 +215,7 @@ class GitIndexer:
import pathspec
+ self._exclude_patterns = exclude_patterns
self._exclude = pathspec.PathSpec.from_lines("gitwildmatch", exclude_patterns or [])
async def index_repo(
@@ -271,7 +272,9 @@ class GitIndexer:
# is not vendored, a lockfile or binary gets its history tier (counts,
# span, authors) from the shared repo-wide walk only.
indexable_files = [fp for fp in tracked_files if not _should_skip_index(fp)]
- history_files = _history_tier_files(self.repo_path, tracked_files)
+ history_files = _history_tier_files(
+ self.repo_path, tracked_files, extra_exclude_patterns=self._exclude_patterns
+ )
from concurrent.futures import ThreadPoolExecutor
@@ -628,7 +631,11 @@ class GitIndexer:
# drawn from the same tracked-file set: the parsed files miss .rst,
# LICENSE and the like.
tier_paths = (self._get_tracked_files(repo) or all_files) if all_files else None
- history_files = _history_tier_files(self.repo_path, tier_paths or changed_file_paths)
+ history_files = _history_tier_files(
+ self.repo_path,
+ tier_paths or changed_file_paths,
+ extra_exclude_patterns=self._exclude_patterns,
+ )
history_changed = history_files.intersection(changed_file_paths)
changed_file_paths = [fp for fp in changed_file_paths if not _should_skip_index(fp)]
if all_files:
diff --git a/packages/core/src/repowise/core/ingestion/git_indexer/records.py b/packages/core/src/repowise/core/ingestion/git_indexer/records.py
index 4efe847a3..49b20854a 100644
--- a/packages/core/src/repowise/core/ingestion/git_indexer/records.py
+++ b/packages/core/src/repowise/core/ingestion/git_indexer/records.py
@@ -4,7 +4,7 @@ from __future__ import annotations
import contextlib
import re
-from collections.abc import Iterable
+from collections.abc import Iterable, Sequence
from dataclasses import dataclass, field
from datetime import UTC, datetime
from pathlib import Path
@@ -632,7 +632,12 @@ def _should_skip_index(file_path: str) -> bool:
return Path(file_path).suffix.lower() not in _CODE_EXTENSIONS
-def _history_tier_files(repo_path: Path, paths: Iterable[str]) -> set[str]:
+def _history_tier_files(
+ repo_path: Path,
+ paths: Iterable[str],
+ extra_exclude_patterns: Sequence[str] | None = None,
+ extra_ignore_filename: str = ".repowiseIgnore",
+) -> set[str]:
"""The non-code files among *paths* that still get their commit history recorded.
The history tier (counts, first and last commit, authors) covers every
@@ -654,7 +659,13 @@ def _history_tier_files(repo_path: Path, paths: Iterable[str]) -> set[str]:
return False
if _BLOCKED_FILENAME_SPEC.match_file(name):
return False
- if in_blocked_dir(file_path, repo_path, output_dirs):
+ if in_blocked_dir(
+ file_path,
+ repo_path,
+ output_dirs,
+ extra_exclude_patterns=extra_exclude_patterns,
+ extra_ignore_filename=extra_ignore_filename,
+ ):
return False
return not _is_binary(repo_path / file_path)
diff --git a/packages/core/src/repowise/core/ingestion/traverser.py b/packages/core/src/repowise/core/ingestion/traverser.py
index 41b530b1a..e69acf347 100644
--- a/packages/core/src/repowise/core/ingestion/traverser.py
+++ b/packages/core/src/repowise/core/ingestion/traverser.py
@@ -16,10 +16,11 @@ It also detects monorepo structure and returns a RepoStructure.
from __future__ import annotations
import configparser
+import functools
import os
import re
import threading
-from collections.abc import Callable, Iterable, Iterator
+from collections.abc import Callable, Iterable, Iterator, Sequence
from dataclasses import dataclass, field
from datetime import datetime
from pathlib import Path
@@ -94,6 +95,7 @@ class _DirIgnore(NamedTuple):
gitignore: pathspec.PathSpec
extra: pathspec.PathSpec
+ reincluded: tuple[re.Pattern[str], ...] = ()
class _TrackedPaths(NamedTuple):
@@ -408,10 +410,22 @@ class FileTraverser:
self._blocked_patterns = _BLOCKED_FILENAME_SPEC
patterns = extra_exclude_patterns or []
self._extra_exclude = _compile_gitignore(patterns)
+ root_ignore_lines: list[str] = []
+ root_ignore_file = self.repo_root / extra_ignore_filename
+ if root_ignore_file.exists():
+ root_ignore_lines = root_ignore_file.read_text(
+ encoding="utf-8", errors="ignore"
+ ).splitlines()
+ self._reincluded_patterns: tuple[re.Pattern[str], ...] = _compile_reincluded_patterns(
+ (*root_ignore_lines, *patterns)
+ )
+ self._output_dir_cache: dict[Path, bool] = {}
# Absolute dir path -> that directory's nested ignore spec. The root is
# pre-seeded because its files are already loaded above.
self._dir_ignore_cache: dict[str, _DirIgnore] = {
- str(self.repo_root): _DirIgnore(_compile_gitignore([]), self._extra_ignore),
+ str(self.repo_root): _DirIgnore(
+ _compile_gitignore([]), self._extra_ignore, self._reincluded_patterns
+ ),
}
# Lazy: read only once a .gitignore rule matches something.
self._tracked: _TrackedPaths | None = None
@@ -589,6 +603,7 @@ class FileTraverser:
spec = _DirIgnore(
load_extra_ignore_spec(dirpath, ".gitignore"),
load_extra_ignore_spec(dirpath, self._extra_ignore_filename),
+ _load_dir_reincluded_patterns(dirpath, self._extra_ignore_filename),
)
with self._dir_ignore_lock:
# Keep the first published spec so every caller shares one object.
@@ -623,28 +638,45 @@ class FileTraverser:
tracked = self._tracked_paths()
return rel_str in (tracked.dirs if is_dir else tracked.files)
+ def _in_blocked_dir(self, rel_str: str, dir_ignore: _DirIgnore | None) -> bool:
+ return in_blocked_dir(
+ rel_str,
+ self.repo_root,
+ self._output_dir_cache,
+ reincluded_patterns=self._reincluded_patterns,
+ is_dir=True,
+ dir_ignore=dir_ignore,
+ extra_ignore_filename=self._extra_ignore_filename,
+ )
+
+ def _is_dir_ignored(self, dirname: str, rel_str: str, dir_ignore: _DirIgnore | None) -> bool:
+ dir_slash = f"{dirname}/"
+ if self._extra_ignore.match_file(f"{rel_str}/") or self._extra_exclude.match_file(
+ f"{rel_str}/"
+ ):
+ return True
+ if dir_ignore is not None and dir_ignore.extra.match_file(dir_slash):
+ return True
+ nested = dir_ignore is not None and dir_ignore.gitignore.match_file(dir_slash)
+ return self._dir_gitignored(rel_str, nested)
+
def _should_skip_dir(
self,
dirname: str,
rel_path: Path,
dir_ignore: _DirIgnore | None = None,
) -> bool:
- if dirname in _BLOCKED_DIRS:
- return True
rel_str = rel_path.as_posix()
+ # Submodules and nested repos are hard boundaries; negation rules never bypass them.
if self._is_repo_boundary(rel_str, self.repo_root / rel_path):
return True
- dir_pattern = rel_str + "/"
- if self._extra_ignore.match_file(dir_pattern) or self._extra_exclude.match_file(
- dir_pattern
- ):
- return True
- # Per-directory ignore: pattern is relative to the parent directory.
- if dir_ignore is not None and dir_ignore.extra.match_file(dirname + "/"):
+ if dirname in _BLOCKED_DIRS:
+ return self._in_blocked_dir(rel_str, dir_ignore)
+ if self._is_dir_ignored(dirname, rel_str, dir_ignore):
return True
- nested = dir_ignore is not None and dir_ignore.gitignore.match_file(dirname + "/")
- # Last, so a gitignored output tree is pruned before anything lists it.
- return self._dir_gitignored(rel_str, nested) or is_output_dir(self.repo_root / rel_path)
+ if dirname in _OUTPUT_DIR_NAMES:
+ return self._in_blocked_dir(rel_str, dir_ignore)
+ return False
def _dir_gitignored(self, rel_str: str, nested_match: bool) -> bool:
"""Whether ``.gitignore`` prunes the directory, which it may not if git tracks a file in it."""
@@ -1448,8 +1480,156 @@ def is_output_dir(abs_dir: Path) -> bool:
return False
+def _compile_reincluded_patterns(lines: Iterable[str]) -> tuple[re.Pattern[str], ...]:
+ """Compile '!' gitignore patterns to exact directory matchers.
+
+ Standard GitWildMatchPattern appends recursive descendant wildcards
+ (e.g. '.*$'), which would treat '!src/build/' as matching
+ 'src/build/node_modules/x.js'. Replacing the trailing descendant wildcard
+ with an optional trailing slash ensures only the explicitly negated
+ directory itself is re-included.
+ """
+ patterns: list[re.Pattern[str]] = []
+ for line in lines:
+ stripped = line.strip()
+ if not stripped.startswith("!"):
+ continue
+ try:
+ regex_str, _ = GitWildMatchPattern.pattern_to_regex(stripped)
+ if regex_str:
+ trimmed = re.sub(
+ r"(\(\?:\(\?P<ps_d>/\)\.\*\)\?|\(\?P<ps_d>/\)\.\*|/\.\*)\$$",
+ r"(?:/)?$",
+ regex_str,
+ )
+ patterns.append(re.compile(trimmed))
+ except GitWildMatchPatternError:
+ continue
+ return tuple(patterns)
+
+
[email protected]_cache(maxsize=1024)
+def _compile_reincluded_file(filepath: str, mtime_ns: int) -> tuple[re.Pattern[str], ...]:
+ try:
+ lines = Path(filepath).read_text(encoding="utf-8", errors="ignore").splitlines()
+ return _compile_reincluded_patterns(lines)
+ except OSError:
+ return ()
+
+
+def _load_dir_reincluded_patterns(
+ dirpath: Path, filename: str = REPOWISE_IGNORE_FILENAME
+) -> tuple[re.Pattern[str], ...]:
+ """Re-included directory patterns loaded from a directory's ignore file.
+
+ Keyed by file path and modification time so changes to nested ignore files
+ refresh automatically across traversals without stale cache hits.
+ """
+ ignore_file = dirpath / filename
+ try:
+ mtime_ns = ignore_file.stat().st_mtime_ns
+ except OSError:
+ return ()
+ return _compile_reincluded_file(str(ignore_file), mtime_ns)
+
+
+def _is_dir_reincluded(
+ rel_dir: str,
+ dirname: str,
+ root_patterns: Sequence[re.Pattern[str]],
+ parent_dir: Path | None = None,
+ dir_ignore: _DirIgnore | None = None,
+ extra_ignore_filename: str = REPOWISE_IGNORE_FILENAME,
+) -> bool:
+ """Whether directory *rel_dir* (POSIX, repo-relative) or *dirname* is re-included."""
+ if any(pat.match(rel_dir) for pat in root_patterns):
+ return True
+ if dir_ignore is not None:
+ return any(pat.match(dirname) for pat in dir_ignore.reincluded)
+ if parent_dir is not None:
+ return any(
+ pat.match(dirname)
+ for pat in _load_dir_reincluded_patterns(parent_dir, extra_ignore_filename)
+ )
+ return False
+
+
+def _check_output_dir_cached(
+ abs_dir: Path,
+ is_leaf_file: bool,
+ leaf_name: str,
+ cache: dict[Path, bool] | None,
+) -> bool:
+ """Whether *abs_dir* is an output root, using *cache* when provided."""
+ cached = None if cache is None else cache.get(abs_dir)
+ if cached is None or (
+ cached and is_leaf_file and _is_handwritten_source_name(leaf_name)
+ ):
+ cached = is_output_dir(abs_dir)
+ if cache is not None:
+ cache[abs_dir] = cached
+ return bool(cached)
+
+
+def _resolve_root_reincluded_patterns(
+ repo_root: Path | None,
+ extra_exclude_patterns: Sequence[str] | None,
+ extra_ignore_filename: str,
+) -> tuple[re.Pattern[str], ...]:
+ """Compile root negation patterns from ignore file and exclude patterns."""
+ lines: list[str] | tuple[str, ...] = ()
+ if repo_root is not None:
+ root_ignore = repo_root / extra_ignore_filename
+ if root_ignore.exists():
+ lines = root_ignore.read_text(encoding="utf-8", errors="ignore").splitlines()
+ return _compile_reincluded_patterns((*lines, *(extra_exclude_patterns or ())))
+
+
+def _is_segment_blocked(
+ dirs: Sequence[str],
+ depth: int,
+ part: str,
+ leaf_name: str,
+ is_dir: bool,
+ repo_root: Path | None,
+ root_patterns: Sequence[re.Pattern[str]],
+ dir_ignore: _DirIgnore | None,
+ extra_ignore_filename: str,
+ cache: dict[Path, bool] | None,
+) -> bool:
+ """Whether directory segment *part* at *depth* within *dirs* is blocked."""
+ is_blocked_name = part in _BLOCKED_DIRS
+ is_output_name = part in _OUTPUT_DIR_NAMES
+ if not is_blocked_name and not is_output_name:
+ return False
+
+ cur_rel = "/".join(dirs[:depth])
+ parent_dir = None
+ if repo_root is not None:
+ parent_dir = repo_root if depth == 1 else repo_root.joinpath(*dirs[:depth - 1])
+ active_dir_ignore = dir_ignore if (is_dir and depth == len(dirs)) else None
+ if _is_dir_reincluded(
+ cur_rel, part, root_patterns, parent_dir, active_dir_ignore, extra_ignore_filename
+ ):
+ return False
+
+ if is_blocked_name or repo_root is None:
+ return True
+
+ abs_dir = repo_root.joinpath(*dirs[:depth])
+ is_leaf = not is_dir and depth == len(dirs)
+ return _check_output_dir_cached(abs_dir, is_leaf, leaf_name, cache)
+
+
def in_blocked_dir(
- rel_path: str, repo_root: Path | None, cache: dict[Path, bool] | None = None
+ rel_path: str,
+ repo_root: Path | None = None,
+ cache: dict[Path, bool] | None = None,
+ extra_exclude_patterns: Sequence[str] | None = None,
+ reincluded_patterns: Sequence[re.Pattern[str]] | None = None,
+ is_dir: bool = False,
+ dir_ignore: _DirIgnore | None = None,
+ extra_ignore_filename: str = REPOWISE_IGNORE_FILENAME,
) -> bool:
"""Whether a directory on *rel_path* (POSIX, repo-relative) is blocklisted.
@@ -1459,30 +1639,40 @@ def in_blocked_dir(
once. A hand-written file directly in a directory cached as output lists
it again, since that file may be what makes it source; build output never
has such a name, so a burst of it stays cached.
+
+ A directory matched by a '!' pattern in .repowiseIgnore or
+ extra_exclude_patterns is re-included and not considered blocked, unless a
+ sub-directory beneath it is itself in the blocklist without its own
+ negation pattern.
"""
- *dirs, name = rel_path.split("/")
- for depth, part in enumerate(dirs, 1):
- if part in _BLOCKED_DIRS:
- return True
- if part not in _OUTPUT_DIR_NAMES:
- continue
- if repo_root is None:
- return True
- abs_dir = repo_root.joinpath(*dirs[:depth])
- cached = None if cache is None else cache.get(abs_dir)
- if cached is None or (
- cached and depth == len(dirs) and _is_handwritten_source_name(name)
- ):
- cached = is_output_dir(abs_dir)
- if cache is not None:
- cache[abs_dir] = cached
- if cached:
- return True
- return False
+ posix = rel_path.replace("\\", "/")
+ parts = posix.split("/")
+ dirs = parts if is_dir else parts[:-1]
+ if not dirs:
+ return False
+
+ root_pats = reincluded_patterns
+ if root_pats is None:
+ root_pats = _resolve_root_reincluded_patterns(
+ repo_root, extra_exclude_patterns, extra_ignore_filename
+ )
+
+ leaf_name = parts[-1] if not is_dir else ""
+ return any(
+ _is_segment_blocked(
+ dirs, depth, part, leaf_name, is_dir, repo_root,
+ root_pats, dir_ignore, extra_ignore_filename, cache
+ )
+ for depth, part in enumerate(dirs, 1)
+ )
def is_candidate_source_path(
- rel_path: str, repo_root: Path | None = None, cache: dict[Path, bool] | None = None
+ rel_path: str,
+ repo_root: Path | None = None,
+ cache: dict[Path, bool] | None = None,
+ extra_exclude_patterns: Sequence[str] | None = None,
+ extra_ignore_filename: str = REPOWISE_IGNORE_FILENAME,
) -> bool:
"""Whether *rel_path* is shaped like a file this repo would index.
@@ -1504,7 +1694,13 @@ def is_candidate_source_path(
parts = Path(posix).parts
if not parts:
return False
- if in_blocked_dir(posix, repo_root, cache):
+ if in_blocked_dir(
+ posix,
+ repo_root,
+ cache,
+ extra_exclude_patterns=extra_exclude_patterns,
+ extra_ignore_filename=extra_ignore_filename,
+ ):
return False
name = parts[-1]
diff --git a/tests/unit/ingestion/test_git_history_tier.py b/tests/unit/ingestion/test_git_history_tier.py
index c3e6e772b..7ecb820f2 100644
--- a/tests/unit/ingestion/test_git_history_tier.py
+++ b/tests/unit/ingestion/test_git_history_tier.py
@@ -170,3 +170,39 @@ def test_a_source_package_named_like_an_output_dir_keeps_its_history(tmp_path) -
kept = _history_tier_files(tmp_path, ["pkg/coverage/README.md", "dist/notes.md"])
assert kept == {"pkg/coverage/README.md"}
+
+
+def test_history_tier_keeps_files_in_reincluded_dir(tmp_path: Path) -> None:
+ from repowise.core.ingestion.git_indexer.records import _history_tier_files
+
+ for rel in ("src/build/README.md", "dist/notes.md"):
+ (tmp_path / rel).parent.mkdir(parents=True, exist_ok=True)
+ (tmp_path / rel).write_text("x\n", encoding="utf-8")
+
+ # Without negation rule, both output-named directories are dropped.
+ assert _history_tier_files(tmp_path, ["src/build/README.md", "dist/notes.md"]) == set()
+
+ # With !src/build/, history rows for src/build are kept.
+ (tmp_path / ".repowiseIgnore").write_text("!src/build/\n", encoding="utf-8")
+ kept = _history_tier_files(tmp_path, ["src/build/README.md", "dist/notes.md"])
+ assert kept == {"src/build/README.md"}
+
+ # Also works via extra_exclude_patterns directly
+ (tmp_path / ".repowiseIgnore").unlink()
+ kept_patterns = _history_tier_files(
+ tmp_path,
+ ["src/build/README.md", "dist/notes.md"],
+ extra_exclude_patterns=["!src/build/"],
+ )
+ assert kept_patterns == {"src/build/README.md"}
+
+ # Also works via custom extra_ignore_filename
+ (tmp_path / ".customIgnore").write_text("!src/build/\n", encoding="utf-8")
+ kept_custom = _history_tier_files(
+ tmp_path,
+ ["src/build/README.md", "dist/notes.md"],
+ extra_ignore_filename=".customIgnore",
+ )
+ assert kept_custom == {"src/build/README.md"}
+
+
diff --git a/tests/unit/ingestion/test_traverser.py b/tests/unit/ingestion/test_traverser.py
index 06c0fda1a..11e193eb4 100644
--- a/tests/unit/ingestion/test_traverser.py
+++ b/tests/unit/ingestion/test_traverser.py
@@ -231,6 +231,98 @@ class TestFileTraverser:
assert paths == {"app.py"}
+ def test_reincluded_dir_in_root_repowise_ignore_is_indexed(self, tmp_path: Path) -> None:
+ (tmp_path / "package.json").write_text('{"name":"tool","type":"module"}', encoding="utf-8")
+ (tmp_path / "src" / "build").mkdir(parents=True)
+ (tmp_path / "src" / "build" / "index.js").write_text(
+ "export function bundle(entries) { return entries.map(String); }\n", encoding="utf-8"
+ )
+ (tmp_path / "src" / "app").mkdir(parents=True)
+ (tmp_path / "src" / "app" / "main.js").write_text(
+ 'import { bundle } from "../build/index.js";\n', encoding="utf-8"
+ )
+
+ # Without negation rule, build holding only JS is pruned as an output dir.
+ paths_without = {f.path for f in FileTraverser(tmp_path).traverse()}
+ assert "src/build/index.js" not in paths_without
+
+ # With !src/build/, the directory is re-included and indexed.
+ (tmp_path / ".repowiseIgnore").write_text("!src/build/\n", encoding="utf-8")
+ paths_with = {f.path for f in FileTraverser(tmp_path).traverse()}
+ assert "src/build/index.js" in paths_with
+ assert "src/app/main.js" in paths_with
+
+ def test_reincluded_dir_in_exclude_patterns_is_indexed(self, tmp_path: Path) -> None:
+ (tmp_path / "package.json").write_text('{"name":"tool","type":"module"}', encoding="utf-8")
+ (tmp_path / "src" / "build").mkdir(parents=True)
+ (tmp_path / "src" / "build" / "index.js").write_text("export const x = 1;\n", encoding="utf-8")
+
+ paths = {
+ f.path
+ for f in FileTraverser(tmp_path, extra_exclude_patterns=["!src/build/"]).traverse()
+ }
+ assert "src/build/index.js" in paths
+
+ def test_reincluded_dir_in_nested_repowise_ignore_is_indexed(self, tmp_path: Path) -> None:
+ (tmp_path / "src" / "build").mkdir(parents=True)
+ (tmp_path / "src" / "build" / "index.js").write_text("export const x = 1;\n", encoding="utf-8")
+ (tmp_path / "src" / ".repowiseIgnore").write_text("!build/\n", encoding="utf-8")
+
+ paths = {f.path for f in FileTraverser(tmp_path).traverse()}
+ assert "src/build/index.js" in paths
+
+ def test_reincluded_dir_does_not_reopen_nested_blocked_dirs(self, tmp_path: Path) -> None:
+ (tmp_path / ".repowiseIgnore").write_text("!src/build/\n", encoding="utf-8")
+ (tmp_path / "src" / "build" / "node_modules").mkdir(parents=True)
+ (tmp_path / "src" / "build" / "index.js").write_text("export const x = 1;\n", encoding="utf-8")
+ (tmp_path / "src" / "build" / "node_modules" / "x.js").write_text(
+ "export const y = 2;\n", encoding="utf-8"
+ )
+
+ paths = {f.path for f in FileTraverser(tmp_path).traverse()}
+ assert "src/build/index.js" in paths
+ assert "src/build/node_modules/x.js" not in paths
+
+ def test_negation_cannot_bypass_nested_repo_or_submodule_boundary(self, tmp_path: Path) -> None:
+ (tmp_path / ".repowiseIgnore").write_text("!vendor/\n", encoding="utf-8")
+ nested = tmp_path / "vendor" / "nested_repo"
+ nested.mkdir(parents=True)
+ (nested / ".git").mkdir()
+ (nested / "mod.py").write_text("x = 1\n", encoding="utf-8")
+ (tmp_path / "vendor" / "lib.py").write_text("y = 2\n", encoding="utf-8")
+
+ paths = {f.path for f in FileTraverser(tmp_path).traverse()}
+ # vendor/lib.py is re-included by !vendor/
+ assert "vendor/lib.py" in paths
+ # But the nested git repository boundary is NEVER bypassed
+ assert "vendor/nested_repo/mod.py" not in paths
+
+ def test_cached_negations_refresh_on_file_creation_or_edit(self, tmp_path: Path) -> None:
+ (tmp_path / "src" / "build").mkdir(parents=True)
+ (tmp_path / "src" / "build" / "index.js").write_text("export const x = 1;\n", encoding="utf-8")
+
+ # 1st traversal: no ignore file, build directory is skipped as output
+ paths1 = {f.path for f in FileTraverser(tmp_path).traverse()}
+ assert "src/build/index.js" not in paths1
+
+ # Now create nested .repowiseIgnore in the same process
+ (tmp_path / "src" / ".repowiseIgnore").write_text("!build/\n", encoding="utf-8")
+
+ # 2nd traversal: cache refreshes and re-includes the directory
+ paths2 = {f.path for f in FileTraverser(tmp_path).traverse()}
+ assert "src/build/index.js" in paths2
+
+ def test_custom_ignore_filename_negations(self, tmp_path: Path) -> None:
+ (tmp_path / "src" / "build").mkdir(parents=True)
+ (tmp_path / "src" / "build" / "index.js").write_text("export const x = 1;\n", encoding="utf-8")
+ (tmp_path / ".customIgnore").write_text("!src/build/\n", encoding="utf-8")
+
+ paths = {
+ f.path
+ for f in FileTraverser(tmp_path, extra_ignore_filename=".customIgnore").traverse()
+ }
+ assert "src/build/index.js" in paths
+
def test_traverses_e2e_specs(self, tmp_path: Path) -> None:
"""e2e spec files are indexed so they can get a file_page (#1497).
diff --git a/tests/unit/ingestion/test_working_tree_changes.py b/tests/unit/ingestion/test_working_tree_changes.py
index 2f3f64267..75c2e54cf 100644
--- a/tests/unit/ingestion/test_working_tree_changes.py
+++ b/tests/unit/ingestion/test_working_tree_changes.py
@@ -300,3 +300,37 @@ class TestIsCandidateSourcePath:
# A hand-written file landing in it later is seen despite the cache.
(tmp_path / "dist" / "cli.py").write_text("x = 1\n", encoding="utf-8")
assert is_candidate_source_path("dist/cli.py", tmp_path, cache) is True
+
+ def test_reincluded_dir_is_candidate_source_path(self, tmp_path: Path) -> None:
+ (tmp_path / "src" / "build").mkdir(parents=True)
+ (tmp_path / "src" / "build" / "index.js").write_text("var a = 1;\n", encoding="utf-8")
+ (tmp_path / "src" / "build" / "node_modules").mkdir(parents=True)
+ (tmp_path / "src" / "build" / "node_modules" / "x.js").write_text(
+ "var b = 2;\n", encoding="utf-8"
+ )
+
+ # Without negation rule, build holding only JS is rejected as output.
+ assert is_candidate_source_path("src/build/index.js", tmp_path) is False
+
+ # With !src/build/, index.js is accepted, but node_modules/x.js remains blocked.
+ (tmp_path / ".repowiseIgnore").write_text("!src/build/\n", encoding="utf-8")
+ assert is_candidate_source_path("src/build/index.js", tmp_path) is True
+ assert is_candidate_source_path("src/build/node_modules/x.js", tmp_path) is False
+
+ # Also via extra_exclude_patterns.
+ assert (
+ is_candidate_source_path(
+ "dist/tool.js", tmp_path, extra_exclude_patterns=["!dist/"]
+ )
+ is True
+ )
+
+ # Also via custom extra_ignore_filename
+ (tmp_path / ".repowiseIgnore").unlink()
+ (tmp_path / ".customIgnore").write_text("!src/build/\n", encoding="utf-8")
+ assert (
+ is_candidate_source_path(
+ "src/build/index.js", tmp_path, extra_ignore_filename=".customIgnore"
+ )
+ is True
+ )