Git.Commands.Cherry (git v0.4.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git cherry.

Finds commits in the current branch (or head) that have not yet been applied to upstream. Each commit is marked with + (not applied) or - (already applied upstream, i.e. an equivalent patch exists).

Summary

Functions

Builds the argument list for git cherry.

Parses the output of git cherry.

Types

t()

@type t() :: %Git.Commands.Cherry{
  head: String.t() | nil,
  limit: String.t() | nil,
  upstream: String.t() | nil,
  verbose: boolean()
}

Functions

args(command)

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

Builds the argument list for git cherry.

Examples

iex> Git.Commands.Cherry.args(%Git.Commands.Cherry{upstream: "main"})
["cherry", "main"]

iex> Git.Commands.Cherry.args(%Git.Commands.Cherry{upstream: "main", verbose: true})
["cherry", "-v", "main"]

iex> Git.Commands.Cherry.args(%Git.Commands.Cherry{upstream: "main", head: "feature"})
["cherry", "main", "feature"]

iex> Git.Commands.Cherry.args(%Git.Commands.Cherry{upstream: "main", head: "feature", limit: "v1.0"})
["cherry", "main", "feature", "v1.0"]

parse_output(stdout, exit_code)

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

Parses the output of git cherry.

Returns {:ok, [%Git.CherryEntry{}]} on success (exit code 0). An empty output produces an empty list.