Skip to content

memory.git_state

memory.git_state

Shared Git working-tree status helpers.

snapshot

snapshot(repo_root: Path | str, requested_paths: Sequence[str] | None = None) -> GitStatusSnapshot

Return a classified view of the current Git working tree.

Source code in memory/git_state.py
def snapshot(repo_root: Path | str, requested_paths: Sequence[str] | None = None) -> GitStatusSnapshot:
    """Return a classified view of the current Git working tree."""

    root = Path(repo_root).resolve()
    requested = tuple(_normalize_path(path) for path in requested_paths or () if str(path).strip())
    entries = tuple(_parse_status(_git_status_output(root)))
    branch = _git_output(("branch", "--show-current"), root)
    head = _git_output(("rev-parse", "HEAD"), root)
    severity = _classify(entries, requested)
    return GitStatusSnapshot(
        branch=branch,
        head=head,
        severity=severity,
        entries=entries,
        requested_paths=requested,
        message=_message_for(severity),
    )