# `Git.Commands.ForEachRef`
[🔗](https://github.com/joshrotenberg/git_wrapper_ex/blob/main/lib/git/commands/for_each_ref.ex#L1)

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.

# `t`

```elixir
@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
}
```

# `args`

```elixir
@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`

```elixir
@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}}`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
