# `Git.Commands.MkTree`
[🔗](https://github.com/joshrotenberg/git_wrapper_ex/blob/main/lib/git/commands/mktree.ex#L1)

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

# `entry`

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

# `t`

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

# `args`

```elixir
@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`

```elixir
@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`

```elixir
@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}}`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
