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

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

Supports listing branches (default), creating a new branch, and deleting
a branch. Branch listing uses `-vv` to include upstream tracking information.

# `t`

```elixir
@type t() :: %Git.Commands.Branch{
  all: boolean(),
  create: String.t() | nil,
  delete: String.t() | nil,
  force_delete: boolean(),
  list: boolean(),
  merged: String.t() | true | nil,
  no_merged: String.t() | true | nil,
  rename: String.t() | nil,
  rename_to: String.t() | nil
}
```

# `args`

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

Returns the argument list for `git branch`.

- If `:create` is set, builds `git branch <name>`.
- If `:delete` is set, builds `git branch -d <name>` (or `-D` with `force_delete: true`).
- Otherwise, lists branches with `-vv` and optionally `--all`.

## Examples

    iex> Git.Commands.Branch.args(%Git.Commands.Branch{})
    ["branch", "-vv"]

    iex> Git.Commands.Branch.args(%Git.Commands.Branch{create: "feat/new"})
    ["branch", "feat/new"]

    iex> Git.Commands.Branch.args(%Git.Commands.Branch{delete: "old", force_delete: true})
    ["branch", "-D", "old"]

# `parse_output`

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

Parses the output of `git branch`.

For list operations (exit 0), parses each line into a `Git.Branch` struct.
For create/delete operations (exit 0, empty output), returns `{:ok, :done}`.
On failure, returns `{:error, {stdout, exit_code}}`.

---

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