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

Implements the `Git.Command` behaviour for `git ls-remote`.

Lists references in a remote repository. Parses the output into
a list of `Git.LsRemoteEntry` structs containing the SHA and ref name.

Symref lines (from `--symref`) are included with `sha` set to `nil`.

# `t`

```elixir
@type t() :: %Git.Commands.LsRemote{
  exit_code: boolean(),
  heads: boolean(),
  quiet: boolean(),
  refs: String.t() | nil,
  remote: String.t() | nil,
  sort: String.t() | nil,
  symref: boolean(),
  tags: boolean()
}
```

# `args`

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

Returns the argument list for `git ls-remote`.

The remote name/URL is placed after flags. The refs pattern, if given,
is appended at the end.

## Examples

    iex> Git.Commands.LsRemote.args(%Git.Commands.LsRemote{})
    ["ls-remote"]

    iex> Git.Commands.LsRemote.args(%Git.Commands.LsRemote{heads: true, tags: true})
    ["ls-remote", "--heads", "--tags"]

    iex> Git.Commands.LsRemote.args(%Git.Commands.LsRemote{remote: "origin", refs: "refs/heads/main"})
    ["ls-remote", "origin", "refs/heads/main"]

    iex> Git.Commands.LsRemote.args(%Git.Commands.LsRemote{symref: true, sort: "version:refname"})
    ["ls-remote", "--symref", "--sort=version:refname"]

# `parse_output`

```elixir
@spec parse_output(String.t(), non_neg_integer()) ::
  {:ok, [Git.LsRemoteEntry.t()]} | {:error, {String.t(), non_neg_integer()}}
```

Parses the output of `git ls-remote`.

On success (exit code 0), parses tab-separated `SHA\tref` lines into
a list of `Git.LsRemoteEntry` structs. Symref lines (prefixed with
`ref:`) are included with `sha` set to `nil`.

Exit code 2 with `--exit-code` means no matching refs and returns
`{:ok, []}`.

Returns `{:error, {stdout, exit_code}}` on other failures.

---

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