Git.Commands.Stash (git v0.4.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git stash.

Supports listing stash entries (default), saving (pushing) changes to the stash, popping the top stash entry, and dropping a stash entry.

Summary

Functions

Returns the argument list for git stash.

Parses the output of git stash.

Types

t()

@type t() :: %Git.Commands.Stash{
  drop: boolean(),
  include_untracked: boolean(),
  index: non_neg_integer() | nil,
  list: boolean(),
  message: String.t() | nil,
  pop: boolean(),
  save: boolean()
}

Functions

args(command)

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

Returns the argument list for git stash.

  • If :save is true, builds git stash push [-m <message>] [-u].
  • If :pop is true, builds git stash pop [stash@{index}].
  • If :drop is true, builds git stash drop [stash@{index}].
  • Otherwise, lists stash entries with git stash list.

Examples

iex> Git.Commands.Stash.args(%Git.Commands.Stash{})
["stash", "list"]

iex> Git.Commands.Stash.args(%Git.Commands.Stash{save: true})
["stash", "push"]

iex> Git.Commands.Stash.args(%Git.Commands.Stash{save: true, message: "wip"})
["stash", "push", "-m", "wip"]

iex> Git.Commands.Stash.args(%Git.Commands.Stash{pop: true})
["stash", "pop"]

iex> Git.Commands.Stash.args(%Git.Commands.Stash{drop: true, index: 1})
["stash", "drop", "stash@{1}"]

parse_output(stdout, exit_code)

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

Parses the output of git stash.

For list operations (exit 0), parses each line into a Git.StashEntry struct. For save/pop/drop operations (exit 0), returns {:ok, :done}. On failure, returns {:error, {stdout, exit_code}}.