Git.Stashes (git v0.4.0)

Copy Markdown View Source

Higher-level stash management operations that compose the lower-level Git.stash/1 command.

All functions accept an optional keyword list. Use :config to specify the repository via a Git.Config struct; when omitted a default config is built from the environment.

Summary

Functions

Applies the latest stash (or a specific stash by index) without removing it.

Clears all stash entries.

Drops a specific stash entry.

Lists all stash entries.

Pops the latest stash entry, applying it and removing it from the stash list.

Saves current changes to the stash with a message.

Functions

apply(opts \\ [])

@spec apply(keyword()) :: {:ok, :done} | {:error, term()}

Applies the latest stash (or a specific stash by index) without removing it.

Uses raw git stash apply since the underlying command module does not support the apply subcommand directly.

Options

  • :config - a Git.Config struct
  • :index - stash index to apply (e.g., 1 for stash@{1})

Examples

{:ok, :done} = Git.Stashes.apply()
{:ok, :done} = Git.Stashes.apply(index: 2)

clear(opts \\ [])

@spec clear(keyword()) :: {:ok, :done} | {:error, term()}

Clears all stash entries.

Uses raw git stash clear since the underlying command module does not support the clear subcommand directly.

Options

Examples

{:ok, :done} = Git.Stashes.clear()

drop(opts \\ [])

@spec drop(keyword()) :: {:ok, :done} | {:error, term()}

Drops a specific stash entry.

Delegates to Git.stash(drop: true).

Options

  • :config - a Git.Config struct
  • :index - stash index to drop (e.g., 1 for stash@{1})

Examples

{:ok, :done} = Git.Stashes.drop()
{:ok, :done} = Git.Stashes.drop(index: 1)

list(opts \\ [])

@spec list(keyword()) :: {:ok, [Git.StashEntry.t()]} | {:error, term()}

Lists all stash entries.

Delegates to Git.stash(list: true).

Options

Examples

{:ok, entries} = Git.Stashes.list()

pop(opts \\ [])

@spec pop(keyword()) :: {:ok, :done} | {:error, term()}

Pops the latest stash entry, applying it and removing it from the stash list.

Delegates to Git.stash(pop: true).

Options

Examples

{:ok, :done} = Git.Stashes.pop()

save(message, opts \\ [])

@spec save(
  String.t(),
  keyword()
) :: {:ok, :done} | {:error, term()}

Saves current changes to the stash with a message.

Delegates to Git.stash(save: true, message: message).

Options

Examples

{:ok, :done} = Git.Stashes.save("work in progress")