Skip to content

API Reference parrot.tools.repo.git_tools

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.tools.repo.git_tools

View source

Local git history helpers: ref validation, argv builders, output parsers.

This module backs git_log / git_show / git_blame on ReadOnlyRepoToolkit (spec §3 Module 3). Everything here is module-level so it is unit-testable without a toolkit instance, and so _generate_tools() (tools/toolkit.py:537) never mistakes a helper for a tool.

Ref validation (validate_ref) is the security control this module exists for: a ref such as --upload-pack=/bin/sh handed to a git command that does not terminate its options is remote code execution (spec §7). Every git invocation below validates the ref and terminates options with --, belt and braces.

Class InvalidRefError

Raised when a caller-supplied git ref is not safe to pass to argv.

Attribute LOG_FORMAT

Attribute SHOW_FORMAT

Function parse_blame

Parse git blame --porcelain output into per-line attribution.

parse_blame(stdout: str) -> list[dict[str, object]]

Parameter Type Default Description
stdout str Raw stdout from a git blame --porcelain invocation.

Returns: list[dict[str, object]] — A list of {line, sha, author, content} dicts, one per blamed line, in final-file line order.

Function parse_log

Parse git log --format=<LOG_FORMAT> output into records.

Splits on the unit/record separators used by LOG_FORMAT rather than whitespace, since commit subjects may contain anything.

parse_log(stdout: str) -> list[dict[str, str]]

Parameter Type Default Description
stdout str Raw stdout from a git log invocation using LOG_FORMAT.

Returns: list[dict[str, str]] — A list of {sha, author, date, subject} dicts, in the order git emitted them.

Function split_show_output

Split git show --format=<SHOW_FORMAT> --stat stdout into parts.

split_show_output(stdout: str) -> tuple[dict[str, str], str]

Parameter Type Default Description
stdout str Raw stdout from the git show invocation.

Returns: tuple[dict[str, str], str] — A (header, stat_text) tuple: header is the parsed {sha, author, date, subject} mapping (empty if unparsable), and stat_text is everything after it (the --stat diffstat).

Function validate_ref

Validate a git ref before it reaches an argv list.

Rejects option-shaped refs — a ref such as --upload-pack=/bin/sh handed to a git command that does not terminate its options is remote code execution (spec §7).

validate_ref(ref: str) -> str

Parameter Type Default Description
ref str Caller-supplied ref: a sha, branch, tag, or range.

Returns: str — The ref, unchanged, when it is safe.

Raises:

  • InvalidRefError — The ref is empty, option-shaped, or contains a character outside the conservative allow-list.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally