Git.Commands.LsRemote (git v0.4.0)

Copy Markdown View Source

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.

Summary

Functions

Returns the argument list for git ls-remote.

Parses the output of git ls-remote.

Types

t()

@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()
}

Functions

args(command)

@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(stdout, exit_code)

@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.