Git.Commands.Notes (git v0.4.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git notes.

Supports listing notes, showing a note for a specific ref, adding notes, appending to existing notes, removing notes, and pruning notes for unreachable objects.

Edit mode (git notes edit) is intentionally not supported because it launches an interactive editor which cannot be driven programmatically.

Summary

Functions

Returns the argument list for git notes.

Parses the output of git notes.

Types

t()

@type t() :: %Git.Commands.Notes{
  add: boolean(),
  append: boolean(),
  force: boolean(),
  list: boolean(),
  message: String.t() | nil,
  notes_ref: String.t() | nil,
  prune: boolean(),
  ref: String.t() | nil,
  remove: String.t() | nil,
  show: String.t() | nil
}

Functions

args(command)

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

Returns the argument list for git notes.

Examples

iex> Git.Commands.Notes.args(%Git.Commands.Notes{})
["notes", "list"]

iex> Git.Commands.Notes.args(%Git.Commands.Notes{show: "HEAD"})
["notes", "show", "HEAD"]

iex> Git.Commands.Notes.args(%Git.Commands.Notes{add: true, message: "my note", ref: "HEAD"})
["notes", "add", "-m", "my note", "HEAD"]

iex> Git.Commands.Notes.args(%Git.Commands.Notes{add: true, message: "note", ref: "HEAD", force: true})
["notes", "add", "-f", "-m", "note", "HEAD"]

iex> Git.Commands.Notes.args(%Git.Commands.Notes{append: true, message: "more", ref: "HEAD"})
["notes", "append", "-m", "more", "HEAD"]

iex> Git.Commands.Notes.args(%Git.Commands.Notes{remove: "HEAD"})
["notes", "remove", "HEAD"]

iex> Git.Commands.Notes.args(%Git.Commands.Notes{prune: true})
["notes", "prune"]

iex> Git.Commands.Notes.args(%Git.Commands.Notes{notes_ref: "custom"})
["notes", "--ref=custom", "list"]

parse_output(stdout, exit_code)

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

Parses the output of git notes.

  • For :list mode, parses lines of "note_sha commit_sha" into a list of maps.
  • For :show mode, returns the note content as a string.
  • For mutation modes (add, append, remove, prune), returns {:ok, :done}.