Implements the Git.Command behaviour for git stash.
Supports listing stash entries (default), saving (pushing) changes to the stash, popping the top stash entry, applying a stash without dropping it, dropping a stash entry, clearing all entries, creating a branch from a stash, and showing the diff for a stash entry.
Summary
Types
Functions
Returns the argument list for git stash.
- If
:saveis true, buildsgit stash push [-m <message>] [-u] [--keep-index]. - If
:popis true, buildsgit stash pop [stash@{index}]. - If
:applyis true, buildsgit stash apply [stash@{index}]. - If
:dropis true, buildsgit stash drop [stash@{index}]. - If
:clearis true, buildsgit stash clear. - If
:branchis a string, buildsgit stash branch <name> [stash@{index}]. - If
:showis true, buildsgit stash show [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}"]
iex> Git.Commands.Stash.args(%Git.Commands.Stash{apply: true, index: 1})
["stash", "apply", "stash@{1}"]
iex> Git.Commands.Stash.args(%Git.Commands.Stash{clear: true})
["stash", "clear"]
iex> Git.Commands.Stash.args(%Git.Commands.Stash{branch: "recovered"})
["stash", "branch", "recovered"]
iex> Git.Commands.Stash.args(%Git.Commands.Stash{show: true})
["stash", "show"]
@spec parse_output(String.t(), non_neg_integer()) :: {:ok, [Git.StashEntry.t()]} | {:ok, :done} | {:ok, String.t()} | {: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 show operations (exit 0), returns the raw diff as {:ok, stdout}.
For save/pop/apply/drop/clear/branch operations (exit 0), returns {:ok, :done}.
On failure, returns {:error, {stdout, exit_code}}.