Created
December 5, 2011 16:11
-
-
Save mizzy/1434109 to your computer and use it in GitHub Desktop.
Simple Grit code for comitting test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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