Git.Commands.Notes (git v0.7.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, copying a note from one object to another, merging a notes ref, removing notes, and pruning notes for unreachable objects.

:copy carries a note across a new commit (for example after a squash-merge or cherry-pick, which produce new SHAs that notes.rewriteRef does not cover). :merge folds another notes ref into the current one, which is git's remedy for concurrent writers to a single ref.

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(),
  copy: {String.t(), String.t()} | nil,
  force: boolean(),
  list: boolean(),
  merge: String.t() | nil,
  message: String.t() | nil,
  notes_ref: String.t() | nil,
  prune: boolean(),
  ref: String.t() | nil,
  remove: String.t() | nil,
  show: String.t() | nil,
  strategy: 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{copy: {"HEAD~1", "HEAD"}})
["notes", "copy", "HEAD~1", "HEAD"]

iex> Git.Commands.Notes.args(%Git.Commands.Notes{copy: {"a", "b"}, force: true})
["notes", "copy", "-f", "a", "b"]

iex> Git.Commands.Notes.args(%Git.Commands.Notes{merge: "refs/notes/other", strategy: "union"})
["notes", "merge", "-s", "union", "refs/notes/other"]

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