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(server): support git logs in worktrees (#2045)

Aman1e0fe132681d
diff --git a/packages/server/src/repowise/server/mcp_server/tool_why.py b/packages/server/src/repowise/server/mcp_server/tool_why.py
index 468392d43..e69ee2380 100644
--- a/packages/server/src/repowise/server/mcp_server/tool_why.py
+++ b/packages/server/src/repowise/server/mcp_server/tool_why.py
@@ -1882,7 +1882,7 @@ async def _git_archaeology_fallback(
# --- Layer 3: Live git log (when local repo exists) ---
git_log_results = []
local_path = getattr(repository, "local_path", None)
- if local_path and (Path(local_path) / ".git").is_dir():
+ if local_path and (Path(local_path) / ".git").exists():
git_log_results = await _run_git_log(local_path, file_path, stem)
result["git_log"] = git_log_results
diff --git a/tests/unit/server/mcp/test_recoverable_caps_wire_contracts.py b/tests/unit/server/mcp/test_recoverable_caps_wire_contracts.py
index 505631b23..d801ca379 100644
--- a/tests/unit/server/mcp/test_recoverable_caps_wire_contracts.py
+++ b/tests/unit/server/mcp/test_recoverable_caps_wire_contracts.py
@@ -834,7 +834,12 @@ async def test_why_fallback_archaeology_and_rationale_wire_recover_annotated_tai
from repowise.core.persistence.models import Repository
repository = await session.get(Repository, setup_mcp)
- repository.local_path = str(Path.cwd())
+ # A linked worktree stores `.git` as a gitdir pointer file. The live git
+ # log only needs a working tree, so this must still enable the fallback.
+ worktree_path = tmp_path / "worktree"
+ worktree_path.mkdir()
+ (worktree_path / ".git").write_text("gitdir: /tmp/repowise-test-worktree\n")
+ repository.local_path = str(worktree_path)
await session.flush()
async def sealed_git_log(*_args: Any, **_kwargs: Any) -> list[dict[str, Any]]: