# `Git.Command`
[🔗](https://github.com/joshrotenberg/git_wrapper_ex/blob/main/lib/git/command.ex#L1)

Behaviour and runner for git commands.

Modules implementing this behaviour define how to build argument lists
for a specific git subcommand and how to parse the resulting output.

# `args`

```elixir
@callback args(command :: struct()) :: [String.t()]
```

Returns the argument list for this command.

# `input`
*optional* 

```elixir
@callback input(command :: struct()) :: iodata() | nil
```

Optional. Returns data to write to the command's stdin, or `nil` for none.

Implemented by commands that read stdin (for example `git mktree` and
`git update-index --index-info`). Stdin is only supported by the default
`Git.Runner.Forcola` runner; under `Git.Runner.SystemCmd` a command that
supplies input gets `{:error, :stdin_unsupported}`.

# `parse_output`

```elixir
@callback parse_output(stdout :: String.t(), exit_code :: non_neg_integer()) ::
  {:ok, term()} | {:error, term()}
```

Parses the stdout and exit code from the git process into a result.

# `run`

```elixir
@spec run(module(), struct(), Git.Config.t()) :: {:ok, term()} | {:error, term()}
```

Runs a git command.

Takes a module implementing the `Git.Command` behaviour, a command
struct, and a `Git.Config`. Builds the full argument list, executes git
through the configured `Git.Runner`, and delegates parsing to the command
module.

Execution is routed through `config.runner` (see `Git.Config` and
`Git.Runner`). The default `Git.Runner.Forcola` runs git in its own process
group and kills the group on timeout (leak-free); `Git.Runner.SystemCmd` is
the fallback when forcola is unavailable.

If the command module implements the optional `input/1` callback and returns
non-nil, that data is written to the command's stdin.

If the command exceeds the configured timeout, returns `{:error, :timeout}`.

## Examples

    Git.Command.run(Git.Commands.Status, %Git.Commands.Status{}, config)

---

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