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(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.py
index 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) -> N
upgrade leaves a mixed wiki, so it keeps its current mode rather than
over-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"] = head
state["total_pages"] = outcome.total_pages
state["provider"] = provider.provider_name
state["model"] = provider.model_name
diff --git a/tests/unit/cli/test_commands.py b/tests/unit/cli/test_commands.py
index 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 pytest
from click.testing import CliRunner
from repowise.cli import __version__
+from repowise.cli.commands.generate_cmd.command import _write_state
from 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
# ---------------------------------------------------------------------------