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.
Summary
Types
@type t() :: %Git.Commands.Branch{ all: boolean(), create: String.t() | nil, delete: String.t() | nil, force: boolean(), 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, start_point: String.t() | nil }
Functions
Returns the argument list for git branch.
- If
:createis set, buildsgit branch <name>(appending:start_pointwhen set, and-fwithforce: trueto move an existing branch). - If
:deleteis set, buildsgit branch -d <name>(or-Dwithforce_delete: true). - Otherwise, lists branches with
-vvand 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{create: "feat/new", start_point: "HEAD~1"})
["branch", "feat/new", "HEAD~1"]
iex> Git.Commands.Branch.args(%Git.Commands.Branch{create: "phase", start_point: "abc123", force: true})
["branch", "-f", "phase", "abc123"]
iex> Git.Commands.Branch.args(%Git.Commands.Branch{delete: "old", force_delete: true})
["branch", "-D", "old"]
@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}}.