Git.Commands.SymbolicRef (git v0.4.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git symbolic-ref.

Reads, creates, or deletes symbolic refs. A symbolic ref is a ref that points to another ref (e.g., HEAD typically points to a branch).

Summary

Functions

Returns the argument list for git symbolic-ref.

Parses the output of git symbolic-ref.

Types

t()

@type t() :: %Git.Commands.SymbolicRef{
  delete: boolean(),
  quiet: boolean(),
  ref: String.t() | nil,
  short: boolean(),
  target: String.t() | nil
}

Functions

args(command)

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

Returns the argument list for git symbolic-ref.

Examples

iex> Git.Commands.SymbolicRef.args(%Git.Commands.SymbolicRef{ref: "HEAD"})
["symbolic-ref", "HEAD"]

iex> Git.Commands.SymbolicRef.args(%Git.Commands.SymbolicRef{ref: "HEAD", short: true})
["symbolic-ref", "--short", "HEAD"]

iex> Git.Commands.SymbolicRef.args(%Git.Commands.SymbolicRef{ref: "HEAD", target: "refs/heads/main"})
["symbolic-ref", "HEAD", "refs/heads/main"]

iex> Git.Commands.SymbolicRef.args(%Git.Commands.SymbolicRef{ref: "HEAD", delete: true})
["symbolic-ref", "--delete", "HEAD"]

iex> Git.Commands.SymbolicRef.args(%Git.Commands.SymbolicRef{ref: "HEAD", quiet: true})
["symbolic-ref", "--quiet", "HEAD"]

parse_output(stdout, exit_code)

@spec parse_output(String.t(), non_neg_integer()) ::
  {:ok, String.t() | :done} | {:error, {String.t(), non_neg_integer()}}

Parses the output of git symbolic-ref.

For reads (exit code 0 with output), returns {:ok, ref_string} trimmed. For writes and deletes (exit code 0 with no output), returns {:ok, :done}. On failure, returns {:error, {stdout, exit_code}}.