Permalink
Browse files

Merge commit 'eric/master' into test

  • Loading branch information...
2 parents f859e80 + 55a5e32 commit bc09a701262425adee32030c3b25f8b1c0be776e @schacon schacon committed Mar 3, 2008
Showing with 117 additions and 1 deletion.
  1. +1 −0 .gitignore
  2. +3 −0 lib/git.rb
  3. +7 −0 lib/git/branch.rb
  4. +31 −1 lib/git/lib.rb
  5. +26 −0 lib/git/stash.rb
  6. +49 −0 lib/git/stashes.rb
View
@@ -0,0 +1 @@
+*.kpf
View
@@ -23,6 +23,9 @@
require 'git/status'
require 'git/author'
+require 'git/stashes'
+require 'git/stash'
+
require 'git/raw/repository'
View
@@ -5,12 +5,15 @@ class Branch < Path
@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 @@ def gcommit
@gcommit
end
+ def stashes
+ @stashes ||= Git::Stashes.new(@base)
+ end
+
def checkout
check_if_create
@base.checkout(@full)
View
@@ -401,8 +401,38 @@ def reset(commit, opts = {})
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
View
@@ -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
View
@@ -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

0 comments on commit bc09a70

Please sign in to comment.