summaryrefslogtreecommitdiffstats
path: root/lib/git/stashes.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/git/stashes.rb')
-rw-r--r--lib/git/stashes.rb49
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/git/stashes.rb b/lib/git/stashes.rb
new file mode 100644
index 0000000..78b1d59
--- /dev/null
+++ b/lib/git/stashes.rb
@@ -0,0 +1,49 @@
+module Git
+
+ # object that holds all the available stashes
+ class Stashes
+ include Enumerable
+
+ @base = nil
+ @stashes = nil
+
+ def initialize(base)
+ @stashes = []
+
+ @base = base
+
+ @base.lib.stashes_all.each do |id, message|
+ @stashes.unshift(Git::Stash.new(@base, message, true))
+ end
+ end
+
+ def save(message)
+ s = Git::Stash.new(@base, message)
+ @stashes.unshift(s) if s.saved?
+ end
+
+ def apply(index=0)
+ @base.lib.stash_apply(index.to_i)
+ end
+
+ def clear
+ @base.lib.stash_clear
+ @stashes = []
+ end
+
+ def size
+ @stashes.size
+ end
+
+ def each
+ @stashes.each do |s|
+ yield s
+ end
+ end
+
+ def [](symbol)
+ @stashes[symbol.to_s]
+ end
+
+ end
+end \ No newline at end of file