Skip to content

Commit

Permalink
Merge commit 'eric/master' into test
Browse files Browse the repository at this point in the history
  • Loading branch information
schacon committed Mar 3, 2008
2 parents f859e80 + 55a5e32 commit bc09a70
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
*.kpf
3 changes: 3 additions & 0 deletions lib/git.rb
Expand Up @@ -23,6 +23,9 @@
require 'git/status'
require 'git/author'

require 'git/stashes'
require 'git/stash'

require 'git/raw/repository'


Expand Down
7 changes: 7 additions & 0 deletions lib/git/branch.rb
Expand Up @@ -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])
Expand All @@ -25,6 +28,10 @@ def gcommit
@gcommit
end

def stashes
@stashes ||= Git::Stashes.new(@base)
end

def checkout
check_if_create
@base.checkout(@full)
Expand Down
32 changes: 31 additions & 1 deletion lib/git/lib.rb
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions 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
49 changes: 49 additions & 0 deletions 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

0 comments on commit bc09a70

Please sign in to comment.