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): skip git-ignored manifests when discovering third-party packages (#3894)

Raghav Chamadiya7d784a479bf8
diff --git a/packages/core/src/repowise/core/ingestion/external_systems/__init__.py b/packages/core/src/repowise/core/ingestion/external_systems/__init__.py
index cfcf7d680..b028709da 100644
--- a/packages/core/src/repowise/core/ingestion/external_systems/__init__.py
+++ b/packages/core/src/repowise/core/ingestion/external_systems/__init__.py
@@ -123,9 +123,13 @@ def _drop_first_party(
def _discover(repo_root: Path) -> list[Path]:
"""Walk the repo (depth ≤ 4) collecting recognised manifest files."""
from repowise.core.fs_walk import PRUNED_DIRS, walk_repo
+ from repowise.core.ingestion.traverser import load_gitignore_spec
seen: list[Path] = []
root = Path(repo_root)
+ # walk_repo reads no ignore files: without this, a manifest in a local
+ # worktree or scratch dir that git status cannot see declared packages.
+ ignore = load_gitignore_spec(root)
# The historical depth cap was a *post-hoc* filter on an unbounded
# ``rglob("*")`` — the walk itself still descended into everything.
# walk_repo prunes junk dirs and nested git repos at traversal time;
@@ -134,13 +138,20 @@ def _discover(repo_root: Path) -> list[Path]:
# Historical skip list included target/dist/build — preserve it on top
# of the shared never-source set.
prune = PRUNED_DIRS | {"target", "dist", "build"}
- for dirpath, dirnames, filenames in walk_repo(root, prune_dirs=prune):
+ # Ignored directories match with a trailing slash, as git matches them.
+ for dirpath, dirnames, filenames in walk_repo(
+ root,
+ prune_dirs=prune,
+ prune=lambda d: ignore.match_file(f"{d.relative_to(root).as_posix()}/"),
+ ):
if len(dirpath.relative_to(root).parts) >= 3:
dirnames[:] = []
- for fname in filenames:
- path = dirpath / fname
- if _parser_for(path) is not None:
- seen.append(path)
+ seen.extend(
+ dirpath / fname
+ for fname in filenames
+ if _parser_for(dirpath / fname) is not None
+ and not ignore.match_file((dirpath / fname).relative_to(root).as_posix())
+ )
return seen
diff --git a/tests/unit/ingestion/external_systems/test_npm.py b/tests/unit/ingestion/external_systems/test_npm.py
index 69b3e8de0..0d6a9ba06 100644
--- a/tests/unit/ingestion/external_systems/test_npm.py
+++ b/tests/unit/ingestion/external_systems/test_npm.py
@@ -129,3 +129,15 @@ def test_pnpm_workspace_deps_not_external(tmp_path):
names = {r.name for r in extract_external_systems(tmp_path)}
assert names == {"vitest", "zod"}
+
+
+def test_discovery_skips_manifests_git_ignores(tmp_path):
+ """A manifest git status cannot see declares nothing: local worktrees, scratch dirs."""
+ (tmp_path / ".gitignore").write_text(".claude/\nscratch.json\n", encoding="utf-8")
+ (tmp_path / ".git" / "info").mkdir(parents=True)
+ (tmp_path / ".git" / "info" / "exclude").write_text("local-stash/\n", encoding="utf-8")
+ _write(tmp_path, "package.json", {"dependencies": {"react": "^18"}})
+ _write(tmp_path, ".claude/worktrees/x/package.json", {"dependencies": {"lodash": "^4"}})
+ _write(tmp_path, "local-stash/demo/package.json", {"dependencies": {"remotion": "^4"}})
+ names = {r.name for r in extract_external_systems(tmp_path)}
+ assert names == {"react"}