Adds the repository-stewardship Python package (src/stewardship) with: - JSON Schemas (Draft 2020-12) for RepositoryContract, KnowledgeBase, CatalogIndex, ContextBundle, BootstrapPlan, AdoptionAssessment/Plan/Report, user config and the repoctl-result envelope. - Safe YAML I/O, path confinement, deterministic clock and canonical-JSON hashing. - validate: schema, ID uniqueness, path safety, KDB references, freshness, secret-shaped fields, shell-string detection, and Markdown frontmatter/fence/link checks. - discover/CatalogIndex with deterministic sorting and duplicate-name detection. - describe (contract-only) and context (intent-scoped ContextBundle with budgeted materialization and --strict truncation). - init: plan-then-apply bootstrap with SHA-256 plan-hash approval, no fake domain artifacts, bundled Claude skills. - adopt: assess/plan/apply/verify overlay workflow per docs/adoption-runbook.md, preserving legacy content roots and KDB, with baseline-hash re-check and rollback. - argparse-based `repoctl` CLI with human/yaml/json output and spec exit codes. - pytest suite (39 tests) covering positive/negative fixtures, discovery, context, bootstrap and adoption (including LXD- and Antivirus-shaped legacy layouts). Managed with uv (.venv), ruff clean, mypy --strict clean. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
36 lines
1.0 KiB
Python
36 lines
1.0 KiB
Python
"""Minimal read-only Git helpers used by adoption assess/plan/apply/verify.
|
|
|
|
Adoption never commits, pushes, clones or touches remotes; these helpers only ever
|
|
call read-only `git` subcommands, plus `git init` for `repoctl init --git-init`.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
|
|
def _run(args: list[str], cwd: Path) -> subprocess.CompletedProcess[str]:
|
|
return subprocess.run(
|
|
["git", *args], cwd=cwd, capture_output=True, text=True, check=False
|
|
)
|
|
|
|
|
|
def head_revision(root: Path) -> str:
|
|
result = _run(["rev-parse", "HEAD"], root)
|
|
if result.returncode != 0:
|
|
return "unborn"
|
|
return result.stdout.strip()
|
|
|
|
|
|
def is_dirty(root: Path) -> bool:
|
|
result = _run(["status", "--porcelain"], root)
|
|
return bool(result.stdout.strip())
|
|
|
|
|
|
def tracked_files(root: Path) -> set[str]:
|
|
result = _run(["ls-files"], root)
|
|
if result.returncode != 0:
|
|
return set()
|
|
return {line.strip() for line in result.stdout.splitlines() if line.strip()}
|