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

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

Supports listing worktrees (default), adding a new worktree, removing
a worktree, and pruning stale worktree information. List output is
always parsed from `--porcelain` format for reliable structured data.

# `t`

```elixir
@type t() :: %Git.Commands.Worktree{
  add_branch: String.t() | nil,
  add_new_branch: String.t() | nil,
  add_path: String.t() | nil,
  detach: boolean(),
  force: boolean(),
  list: boolean(),
  lock: boolean(),
  porcelain: boolean(),
  prune: boolean(),
  remove_path: String.t() | nil
}
```

# `args`

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

Returns the argument list for `git worktree`.

- If `:add_path` is set, builds `git worktree add [options] <path> [<branch>]`.
- If `:remove_path` is set, builds `git worktree remove [--force] <path>`.
- If `:prune` is true, builds `git worktree prune`.
- Otherwise, lists worktrees with `git worktree list --porcelain`.

## Examples

    iex> Git.Commands.Worktree.args(%Git.Commands.Worktree{})
    ["worktree", "list", "--porcelain"]

    iex> Git.Commands.Worktree.args(%Git.Commands.Worktree{add_path: "/tmp/wt", add_branch: "main"})
    ["worktree", "add", "/tmp/wt", "main"]

    iex> Git.Commands.Worktree.args(%Git.Commands.Worktree{remove_path: "/tmp/wt", force: true})
    ["worktree", "remove", "--force", "/tmp/wt"]

    iex> Git.Commands.Worktree.args(%Git.Commands.Worktree{prune: true})
    ["worktree", "prune"]

# `parse_output`

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

Parses the output of `git worktree`.

For list operations (exit 0), parses porcelain output into a list of
`Git.Worktree` structs. For add/remove/prune operations (exit 0),
returns `{:ok, :done}`. On failure, returns `{:error, {stdout, exit_code}}`.

---

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