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

Implements the `Git.Command` behaviour for `git commit`.

Supports the message (`-m`) or message-from-file (`-F`) forms, the `-a`,
`--amend`, `--allow-empty`, `--no-verify`, `--no-edit`, and `--signoff`
flags, GPG signing (`-S`/`-S<keyid>`), the `--author`, `--date`, `--fixup`,
`--squash`, `-C`, and `--cleanup` value options, and `--only` with a
pathspec.

The message is optional: with `--amend --no-edit` (or `-F`), no `-m` is
emitted.

# `t`

```elixir
@type t() :: %Git.Commands.Commit{
  all: boolean(),
  allow_empty: boolean(),
  amend: boolean(),
  author: String.t() | nil,
  cleanup: String.t() | nil,
  date: String.t() | nil,
  file: String.t() | nil,
  fixup: String.t() | nil,
  message: String.t() | nil,
  no_edit: boolean(),
  no_verify: boolean(),
  only: [String.t()],
  reuse_message: String.t() | nil,
  sign: boolean() | String.t(),
  signoff: boolean(),
  squash: String.t() | nil
}
```

# `args`

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

Returns the argument list for `git commit`.

Emits the message source (`-F <file>` when `:file` is set, otherwise
`-m <message>` when `:message` is set), followed by the enabled flags, the
value options, and the `--only` pathspec.

## Examples

    iex> Git.Commands.Commit.args(%Git.Commands.Commit{message: "test", all: true})
    ["commit", "-m", "test", "-a"]

    iex> Git.Commands.Commit.args(%Git.Commands.Commit{amend: true, no_edit: true})
    ["commit", "--amend", "--no-edit"]

    iex> Git.Commands.Commit.args(%Git.Commands.Commit{message: "m", signoff: true, author: "A U <a@u>"})
    ["commit", "-m", "m", "--signoff", "--author", "A U <a@u>"]

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

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

    iex> Git.Commands.Commit.args(%Git.Commands.Commit{fixup: "HEAD~1"})
    ["commit", "--fixup", "HEAD~1"]

# `parse_output`

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

Parses the output of `git commit`.

On success (exit code 0), parses the output into a `Git.CommitResult`
struct. On failure, returns `{:error, {stdout, exit_code}}`.

---

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