feat(6242): a repo renamed on its forge keeps its binding and shape ledger
CI & Build / Python lint (push) Successful in 3s
CI & Build / Plugin hooks (push) Successful in 14s
CI & Build / TypeScript typecheck (push) Successful in 1m13s
CI & Build / integration (push) Successful in 1m15s
CI & Build / Python tests (push) Successful in 2m8s
CI & Build / Build & push image (push) Successful in 28s

A binding and every row of its project's code-shape ledger are keyed by the
repo's remote. A rename on the forge changes the remote, so binding the new name
started an empty ledger beside the old one and left every judgment behind.

bind_repo now takes moved_from, the old remote. Its binding and the project's
ledger rows move to the new key in one transaction, and the reply says how many
shapes moved. The move is refused when:
- the old name isn't bound to that project;
- the new name is already bound;
- the project already has a ledger under the new name.

Each refusal leaves both names exactly as they were.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-22 13:53:57 -04:00
co-authored by Claude Opus 5.5
parent a07547447f
commit 5ad1df8e0f
4 changed files with 186 additions and 3 deletions
+23 -2
View File
@@ -13,7 +13,9 @@ from grimoire.services import projects as projects_svc
from grimoire.services import repo_bindings as repo_bindings_svc
async def bind_repo(repo_url: str, project_id: int, ref: str = "") -> dict:
async def bind_repo(
repo_url: str, project_id: int, ref: str = "", moved_from: str = "",
) -> dict:
"""Bind a git repository to a Grimoire project for session-start context.
After this, any session started in that repo auto-loads the project's
@@ -27,21 +29,34 @@ async def bind_repo(repo_url: str, project_id: int, ref: str = "") -> dict:
the push, not the merge. Re-binding with ref="" keeps the standing ref;
pass ref="-" to clear it back to the default branch.
A repo renamed on its forge has a new remote, and its ledger is stored
under the old one. Pass the old remote as `moved_from` and the binding and
every shape judgment move to the new name together. Binding the new name
without it starts an empty ledger beside the old one.
Args:
repo_url: the repo's git remote (e.g. the output of
`git remote get-url origin` — ssh or https form, both work).
project_id: the Grimoire project this repo represents.
ref: branch the ledger follows ("" = leave as is / default branch on
a new binding; "-" = clear to the default branch).
moved_from: the repo's remote before a rename on the forge. The
old name must be bound to this project, and the new one must be
neither bound nor holding a ledger of this project's.
"""
uid = current_user_id()
project = await projects_svc.get_project(uid, project_id)
if project is None:
raise ValueError(f"project {project_id} not found")
ref_arg = None if not ref else ("" if ref.strip() == "-" else ref)
moved = None
if moved_from:
_, moved = await repo_bindings_svc.move_binding(
uid, moved_from, repo_url, project_id,
)
binding = await repo_bindings_svc.set_binding(uid, repo_url, project_id, ref_arg)
follows = binding.ref or "the default branch"
return {
out = {
"repo_key": binding.repo_key,
"project_id": binding.project_id,
"project_title": project.title,
@@ -51,6 +66,12 @@ async def bind_repo(repo_url: str, project_id: int, ref: str = "") -> dict:
f"the ledger follows {follows}."
),
}
if moved is not None:
old_key = repo_bindings_svc.normalize_repo_key(moved_from)
out["moved_from"] = old_key
out["shapes_moved"] = moved
out["message"] += f" Moved from `{old_key}` with {moved} shape(s)."
return out
async def list_repo_bindings() -> dict: