Git.Commands.Describe (git v0.4.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git describe.

Describes a commit using the most recent tag reachable from it. Supports various formatting options for the description output.

Summary

Functions

Returns the argument list for git describe.

Parses the output of git describe.

Types

t()

@type t() :: %Git.Commands.Describe{
  abbrev: non_neg_integer() | nil,
  all: boolean(),
  always: boolean(),
  broken: boolean(),
  candidates: non_neg_integer() | nil,
  dirty: boolean() | String.t(),
  exact_match: boolean(),
  exclude: String.t() | nil,
  first_parent: boolean(),
  long: boolean(),
  match: String.t() | nil,
  ref: String.t() | nil,
  tags: boolean()
}

Functions

args(command)

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

Returns the argument list for git describe.

Examples

iex> Git.Commands.Describe.args(%Git.Commands.Describe{})
["describe"]

iex> Git.Commands.Describe.args(%Git.Commands.Describe{tags: true, always: true})
["describe", "--tags", "--always"]

iex> Git.Commands.Describe.args(%Git.Commands.Describe{abbrev: 4, long: true})
["describe", "--long", "--abbrev=4"]

iex> Git.Commands.Describe.args(%Git.Commands.Describe{dirty: true})
["describe", "--dirty"]

iex> Git.Commands.Describe.args(%Git.Commands.Describe{dirty: "-modified"})
["describe", "--dirty=-modified"]

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

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