Class: Git::Stashes
Overview
Collection of stash entries for a Git repository
Instance Method Summary collapse
-
#[](index) ⇒ Git::Stash?
Returns the stash entry at the given index.
-
#all ⇒ Array<Array(Integer, String)>
Returns all stash entries as an array of index and message pairs.
-
#apply(index = nil) ⇒ String
Applies a stash entry to the working directory.
-
#clear
Removes all stash entries.
-
#each
Iterates over each stash entry in newest-first order.
-
#initialize(base)
constructor
Initialize the stashes collection.
-
#save(message)
Saves the current working-directory state to a new stash entry.
-
#size ⇒ Integer
Returns the number of stash entries.
Constructor Details
#initialize(base)
Initialize the stashes collection
Loads all existing stash entries from the repository at construction time.
34 35 36 37 38 39 40 41 42 |
# File 'lib/git/stashes.rb', line 34 def initialize(base) @stashes = [] @base = base stash_repository.stashes_all.each do |stash| = stash[1] @stashes.unshift(Git::Stash.new(@base, , existing: true)) end end |
Instance Method Details
#[](index) ⇒ Git::Stash?
Returns the stash entry at the given index
Stashes are stored in newest-first order; index 0 is the most recent stash.
156 157 158 |
# File 'lib/git/stashes.rb', line 156 def [](index) @stashes[index.to_i] end |
#all ⇒ Array<Array(Integer, String)>
Returns all stash entries as an array of index and message pairs
Entries are listed in oldest-first order matching Repository#stashes_all.
56 57 58 |
# File 'lib/git/stashes.rb', line 56 def all stash_repository.stashes_all end |
#apply(index = nil) ⇒ String
Applies a stash entry to the working directory
91 92 93 |
# File 'lib/git/stashes.rb', line 91 def apply(index = nil) stash_repository.stash_apply(index) end |
#clear
This method returns an undefined value.
Removes all stash entries
105 106 107 108 109 |
# File 'lib/git/stashes.rb', line 105 def clear stash_repository.stash_clear @stashes = [] nil end |
#each ⇒ Enumerator<Git::Stash> #each {|stash| ... } ⇒ Array<Git::Stash>
Iterates over each stash entry in newest-first order
141 142 143 |
# File 'lib/git/stashes.rb', line 141 def each(&) @stashes.each(&) end |
#save(message)
This method returns an undefined value.
Saves the current working-directory state to a new stash entry
72 73 74 75 |
# File 'lib/git/stashes.rb', line 72 def save() s = Git::Stash.new(@base, ) @stashes.unshift(s) if s.saved? end |
#size ⇒ Integer
Returns the number of stash entries
118 119 120 |
# File 'lib/git/stashes.rb', line 118 def size @stashes.size end |