Module: Git::Repository::Stashing Private

Included in:
Git::Repository
Defined in:
lib/git/repository/stashing.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Facade methods for stash operations

Included by Git::Repository.

Instance Method Summary collapse

Instance Method Details

#stash_apply(id = nil) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Apply a stash to the working directory

Applies the changes recorded in a stash entry to the working directory without removing the entry from the stash list. Unlike git stash pop, the stash entry is preserved after applying.

Examples:

Apply the most recent stash

repo.stash_apply #=> "HEAD is now at abc1234 Initial commit"

Apply a specific stash entry by reference

repo.stash_apply('stash@{1}') #=> "HEAD is now at abc1234 Initial commit"

Raises:

See Also:



119
120
121
# File 'lib/git/repository/stashing.rb', line 119

def stash_apply(id = nil)
  Git::Commands::Stash::Apply.new(@execution_context).call(id).stdout
end

#stash_clearString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Remove all stash entries

Removes all entries from the stash list. Use with caution as this operation cannot be undone.

Examples:

Clear all stashes

repo.stash_clear #=> ""

Raises:

See Also:



138
139
140
# File 'lib/git/repository/stashing.rb', line 138

def stash_clear
  Git::Commands::Stash::Clear.new(@execution_context).call.stdout
end

#stash_listString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Deprecated.

Use #stashes_all instead

Returns stash entries as a formatted string matching git stash list output

Examples:

List stashes as a formatted string

repo.stash_list #=> "stash@{0}: On main: WIP\nstash@{1}: On feature: Fix bug"

Raises:

See Also:



66
67
68
69
70
71
72
73
74
# File 'lib/git/repository/stashing.rb', line 66

def stash_list
  Git::Deprecation.warn(
    'Git::Repository#stash_list is deprecated and will be removed in v6.0.0. ' \
    'Use Git::Repository#stashes_all instead.'
  )
  result = Git::Commands::Stash::List.new(@execution_context).call
  stashes = Git::Parsers::Stash.parse_list(result.stdout)
  stashes.map { |info| "#{info.name}: #{info.message}" }.join("\n")
end

#stash_save(message) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Save the current working directory and index state to a new stash

Examples:

Save current changes

repo.stash_save('WIP: feature work')

Raises:

See Also:



90
91
92
93
# File 'lib/git/repository/stashing.rb', line 90

def stash_save(message) # rubocop:disable Naming/PredicateMethod
  result = Git::Commands::Stash::Push.new(@execution_context).call(message: message)
  !result.stdout.include?('No local changes to save')
end

#stashes_allArray<Array(Integer, String)>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

The sequential index returned here is not the same as git's stash@{N} reference used by #stash_apply. In git, stash@{0} is the most recent stash, while index 0 here is the oldest. To apply a specific stash from this list, convert the entry's position to a git reference: 'stash@{%d}' % (total - 1 - index), or pass the string reference directly to #stash_apply.

Returns all stash entries as an array of index and message pairs

Lists all stash entries in the repository ordered from oldest to newest. The index is a sequential number starting from 0 for the oldest stash. The message is the stash description with the leading branch prefix (e.g. "On main:" or "WIP on main:") stripped.

Examples:

List all stashes (oldest first)

repo.stashes_all #=> [[0, "Fix bug"], [1, "Add feature"]]

Raises:

See Also:



40
41
42
43
44
45
46
47
# File 'lib/git/repository/stashing.rb', line 40

def stashes_all
  result = Git::Commands::Stash::List.new(@execution_context).call
  stashes = Git::Parsers::Stash.parse_list(result.stdout)
  stashes.reverse.each_with_index.map do |info, i|
    message = info.message.sub(/^(?:WIP on|On)\s+[^:]+:\s*/, '')
    [i, message]
  end
end