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

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

Builds `git add [flags] [-- <paths>]`. Flags and a pathspec compose, so a
path can be staged together with any of `--all`, `--update`, `--force`,
`--dry-run`, `--intent-to-add`, `--renormalize`, and `--chmod`.

# `t`

```elixir
@type t() :: %Git.Commands.Add{
  all: boolean(),
  chmod: String.t() | nil,
  dry_run: boolean(),
  files: [String.t()],
  force: boolean(),
  intent_to_add: boolean(),
  renormalize: boolean(),
  update: boolean()
}
```

# `args`

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

Returns the argument list for `git add`.

Emits the enabled flags followed by the pathspec, so flags and files compose
(unlike the previous behavior, where `:all` dropped `:files`).

## Examples

    iex> Git.Commands.Add.args(%Git.Commands.Add{all: true})
    ["add", "--all"]

    iex> Git.Commands.Add.args(%Git.Commands.Add{files: ["foo.txt", "bar.txt"]})
    ["add", "foo.txt", "bar.txt"]

    iex> Git.Commands.Add.args(%Git.Commands.Add{update: true, files: ["lib"]})
    ["add", "--update", "lib"]

    iex> Git.Commands.Add.args(%Git.Commands.Add{intent_to_add: true, files: ["new.ex"]})
    ["add", "--intent-to-add", "new.ex"]

    iex> Git.Commands.Add.args(%Git.Commands.Add{chmod: "+x", files: ["run.sh"]})
    ["add", "--chmod=+x", "run.sh"]

# `parse_output`

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

Parses the output of `git add`.

On success (exit code 0), returns `{:ok, :done}`. On failure, returns
`{:error, {stdout, exit_code}}`.

---

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