Module: Git::Repository::Stashing
- Included in:
- Git::Repository
- Defined in:
- lib/git/repository/stashing.rb
Overview
Facade methods for stash operations
Included by Git::Repository.
Instance Method Summary collapse
-
#stash_apply(id = nil) ⇒ String
Apply a stash to the working directory.
-
#stash_clear ⇒ String
Remove all stash entries.
-
#stash_save(message) ⇒ Boolean
Save the current working directory and index state to a new stash.
-
#stashes_all ⇒ Array<Array(Integer, String)>
Returns all stash entries as an array of index and message pairs.
Instance Method Details
#stash_apply(id = nil) ⇒ String
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.
83 84 85 |
# File 'lib/git/repository/stashing.rb', line 83 def stash_apply(id = nil) Git::Commands::Stash::Apply.new(@execution_context).call(id).stdout end |
#stash_clear ⇒ String
Remove all stash entries
Removes all entries from the stash list. Use with caution as this operation cannot be undone.
102 103 104 |
# File 'lib/git/repository/stashing.rb', line 102 def stash_clear Git::Commands::Stash::Clear.new(@execution_context).call.stdout end |
#stash_save(message) ⇒ Boolean
Save the current working directory and index state to a new stash
57 58 59 60 |
# File 'lib/git/repository/stashing.rb', line 57 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)>
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.
33 34 35 36 37 38 39 40 41 |
# File 'lib/git/repository/stashing.rb', line 33 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| match_data = info..match(/^[^:]+:(.*)$/) = match_data ? match_data[1].strip : info. [i, ] end end |