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
feat(update): index uncommitted work with repowise update --working-tree (#3095)
Raghav Chamadiyae54bfe62f013
diff --git a/docs/reference/CLI_REFERENCE.md b/docs/reference/CLI_REFERENCE.mdindex ece8b2eb9..b7bef8661 100644--- a/docs/reference/CLI_REFERENCE.md+++ b/docs/reference/CLI_REFERENCE.md@@ -269,6 +269,7 @@ See [WORKTREES.md](../scale/WORKTREES.md).| `--no-workspace` | Force single-repo mode (handy when running from a workspace root) || `--repo` | Update a specific workspace repo by alias || `--index-only` | Refresh the index only, skip doc regeneration for this run. In workspace mode, forces every stale repo to index-only. |+| `--working-tree` | Also index uncommitted work (staged, unstaged and untracked files) on top of the commits since the last sync, so a rename you have not committed yet shows up in the graph. Off by default, so hooks and plain `update` stay anchored to commits. In workspace mode a repo with uncommitted changes counts as stale and is updated the same way. `repowise watch` always does this. || `--docs` / `--no-docs` | Regenerate wiki pages for changed files, or skip doc regeneration entirely. Works in workspace mode too: `--docs` fans out to every stale repo's docs update (each needs an LLM provider/key configured, or pass `--provider`), and `--no-docs` forces index-only across the workspace. Without either flag each repo follows its own `docs_enabled`. || `--full` | Upgrade a fast (`--mode fast`) index to a full one, see below. Single-repo only; errors in workspace mode. || `--no-cost-tracking` | Don't record LLM spend for this run |@@ -290,6 +291,7 @@ Over MCP, an ordinary tool response carries a **compact projection** of this objrepowise update # diff since last syncrepowise update --dry-run # previewrepowise update --since v1.0.0 # diff from a tag+repowise update --working-tree # include uncommitted editsrepowise update --reasoning off # one-off supported-provider thinking-off runrepowise update --workspace # all workspace repos (docs where enabled, incl. first-time indexing)repowise update --workspace --docs # force docs regeneration across every stale repodiff --git a/packages/cli/src/repowise/cli/commands/update_cmd/command.py b/packages/cli/src/repowise/cli/commands/update_cmd/command.pyindex 894502a8b..6344f37fe 100644--- a/packages/cli/src/repowise/cli/commands/update_cmd/command.py+++ b/packages/cli/src/repowise/cli/commands/update_cmd/command.py@@ -320,6 +320,17 @@ def _surface_reindex_recommendation(repo_path, verdict, *, emitter: Any, dry_run"iteration on extractors / resolvers without spending tokens."),)+ "--working-tree",+ "include_working_tree",+ is_flag=True,+ default=False,+ help=(+ "Also index uncommitted work (staged, unstaged and untracked files) on "+ "top of the commits since the last sync. In a workspace, a repo with "+ "uncommitted changes counts as stale and is updated the same way."+ ),+)@click.option("--docs/--no-docs","docs_flag",@@ -416,6 +427,7 @@ def update_command(no_cost_tracking: bool = False,verbose: bool = False,progress: str = "rich",+ include_working_tree: bool = False,) -> None:"""Incrementally update wiki pages for files changed since last sync.@@ -445,6 +457,7 @@ def update_command(no_cost_tracking=no_cost_tracking,verbose=verbose,progress=progress,+ include_working_tree=include_working_tree,)@@ -641,7 +654,8 @@ def run_update(a webhook, a manual sync — and indexing a half-finished edit under those isnot what the user asked for. ``repowise watch`` sets it: watching for filesaves and then only ever diffing commit-to-commit is what made the watcher- a no-op until you committed.+ a no-op until you committed. ``repowise update --working-tree`` sets it on+ request."""start = time.monotonic()# Per-stage wall clock for this run, written to ``state.json`` by every path@@ -709,6 +723,7 @@ def run_update(concurrency=concurrency,no_cost_tracking=no_cost_tracking,progress=progress,+ include_working_tree=include_working_tree,)except Exception as exc:if emitter is not None:diff --git a/packages/cli/src/repowise/cli/commands/update_cmd/workspace.py b/packages/cli/src/repowise/cli/commands/update_cmd/workspace.pyindex 463bdc4f6..39892cfc9 100644--- a/packages/cli/src/repowise/cli/commands/update_cmd/workspace.py+++ b/packages/cli/src/repowise/cli/commands/update_cmd/workspace.py@@ -62,6 +62,7 @@ def _workspace_update(concurrency: int = 10,no_cost_tracking: bool = False,progress: str = "rich",+ include_working_tree: bool = False,) -> None:"""Update stale repos in a workspace.@@ -78,6 +79,7 @@ def _workspace_update("""from repowise.cli.helpers import load_statefrom repowise.core.docs_mode import resolve_docs_mode+ from repowise.core.ingestion.change_detector import has_working_tree_changesfrom repowise.core.repo_config import config_fingerprintfrom repowise.core.workspace import (check_repo_staleness,@@ -125,10 +127,16 @@ def _workspace_update())is_stale = is_stale or config_stale+ dirty = bool(+ indexed and not is_stale and include_working_tree and has_working_tree_changes(abs_path)+ )+ is_stale = is_stale or dirtyif not indexed:status = "[dim]not indexed[/dim]"elif config_stale and not behind:status = "[yellow]config changed[/yellow]"+ elif dirty:+ status = "[yellow]uncommitted changes[/yellow]"elif is_stale:status = f"[yellow]{behind} new commit(s)[/yellow]"else:@@ -218,6 +226,7 @@ def _workspace_update(concurrency=concurrency,no_cost_tracking=no_cost_tracking,progress=progress,+ include_working_tree=include_working_tree,)return@@ -232,6 +241,7 @@ def _workspace_update(ws_config,repo_filter=repo_alias,dry_run=False,+ include_working_tree=include_working_tree,on_repo_start=_on_start,on_repo_done=_print_repo_result,)@@ -358,6 +368,7 @@ def _workspace_docs_update(concurrency: int,no_cost_tracking: bool,progress: str,+ include_working_tree: bool = False,) -> None:"""Update a workspace where at least one stale repo wants docs.@@ -407,6 +418,7 @@ def _workspace_docs_update(only_aliases=core_aliases,run_hooks=False,dry_run=False,+ include_working_tree=include_working_tree,on_repo_start=_on_start,on_repo_done=_print_repo_result,)@@ -444,6 +456,7 @@ def _workspace_docs_update(# corrupt it. The per-repo rich output goes to stderr there.progress="rich",skip_cross_repo_hooks=True,+ include_working_tree=include_working_tree,)except Exception as exc:docs_failed += 1diff --git a/tests/unit/cli/test_update_working_tree.py b/tests/unit/cli/test_update_working_tree.pynew file mode 100644index 000000000..efe806032--- /dev/null+++ b/tests/unit/cli/test_update_working_tree.py@@ -0,0 +1,106 @@+"""``repowise update --working-tree`` indexes uncommitted work."""++from __future__ import annotations++import asyncio+from pathlib import Path++from click.testing import CliRunner+from sqlalchemy import select++from repowise.cli.commands.update_cmd import command as update_command_mod+from repowise.cli.main import cli+from tests.unit.cli.test_update_e2e import _git, _index_full, _make_git_repo+++def _capture_run_update(monkeypatch) -> dict:+ seen: dict = {}++ def _fake(**kwargs):+ seen.update(kwargs)++ monkeypatch.setattr(update_command_mod, "run_update", _fake)+ return seen+++def test_working_tree_flag_reaches_run_update(monkeypatch, tmp_path: Path) -> None:+ seen = _capture_run_update(monkeypatch)+ result = CliRunner().invoke(cli, ["update", str(tmp_path), "--working-tree"])+ assert result.exit_code == 0, result.output+ assert seen["include_working_tree"] is True+++def test_update_without_flag_stays_commit_anchored(monkeypatch, tmp_path: Path) -> None:+ seen = _capture_run_update(monkeypatch)+ result = CliRunner().invoke(cli, ["update", str(tmp_path)])+ assert result.exit_code == 0, result.output+ assert seen["include_working_tree"] is False+++async def _symbols_and_call_edges(repo: Path) -> tuple[set[str], set[tuple[str, str]]]:+ from repowise.core.persistence import create_engine, create_session_factory, get_session+ from repowise.core.persistence.database import resolve_db_url+ from repowise.core.persistence.models import GraphEdge, GraphNode++ engine = create_engine(resolve_db_url(repo))+ try:+ sf = create_session_factory(engine)+ async with get_session(sf) as session:+ nodes = {n.node_id for n in (await session.execute(select(GraphNode))).scalars()}+ edges = {+ (e.source_node_id, e.target_node_id)+ for e in (await session.execute(select(GraphEdge))).scalars()+ if e.edge_type == "calls"+ }+ return nodes, edges+ finally:+ await engine.dispose()+++def test_uncommitted_rename_is_indexed_with_working_tree(tmp_path: Path) -> None:+ from repowise.cli.helpers import save_state++ repo = _make_git_repo(tmp_path)+ _index_full(repo)+ head = _git(repo, "rev-parse", "HEAD")+ save_state(repo, {"last_sync_commit": head, "docs_enabled": False})++ # Rename the function and its caller's call site, without committing.+ (repo / "a.py").write_text("def alpha_renamed():\n return 1\n")+ (repo / "b.py").write_text(+ "from a import alpha_renamed\n\n\ndef beta():\n return alpha_renamed() + 1\n"+ )++ result = CliRunner().invoke(cli, ["update", str(repo), "--no-workspace", "--working-tree"])+ assert result.exit_code == 0, result.output++ nodes, calls = asyncio.run(_symbols_and_call_edges(repo))+ assert "a.py::alpha_renamed" in nodes+ assert "a.py::alpha" not in nodes+ assert ("b.py::beta", "a.py::alpha_renamed") in calls+ assert _git(repo, "rev-parse", "HEAD") == head+++def test_workspace_update_indexes_uncommitted_work_with_working_tree(+ tmp_path: Path, monkeypatch+) -> None:+ from repowise.cli.helpers import save_state+ from tests.unit.cli.test_workspace_docs_pointer import _make_workspace++ repo = _make_workspace(tmp_path)+ _index_full(repo)+ save_state(repo, {"last_sync_commit": _git(repo, "rev-parse", "HEAD"), "docs_enabled": False})+ monkeypatch.chdir(repo)+ # Records the indexed head in the workspace config, so only the edit below is new.+ assert CliRunner().invoke(cli, ["update", "--workspace"]).exit_code == 0++ (repo / "a.py").write_text("def alpha_renamed():\n return 1\n")++ plain = CliRunner().invoke(cli, ["update", "--workspace"])+ assert plain.exit_code == 0, plain.output+ assert "All repos are up to date" in plain.output++ result = CliRunner().invoke(cli, ["update", "--workspace", "--working-tree"])+ assert result.exit_code == 0, result.output+ nodes, _ = asyncio.run(_symbols_and_call_edges(repo))+ assert "a.py::alpha_renamed" in nodes