PromptRunner.Git (PromptRunnerSDK v0.9.0)

Copy Markdown View Source

Git commit helpers for single-repo and multi-repo prompt runs, plus the read-only repository inspection used by the verifier and by watch.

Everything in the inspection surface uses git -C <root> rather than the :cd option so a path that does not exist reports a git error instead of raising, and nothing in it writes: not the working tree, not the index, not a local branch, and not a remote-tracking ref.

Summary

Functions

Runs a git command in root and returns {output, exit_code}.

Returns the number of commits reachable from HEAD, or nil when unavailable.

Resolves ref on remote and returns its object id, under a bounded timeout.

Returns the trimmed git status --porcelain lines for root.

Returns the upstream ref for the current branch (for example origin/main), or nil when the branch has no upstream configured.

Runs a git command in root and returns its trimmed output, or nil on failure.

Returns true when root is inside a git work tree.

Types

source()

@type source() :: PromptRunner.Plan.t() | PromptRunner.Config.t()

Functions

cmd(root, args)

@spec cmd(String.t(), [String.t()]) :: {String.t(), non_neg_integer()}

Runs a git command in root and returns {output, exit_code}.

commit_count(root)

@spec commit_count(String.t()) :: non_neg_integer() | nil

Returns the number of commits reachable from HEAD, or nil when unavailable.

commit_multi_repo(source, num, target_repos)

@spec commit_multi_repo(source(), String.t(), [{String.t(), String.t()}]) :: [
  {String.t(), term()}
]

commit_repo(project_dir, msg, num, repo_name)

@spec commit_repo(String.t(), String.t(), String.t(), String.t()) ::
  {:ok, String.t()} | {:skip, atom()} | {:error, atom()}

commit_single_repo(source, num, repo_name \\ "default", repo_path \\ nil)

@spec commit_single_repo(source(), String.t(), String.t(), String.t() | nil) ::
  {:ok, String.t()} | {:skip, atom()} | {:error, atom()}

ls_remote(root, remote, ref, timeout_ms)

@spec ls_remote(String.t(), String.t(), String.t(), timeout()) ::
  {:ok, String.t()} | {:error, term()}

Resolves ref on remote and returns its object id, under a bounded timeout.

git ls-remote is a pure query: it opens a connection, reads the remote's ref advertisement, and writes nothing. Unlike git fetch it does not create or move remote-tracking refs, so a verify clause built on it cannot alter the repository it is judging — a gate that mutates anything in its subject is a gate that can change the thing it measures.

The timeout matters because a verify clause runs after the model work is already spent: an unreachable remote must not hang the run.

Returns {:error, :ref_absent} when the remote has no such ref.

status_lines(root)

@spec status_lines(String.t()) :: {:ok, [String.t()]} | {:error, String.t()}

Returns the trimmed git status --porcelain lines for root.

An empty list means the working tree is clean.

upstream_ref(root)

@spec upstream_ref(String.t()) :: String.t() | nil

Returns the upstream ref for the current branch (for example origin/main), or nil when the branch has no upstream configured.

value(root, args)

@spec value(String.t(), [String.t()]) :: String.t() | nil

Runs a git command in root and returns its trimmed output, or nil on failure.

worktree?(root)

@spec worktree?(String.t()) :: boolean()

Returns true when root is inside a git work tree.