Git.Commands.UpdateRef (git v0.4.0)

Copy Markdown View Source

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

Updates the object name stored in a ref safely. Supports conditional updates (compare-and-swap), reflog messages, and deletion.

Summary

Functions

Returns the argument list for git update-ref.

Parses the output of git update-ref.

Types

t()

@type t() :: %Git.Commands.UpdateRef{
  create_reflog: boolean(),
  delete: boolean(),
  message: String.t() | nil,
  new_value: String.t() | nil,
  no_deref: boolean(),
  old_value: String.t() | nil,
  ref: String.t() | nil
}

Functions

args(command)

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

Returns the argument list for git update-ref.

Examples

iex> Git.Commands.UpdateRef.args(%Git.Commands.UpdateRef{ref: "refs/heads/main", new_value: "abc123"})
["update-ref", "refs/heads/main", "abc123"]

iex> Git.Commands.UpdateRef.args(%Git.Commands.UpdateRef{ref: "refs/heads/main", new_value: "abc123", old_value: "def456"})
["update-ref", "refs/heads/main", "abc123", "def456"]

iex> Git.Commands.UpdateRef.args(%Git.Commands.UpdateRef{ref: "refs/heads/main", new_value: "abc123", message: "reset"})
["update-ref", "-m", "reset", "refs/heads/main", "abc123"]

iex> Git.Commands.UpdateRef.args(%Git.Commands.UpdateRef{ref: "refs/heads/old", delete: true})
["update-ref", "-d", "refs/heads/old"]

iex> Git.Commands.UpdateRef.args(%Git.Commands.UpdateRef{ref: "HEAD", new_value: "abc123", no_deref: true})
["update-ref", "--no-deref", "HEAD", "abc123"]

iex> Git.Commands.UpdateRef.args(%Git.Commands.UpdateRef{ref: "refs/heads/main", new_value: "abc123", create_reflog: true})
["update-ref", "--create-reflog", "refs/heads/main", "abc123"]

parse_output(stdout, exit_code)

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

Parses the output of git update-ref.

Always returns {:ok, :done} on success (exit code 0) since git update-ref produces no meaningful output. On failure, returns {:error, {stdout, exit_code}}.