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(cli): preserve sync baseline when HEAD is unavailable (#1521)
Sanjay Santhanamebea52dd2ab7
diff --git a/packages/cli/src/repowise/cli/commands/generate_cmd/command.py b/packages/cli/src/repowise/cli/commands/generate_cmd/command.pyindex 1131b2721..1893e9d75 100644--- a/packages/cli/src/repowise/cli/commands/generate_cmd/command.py+++ b/packages/cli/src/repowise/cli/commands/generate_cmd/command.py@@ -356,7 +356,9 @@ def _write_state(repo_path: Path, state: dict, provider: Any, outcome: Any) -> Nupgrade leaves a mixed wiki, so it keeps its current mode rather thanover-claiming that everything is written."""- state["last_sync_commit"] = get_head_commit(repo_path)+ head = get_head_commit(repo_path)+ if head is not None:+ state["last_sync_commit"] = headstate["total_pages"] = outcome.total_pagesstate["provider"] = provider.provider_namestate["model"] = provider.model_namediff --git a/tests/unit/cli/test_commands.py b/tests/unit/cli/test_commands.pyindex 10262d89d..4cf73042e 100644--- a/tests/unit/cli/test_commands.py+++ b/tests/unit/cli/test_commands.py@@ -2,10 +2,15 @@from __future__ import annotations+from pathlib import Path+from types import SimpleNamespace+from unittest.mock import patch+import pytestfrom click.testing import CliRunnerfrom repowise.cli import __version__+from repowise.cli.commands.generate_cmd.command import _write_statefrom repowise.cli.main import cli@@ -14,6 +19,23 @@ def runner():return CliRunner()+def test_generate_state_preserves_sync_commit_when_head_is_unavailable():+ state = {"last_sync_commit": "known-good-commit"}+ outcome = SimpleNamespace(total_pages=1, remaining_template_pages=0)+ provider = SimpleNamespace(provider_name="mock", model_name="mock")++ with (+ patch(+ "repowise.cli.commands.generate_cmd.command.get_head_commit",+ return_value=None,+ ),+ patch("repowise.cli.commands.generate_cmd.command.save_state"),+ ):+ _write_state(Path("/tmp/not-a-git-repository"), state, provider, outcome)++ assert state["last_sync_commit"] == "known-good-commit"++# ---------------------------------------------------------------------------# Basic CLI tests# ---------------------------------------------------------------------------