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

Implements the `Git.Command` behaviour for `git sparse-checkout`.

Supports initializing, setting, adding, listing, disabling, reapplying,
and checking rules for sparse-checkout.

# `t`

```elixir
@type t() :: %Git.Commands.SparseCheckout{
  add: [String.t()],
  check_rules: boolean(),
  cone: boolean(),
  disable: boolean(),
  init: boolean(),
  list: boolean(),
  no_cone: boolean(),
  no_sparse_index: boolean(),
  reapply: boolean(),
  set: [String.t()],
  sparse_index: boolean()
}
```

# `args`

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

Returns the argument list for `git sparse-checkout`.

- If `:init` is true, builds `git sparse-checkout init [--cone] [--sparse-index]`.
- If `:set` is non-empty, builds `git sparse-checkout set [--cone] [--no-cone] <patterns...>`.
- If `:add` is non-empty, builds `git sparse-checkout add [--cone] [--no-cone] <patterns...>`.
- If `:disable` is true, builds `git sparse-checkout disable`.
- If `:reapply` is true, builds `git sparse-checkout reapply`.
- If `:check_rules` is true, builds `git sparse-checkout check-rules`.
- Otherwise, lists current patterns with `git sparse-checkout list`.

## Examples

    iex> Git.Commands.SparseCheckout.args(%Git.Commands.SparseCheckout{})
    ["sparse-checkout", "list"]

    iex> Git.Commands.SparseCheckout.args(%Git.Commands.SparseCheckout{init: true, cone: true})
    ["sparse-checkout", "init", "--cone"]

    iex> Git.Commands.SparseCheckout.args(%Git.Commands.SparseCheckout{set: ["src/", "docs/"], cone: true})
    ["sparse-checkout", "set", "--cone", "src/", "docs/"]

    iex> Git.Commands.SparseCheckout.args(%Git.Commands.SparseCheckout{add: ["tests/"]})
    ["sparse-checkout", "add", "tests/"]

    iex> Git.Commands.SparseCheckout.args(%Git.Commands.SparseCheckout{disable: true})
    ["sparse-checkout", "disable"]

    iex> Git.Commands.SparseCheckout.args(%Git.Commands.SparseCheckout{reapply: true})
    ["sparse-checkout", "reapply"]

# `parse_output`

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

Parses the output of `git sparse-checkout`.

For list operations (exit 0), returns `{:ok, [pattern]}` with one pattern
per line. For all mutation operations (exit 0), returns `{:ok, :done}`.
On failure, returns `{:error, {stdout, exit_code}}`.

---

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