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

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

Supports switching to an existing branch, creating and switching to a new
branch (`-b`), and restoring files from the index.

# `t`

```elixir
@type t() :: %Git.Commands.Checkout{
  branch: String.t() | nil,
  create: boolean(),
  files: [String.t()]
}
```

# `args`

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

Returns the argument list for `git checkout`.

- If `:files` is non-empty, builds `git checkout -- <files...>`.
- If `:branch` is set and `:create` is true, builds `git checkout -b <branch>`.
- If `:branch` is set, builds `git checkout <branch>`.

## Examples

    iex> Git.Commands.Checkout.args(%Git.Commands.Checkout{branch: "main"})
    ["checkout", "main"]

    iex> Git.Commands.Checkout.args(%Git.Commands.Checkout{branch: "feat/new", create: true})
    ["checkout", "-b", "feat/new"]

    iex> Git.Commands.Checkout.args(%Git.Commands.Checkout{files: ["README.md", "lib/foo.ex"]})
    ["checkout", "--", "README.md", "lib/foo.ex"]

# `parse_output`

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

Parses the output of `git checkout`.

For file restore operations (exit 0), returns `{:ok, :done}`.
For branch operations (exit 0), parses into a `Git.Checkout` struct.
On failure, returns `{:error, {stdout, exit_code}}`.

---

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