Skip to content

Instantly share code, notes, and snippets.

@mizzy
Created December 5, 2011 16:11
Show Gist options
  • Select an option

  • Save mizzy/1434109 to your computer and use it in GitHub Desktop.

Select an option

Save mizzy/1434109 to your computer and use it in GitHub Desktop.
Simple Grit code for comitting test
require 'grit'
class Committer
def initialize
@repo = Grit::Repo.new("/home/miya/git/test")
end
def actor
@actor ||=
begin
Grit::Actor.new('Gosuke Miyashita', '[email protected]')
end
end
def parents
@parents ||=
begin
arr = [@repo.commit('master')]
arr.flatten!
arr.compact!
arr
end
end
def index
@index ||=
begin
idx = @repo.index
if parent = parents.first
idx.read_tree(parent.tree.id)
end
idx
end
end
def commit
sha1 = index.commit("hoge", parents, actor, nil, 'master')
sha1
end
def method_missing(name, *args)
index.send(name, *args)
end
end
require 'committer'
committer = Committer.new
committer.add("test.txt", "foo¥nbar¥n")
committer.commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment