Git.Commands.NameRev (git v0.6.1)

Copy Markdown View Source

Implements the Git.Command behaviour for git name-rev.

Finds a symbolic name for a given commit. With :name_only the output is just the name; otherwise git prints the input followed by the name. With :tags only tags are used to name the commit.

Summary

Functions

Returns the argument list for git name-rev.

Parses the output of git name-rev.

Types

t()

@type t() :: %Git.Commands.NameRev{
  commit: String.t() | nil,
  name_only: boolean(),
  tags: boolean()
}

Functions

args(command)

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

Returns the argument list for git name-rev.

Examples

iex> Git.Commands.NameRev.args(%Git.Commands.NameRev{commit: "HEAD"})
["name-rev", "HEAD"]

iex> Git.Commands.NameRev.args(%Git.Commands.NameRev{commit: "HEAD", name_only: true})
["name-rev", "--name-only", "HEAD"]

iex> Git.Commands.NameRev.args(%Git.Commands.NameRev{commit: "HEAD", name_only: true, tags: true})
["name-rev", "--name-only", "--tags", "HEAD"]

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 name-rev.

On success, returns {:ok, name} with the trimmed output string. On a non-zero exit code, returns {:error, {stdout, exit_code}}.