Git.Commands.Branch (git v0.4.0)

Copy Markdown View Source

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

Functions

Returns the argument list for git branch.

Parses the output of git branch.

Types

t()

@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
}

Functions

args(branch)

@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(stdout, exit_code)

@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}}.