Implements the Git.Command behaviour for git show-ref.
Lists references in a local repository. Supports filtering by heads or tags, verifying specific refs, abbreviated hashes, and dereferencing tags.
Uses the process dictionary to communicate the output mode from args/1
to parse_output/2.
Summary
Types
@type t() :: %Git.Commands.ShowRef{ abbrev: non_neg_integer() | nil, dereference: boolean(), exclude_existing: boolean(), hash: boolean() | non_neg_integer(), heads: boolean(), patterns: [String.t()], quiet: boolean(), tags: boolean(), verify: boolean() }
Functions
Returns the argument list for git show-ref.
Examples
iex> Git.Commands.ShowRef.args(%Git.Commands.ShowRef{})
["show-ref"]
iex> Git.Commands.ShowRef.args(%Git.Commands.ShowRef{heads: true})
["show-ref", "--heads"]
iex> Git.Commands.ShowRef.args(%Git.Commands.ShowRef{tags: true})
["show-ref", "--tags"]
iex> Git.Commands.ShowRef.args(%Git.Commands.ShowRef{verify: true, patterns: ["refs/heads/main"]})
["show-ref", "--verify", "refs/heads/main"]
iex> Git.Commands.ShowRef.args(%Git.Commands.ShowRef{hash: true})
["show-ref", "--hash"]
iex> Git.Commands.ShowRef.args(%Git.Commands.ShowRef{hash: 8})
["show-ref", "--hash=8"]
iex> Git.Commands.ShowRef.args(%Git.Commands.ShowRef{abbrev: 8})
["show-ref", "--abbrev=8"]
iex> Git.Commands.ShowRef.args(%Git.Commands.ShowRef{dereference: true})
["show-ref", "-d"]
iex> Git.Commands.ShowRef.args(%Git.Commands.ShowRef{quiet: true, verify: true, patterns: ["refs/heads/main"]})
["show-ref", "--verify", "-q", "refs/heads/main"]
@spec parse_output(String.t(), non_neg_integer()) :: {:ok, term()} | {:error, {String.t(), non_neg_integer()}}
Parses the output of git show-ref.
- Default mode (exit 0): parses "sha ref" lines into
{:ok, [%{sha, ref}]} - Hash mode (exit 0): returns
{:ok, [String.t()]}of SHA values - Verify mode (exit 0): parses "sha ref" lines; (exit 1/128):
{:ok, []} - Quiet+verify mode (exit 0):
{:ok, true}; (exit 1/128):{:ok, false} - Exit code 1 without verify: no matching refs =
{:ok, []}