Git.Commands.CommitTree (git v0.5.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git commit-tree.

Builds a commit object directly from a tree object, with zero or more parents, a message, and optional GPG signing. Returns the new commit's SHA.

Unlike git commit, this is a plumbing command: it does not touch the index, working tree, or HEAD. It is the building block for free-floating commits, e.g. commits attached only to a non-branch ref with no presence on any branch.

Summary

Functions

Returns the argument list for git commit-tree.

Parses the output of git commit-tree.

Types

t()

@type t() :: %Git.Commands.CommitTree{
  message: String.t() | nil,
  messages: [String.t()],
  no_gpg_sign: boolean(),
  parents: [String.t()],
  sign: boolean() | String.t(),
  tree: String.t()
}

Functions

args(command)

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

Returns the argument list for git commit-tree.

Examples

iex> Git.Commands.CommitTree.args(%Git.Commands.CommitTree{tree: "abc123", message: "init"})
["commit-tree", "-m", "init", "abc123"]

iex> Git.Commands.CommitTree.args(%Git.Commands.CommitTree{tree: "abc123", parents: ["def456"], message: "next"})
["commit-tree", "-p", "def456", "-m", "next", "abc123"]

iex> Git.Commands.CommitTree.args(%Git.Commands.CommitTree{tree: "abc123", parents: ["a", "b"], message: "merge"})
["commit-tree", "-p", "a", "-p", "b", "-m", "merge", "abc123"]

iex> Git.Commands.CommitTree.args(%Git.Commands.CommitTree{tree: "abc123", message: "x", sign: true})
["commit-tree", "-S", "-m", "x", "abc123"]

iex> Git.Commands.CommitTree.args(%Git.Commands.CommitTree{tree: "abc123", message: "x", sign: "ABCD1234"})
["commit-tree", "-SABCD1234", "-m", "x", "abc123"]

iex> Git.Commands.CommitTree.args(%Git.Commands.CommitTree{tree: "abc123", message: "x", no_gpg_sign: true})
["commit-tree", "--no-gpg-sign", "-m", "x", "abc123"]

iex> Git.Commands.CommitTree.args(%Git.Commands.CommitTree{tree: "abc123", messages: ["subject", "body"]})
["commit-tree", "-m", "subject", "-m", "body", "abc123"]

iex> Git.Commands.CommitTree.args(%Git.Commands.CommitTree{tree: "abc123", message: "subject", messages: ["body"]})
["commit-tree", "-m", "subject", "-m", "body", "abc123"]

parse_output(stdout, exit_code)

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

Parses the output of git commit-tree.

On success (exit code 0), returns {:ok, sha} where sha is the trimmed SHA of the new commit. On failure, returns {:error, {stdout, exit_code}}.