summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--lib/git.rb3
-rw-r--r--lib/git/branch.rb7
-rw-r--r--lib/git/lib.rb32
-rw-r--r--lib/git/stash.rb26
-rw-r--r--lib/git/stashes.rb49
6 files changed, 117 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..549ba1a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.kpf \ No newline at end of file
diff --git a/lib/git.rb b/lib/git.rb
index 49a61ea..c7c2703 100644
--- a/lib/git.rb
+++ b/lib/git.rb
@@ -23,6 +23,9 @@ require 'git/diff'
require 'git/status'
require 'git/author'
+require 'git/stashes'
+require 'git/stash'
+
require 'git/raw/repository'
diff --git a/lib/git/branch.rb b/lib/git/branch.rb
index 6c1bc44..5dc8ec7 100644
--- a/lib/git/branch.rb
+++ b/lib/git/branch.rb
@@ -5,12 +5,15 @@ module Git
@base = nil
@gcommit = nil
+ @stashes = nil
def initialize(base, name)
@remote = nil
@full = name
@base = base
+ @stashes = Git::Stashes.new(@base)
+
parts = name.split('/')
if parts[1]
@remote = Git::Remote.new(@base, parts[0])
@@ -25,6 +28,10 @@ module Git
@gcommit
end
+ def stashes
+ @stashes ||= Git::Stashes.new(@base)
+ end
+
def checkout
check_if_create
@base.checkout(@full)
diff --git a/lib/git/lib.rb b/lib/git/lib.rb
index 1a60be6..4c4147d 100644
--- a/lib/git/lib.rb
+++ b/lib/git/lib.rb
@@ -401,8 +401,38 @@ module Git
arr_opts << commit.to_s if commit
command('reset', arr_opts)
end
+
+ 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]
+ }
+ end
+ arr
+ end
+
+ def stash_save(message)
+ output = command('stash save', [message])
+ return false unless output.match(/HEAD is now at/)
+ return true
+ end
-
+ def stash_apply(id)
+ command('stash apply', [id])
+ # Already uptodate! ---???? What then
+ end
+
+ def stash_clear
+ command('stash clear')
+ end
+
+ def stash_list
+ command('stash list')
+ end
+
def branch_new(branch)
command('branch', branch)
end
diff --git a/lib/git/stash.rb b/lib/git/stash.rb
new file mode 100644
index 0000000..e02c043
--- /dev/null
+++ b/lib/git/stash.rb
@@ -0,0 +1,26 @@
+module Git
+ class Stash
+ def initialize(base, message, existing=false)
+ @base = base
+ @message = message
+ save if existing == false
+ end
+
+ def save
+ @saved = @base.lib.stash_save(@message)
+ end
+
+ def saved?
+ @saved
+ end
+
+ def message
+ @message
+ end
+
+ def to_s
+ message
+ end
+
+ end
+end \ No newline at end of file
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