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
-
#stash_apply(id = nil) ⇒ String
private
Apply a stash to the working directory.
-
#stash_clear ⇒ String
private
Remove all stash entries.
-
#stash_list ⇒ String
deprecated
private
Deprecated.
Use #stashes_all instead
-
#stash_save(message) ⇒ Boolean
private
Save the current working directory and index state to a new stash.
-
#stashes_all ⇒ Array<Array(Integer, String)>
private
Returns all stash entries as an array of index and message pairs.
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.
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_clear ⇒ 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.
Remove all stash entries
Removes all entries from the stash list. Use with caution as this operation cannot be undone.
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_list ⇒ 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.
Use #stashes_all instead
Returns stash entries as a formatted string matching git stash list output
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 a future version. ' \ '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.}" }.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
90 91 92 93 |
# File 'lib/git/repository/stashing.rb', line 90 def stash_save() # rubocop:disable Naming/PredicateMethod result = Git::Commands::Stash::Push.new(@execution_context).call(message: ) !result.stdout.include?('No local changes to save') end |
#stashes_all ⇒ Array<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.
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.
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| = info..sub(/^(?:WIP on|On)\s+[^:]+:\s*/, '') [i, ] end end |