Git.Commands.ForEachRef (git v0.4.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git for-each-ref.

Iterates over all refs matching the given pattern(s) and formats them according to the given format string. Useful for scripting and inspecting refs programmatically.

Summary

Functions

Returns the argument list for git for-each-ref.

Parses the output of git for-each-ref.

Types

t()

@type t() :: %Git.Commands.ForEachRef{
  contains: String.t() | nil,
  count: non_neg_integer() | nil,
  format: String.t() | nil,
  merged: String.t() | nil,
  no_merged: String.t() | nil,
  pattern: String.t() | [String.t()] | nil,
  points_at: String.t() | nil,
  sort: String.t() | [String.t()] | nil
}

Functions

args(command)

@spec args(t()) :: [String.t()]

Returns the argument list for git for-each-ref.

Examples

iex> Git.Commands.ForEachRef.args(%Git.Commands.ForEachRef{})
["for-each-ref"]

iex> Git.Commands.ForEachRef.args(%Git.Commands.ForEachRef{format: "%(refname)"})
["for-each-ref", "--format=%(refname)"]

iex> Git.Commands.ForEachRef.args(%Git.Commands.ForEachRef{sort: "-creatordate", count: 5})
["for-each-ref", "--count=5", "--sort=-creatordate"]

iex> Git.Commands.ForEachRef.args(%Git.Commands.ForEachRef{sort: ["-creatordate", "refname"]})
["for-each-ref", "--sort=-creatordate", "--sort=refname"]

iex> Git.Commands.ForEachRef.args(%Git.Commands.ForEachRef{pattern: "refs/heads/"})
["for-each-ref", "refs/heads/"]

iex> Git.Commands.ForEachRef.args(%Git.Commands.ForEachRef{pattern: ["refs/heads/", "refs/tags/"]})
["for-each-ref", "refs/heads/", "refs/tags/"]

parse_output(stdout, exit_code)

@spec parse_output(String.t(), non_neg_integer()) ::
  {:ok, String.t()} | {:error, {String.t(), non_neg_integer()}}

Parses the output of git for-each-ref.

On success (exit code 0), returns {:ok, output} where output is the trimmed string. On failure, returns {:error, {stdout, exit_code}}.