Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/git/lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -604,10 +604,12 @@ def stashes_all
arr = []
filename = File.join(@git_dir, 'logs/refs/stash')
if File.exist?(filename)
File.open(filename).each_with_index { |line, i|
m = line.match(/:(.*)$/)
arr << [i, m[1].strip]
}
File.open(filename) do |f|
f.each_with_index do |line, i|
m = line.match(/:(.*)$/)
arr << [i, m[1].strip]
end
end
end
arr
end
Expand Down
11 changes: 11 additions & 0 deletions lib/git/stashes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ def initialize(base)
@stashes.unshift(Git::Stash.new(@base, message, true))
end
end

#
# Returns an multi-dimensional Array of elements that have been stash saved.
# Array is based on position and name. See Example
#
# @example Returns Array of items that have been stashed
# .all - [0, "testing-stash-all"]]
# @return [Array]
def all
@base.lib.stashes_all
end

def save(message)
s = Git::Stash.new(@base, message)
Expand Down
22 changes: 22 additions & 0 deletions tests/units/test_stashes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,27 @@ def test_stash_unstash
end
end
end

def test_stashes_all
in_temp_dir do |path|
g = Git.clone(@wbare, 'stash_test')
Dir.chdir('stash_test') do
assert_equal(0, g.branch.stashes.size)
new_file('test-file1', 'blahblahblah1')
new_file('test-file2', 'blahblahblah2')
assert(g.status.untracked.assoc('test-file1'))

g.add

assert(g.status.added.assoc('test-file1'))

g.branch.stashes.save('testing-stash-all')

stashes = g.branch.stashes.all

assert(stashes[0].include?('testing-stash-all'))
end
end
end

end