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.
Summary
Types
Functions
Returns the argument list for git worktree.
- If
:add_pathis set, buildsgit worktree add [options] <path> [<branch>]. - If
:remove_pathis set, buildsgit worktree remove [--force] <path>. - If
:pruneis true, buildsgit 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"]
@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}}.