Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(exclude-patterns): enforce exclude_patterns in git indexer and dynamic edges (#308)
joptimusf00e7995d581
diff --git a/packages/cli/src/repowise/cli/commands/update_cmd.py b/packages/cli/src/repowise/cli/commands/update_cmd.pyindex 014537e1e..bb99f925c 100644--- a/packages/cli/src/repowise/cli/commands/update_cmd.py+++ b/packages/cli/src/repowise/cli/commands/update_cmd.py@@ -266,6 +266,17 @@ def _workspace_update(# ---------------------------------------------------------------------------+def _build_filtered_changed_paths(file_diffs: list, exclude_patterns: list[str]) -> list[str]:+ """Extract paths from file_diffs, filtering out excluded patterns."""+ paths = [fd.path for fd in file_diffs]+ if not exclude_patterns:+ return paths+ import pathspec++ spec = pathspec.PathSpec.from_lines("gitwildmatch", exclude_patterns)+ return [p for p in paths if not spec.match_file(p)]++def _rebuild_graph_and_git(repo_path: Any,file_diffs: list,@@ -290,7 +301,7 @@ def _rebuild_graph_and_git(parser = ASTParser()parsed_files: list = []source_map: dict[str, bytes] = {}- graph_builder = GraphBuilder(repo_path)+ graph_builder = GraphBuilder(repo_path, exclude_patterns=exclude_patterns)for fi in file_infos:try:@@ -325,8 +336,9 @@ def _rebuild_graph_and_git(repo_path,commit_limit=_commit_limit,follow_renames=_follow_renames,+ exclude_patterns=exclude_patterns or None,)- changed_paths = [fd.path for fd in file_diffs]+ changed_paths = _build_filtered_changed_paths(file_diffs, exclude_patterns)updated_meta = run_async(git_indexer.index_changed_files(changed_paths))git_meta_map = {m["file_path"]: m for m in updated_meta}graph_builder.update_co_change_edges(git_meta_map)diff --git a/packages/core/src/repowise/core/ingestion/git_indexer/indexer.py b/packages/core/src/repowise/core/ingestion/git_indexer/indexer.pyindex f5e2cf454..0cd84ed19 100644--- a/packages/core/src/repowise/core/ingestion/git_indexer/indexer.py+++ b/packages/core/src/repowise/core/ingestion/git_indexer/indexer.py@@ -58,12 +58,17 @@ class GitIndexer:commit_limit: int | None = None,follow_renames: bool = False,tier: GitIndexTier = GitIndexTier.FULL,+ exclude_patterns: list[str] | None = None,) -> None:self.repo_path = Path(repo_path)self.commit_limit = commit_limit or _DEFAULT_COMMIT_LIMITself.follow_renames = follow_renamesself.tier = tier+ import pathspec++ self._exclude = pathspec.PathSpec.from_lines("gitwildmatch", exclude_patterns or [])+async def index_repo(self,repo_id: str,@@ -428,7 +433,10 @@ class GitIndexer:def _get_tracked_files(self, repo: Any) -> list[str]:try:output = repo.git.ls_files()- return [f for f in output.splitlines() if f.strip()]+ paths = [f for f in output.splitlines() if f.strip()]+ if self._exclude.patterns:+ paths = [p for p in paths if not self._exclude.match_file(p)]+ return pathsexcept Exception as exc:logger.warning("Failed to list tracked files", error=str(exc))return []diff --git a/packages/core/src/repowise/core/ingestion/graph/_edges.py b/packages/core/src/repowise/core/ingestion/graph/_edges.pyindex 287b797c4..737892872 100644--- a/packages/core/src/repowise/core/ingestion/graph/_edges.py+++ b/packages/core/src/repowise/core/ingestion/graph/_edges.py@@ -79,6 +79,8 @@ class EdgesMixin:if e.source not in self._graph:continueif e.target not in self._graph:+ if self._exclude.patterns and self._exclude.match_file(e.target):+ continueself._graph.add_node(e.target)sub_type = e.edge_type or "dynamic"graph_edge_type = (diff --git a/packages/core/src/repowise/core/ingestion/graph/builder.py b/packages/core/src/repowise/core/ingestion/graph/builder.pyindex b89895e44..9f6223d4d 100644--- a/packages/core/src/repowise/core/ingestion/graph/builder.py+++ b/packages/core/src/repowise/core/ingestion/graph/builder.py@@ -40,13 +40,22 @@ class GraphBuilder(MetricsMixin, ResolveMixin, EdgesMixin, SerializeMixin, Rehydpr = builder.pagerank()"""- def __init__(self, repo_path: Path | str | None = None) -> None:+ def __init__(+ self,+ repo_path: Path | str | None = None,+ *,+ exclude_patterns: list[str] | None = None,+ ) -> None:self._graph: nx.DiGraph = nx.DiGraph()self._parsed_files: dict[str, ParsedFile] = {} # path → ParsedFileself._built = Falseself._repo_path: Path | None = Path(repo_path) if repo_path else Noneself._tsconfig_resolver: Any | None = None # TsconfigResolver (lazy import)+ import pathspec++ self._exclude = pathspec.PathSpec.from_lines("gitwildmatch", exclude_patterns or [])+# Community / flow / metric caches (invalidated on build)self._community_cache: dict[str, int] | None = Noneself._symbol_community_cache: dict[str, int] | None = Nonediff --git a/packages/core/src/repowise/core/pipeline/orchestrator.py b/packages/core/src/repowise/core/pipeline/orchestrator.pyindex b1a50866b..7219cdd5a 100644--- a/packages/core/src/repowise/core/pipeline/orchestrator.py+++ b/packages/core/src/repowise/core/pipeline/orchestrator.py@@ -247,6 +247,7 @@ async def run_pipeline(commit_depth=commit_depth,follow_renames=follow_renames,tier=git_tier,+ exclude_patterns=exclude_patterns,progress=progress,)diff --git a/packages/core/src/repowise/core/pipeline/phases/git.py b/packages/core/src/repowise/core/pipeline/phases/git.pyindex 06f7c7f2b..f31350153 100644--- a/packages/core/src/repowise/core/pipeline/phases/git.py+++ b/packages/core/src/repowise/core/pipeline/phases/git.py@@ -25,6 +25,7 @@ async def _run_git_indexing(commit_depth: int,follow_renames: bool,tier: GitIndexTier = GitIndexTier.FULL,+ exclude_patterns: list[str] | None = None,progress: ProgressCallback | None,) -> tuple[Any | None, list[dict], dict[str, dict]]:"""Run git history indexing.@@ -39,6 +40,7 @@ async def _run_git_indexing(commit_limit=commit_depth,follow_renames=follow_renames,tier=tier,+ exclude_patterns=exclude_patterns,)def _on_start(total: int) -> None:diff --git a/packages/core/src/repowise/core/pipeline/phases/ingestion.py b/packages/core/src/repowise/core/pipeline/phases/ingestion.pyindex a53078a3d..16d422115 100644--- a/packages/core/src/repowise/core/pipeline/phases/ingestion.py+++ b/packages/core/src/repowise/core/pipeline/phases/ingestion.py@@ -169,7 +169,7 @@ async def _run_ingestion(parsed_files: list[Any] = []source_map: dict[str, bytes] = {}- graph_builder = GraphBuilder(repo_path=repo_path)+ graph_builder = GraphBuilder(repo_path=repo_path, exclude_patterns=exclude_patterns)loop = asyncio.get_running_loop()workers = max(1, os.cpu_count() or 4)diff --git a/tests/unit/cli/test_commands.py b/tests/unit/cli/test_commands.pyindex 3456dec72..528b46435 100644--- a/tests/unit/cli/test_commands.py+++ b/tests/unit/cli/test_commands.py@@ -122,3 +122,27 @@ class TestErrorCases:(tmp_path / ".repowise").mkdir()result = runner.invoke(cli, ["update", str(tmp_path)])assert result.exit_code != 0+++class TestBuildFilteredChangedPaths:+ def test_excludes_matching_patterns(self):+ from unittest.mock import MagicMock++ from repowise.cli.commands.update_cmd import _build_filtered_changed_paths++ fds = [+ MagicMock(path="src/main.py"),+ MagicMock(path=".claude/config.yml"),+ MagicMock(path="tools/build.sh"),+ ]+ result = _build_filtered_changed_paths(fds, [".claude/", "tools/"])+ assert result == ["src/main.py"]++ def test_no_patterns_returns_all(self):+ from unittest.mock import MagicMock++ from repowise.cli.commands.update_cmd import _build_filtered_changed_paths++ fds = [MagicMock(path="src/main.py"), MagicMock(path=".claude/config.yml")]+ result = _build_filtered_changed_paths(fds, [])+ assert result == ["src/main.py", ".claude/config.yml"]diff --git a/tests/unit/ingestion/test_graph.py b/tests/unit/ingestion/test_graph.pyindex 34346d0e6..e36c5f9d1 100644--- a/tests/unit/ingestion/test_graph.py+++ b/tests/unit/ingestion/test_graph.py@@ -954,3 +954,28 @@ class TestGoImports:b.build()g = b.graph()assert g.has_edge("main.go", "calculator/calculator.go")+++class TestDynamicEdgeExcludeFilter:+ def _edge(self, target: str):+ from repowise.core.ingestion.dynamic_hints import DynamicEdge++ return DynamicEdge(+ source="src/main.py",+ target=target,+ edge_type="co_change",+ hint_source="git",+ weight=1.0,+ )++ def test_skips_excluded_targets(self):+ gb = GraphBuilder("/tmp/fake", exclude_patterns=[".claude/"])+ gb._graph.add_node("src/main.py")+ gb.add_dynamic_edges([self._edge(".claude/config.yml")])+ assert ".claude/config.yml" not in gb._graph++ def test_allows_non_excluded_targets(self):+ gb = GraphBuilder("/tmp/fake", exclude_patterns=[".claude/"])+ gb._graph.add_node("src/main.py")+ gb.add_dynamic_edges([self._edge("src/utils.py")])+ assert "src/utils.py" in gb._graphdiff --git a/tests/unit/test_git_indexer.py b/tests/unit/test_git_indexer.pyindex 49184c90b..9974a4e8f 100644--- a/tests/unit/test_git_indexer.py+++ b/tests/unit/test_git_indexer.py@@ -756,3 +756,25 @@ class TestBlameOwnershipComputed:assert name == "Alice"assert email == "[email protected]"assert pct == pytest.approx(0.8)+++class TestExcludePatterns:+ def test_get_tracked_files_respects_exclude_patterns(self) -> None:+ indexer = GitIndexer("/tmp/fake", exclude_patterns=[".claude/", "tools/"])++ fake_repo = MagicMock()+ fake_repo.git.ls_files.return_value = (+ "src/main.py\n.claude/config.yml\ntools/build.sh\nsrc/utils.py"+ )++ result = indexer._get_tracked_files(fake_repo)+ assert result == ["src/main.py", "src/utils.py"]++ def test_get_tracked_files_no_exclude_patterns(self) -> None:+ indexer = GitIndexer("/tmp/fake")++ fake_repo = MagicMock()+ fake_repo.git.ls_files.return_value = "src/main.py\n.claude/config.yml"++ result = indexer._get_tracked_files(fake_repo)+ assert result == ["src/main.py", ".claude/config.yml"]