Git.Commands.MkTree (git v0.7.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git mktree.

Builds a tree object from ls-tree-formatted entries fed on stdin and returns its SHA, with no index or working tree. Together with hash_object and commit_tree this lets a consumer synthesize whole trees and commits purely from object SHAs (for example generated-content commits).

Reads stdin, so it needs the default Git.Runner.Forcola runner; under Git.Runner.SystemCmd it returns {:error, :stdin_unsupported}.

Summary

Functions

Returns the argument list for git mktree.

Formats the entries for git mktree's stdin as <mode> <type> <object>\t<path> lines. Empty entries feed empty stdin, which produces the empty tree.

Parses the output of git mktree.

Types

entry()

@type entry() :: %{
  mode: String.t(),
  type: String.t(),
  object: String.t(),
  path: String.t()
}

t()

@type t() :: %Git.Commands.MkTree{entries: [entry()], missing: boolean()}

Functions

args(mk_tree)

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

Returns the argument list for git mktree.

Examples

iex> Git.Commands.MkTree.args(%Git.Commands.MkTree{})
["mktree"]

iex> Git.Commands.MkTree.args(%Git.Commands.MkTree{missing: true})
["mktree", "--missing"]

input(mk_tree)

@spec input(t()) :: iodata()

Formats the entries for git mktree's stdin as <mode> <type> <object>\t<path> lines. Empty entries feed empty stdin, which produces the empty tree.

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

On success (exit code 0), returns {:ok, sha} with the trimmed tree SHA. On failure, returns {:error, {stdout, exit_code}}.