Created
February 23, 2016 22:59
-
-
Save rendon/e0f1338258eb7b3f172c to your computer and use it in GitHub Desktop.
Rugged minimal example
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 'rugged' | |
dir = "/home/rendon/repos/snippet001/" | |
name = "README.md" | |
# For existing repositories | |
#repo = Rugged::Repository.new(dir) | |
repo = Rugged::Repository.init_at(dir) | |
File.open(File.join(dir, name), "w") do |f| | |
f.write("This is a README file...\n") | |
end | |
oid = Rugged::Blob.from_workdir repo, name | |
index = repo.index | |
index.add(:path => name, :oid => oid, :mode => 0100644) | |
options = {} | |
options[:tree] = index.write_tree(repo) | |
options[:author] = { :email => "[email protected]", :name => "Test author", :time => Time.now } | |
options[:comitter] = { :email => "[email protected]", :name => "Test author", :time => Time.now } | |
options[:message] = "Add README" | |
options[:parents] = repo.empty? ? [] : [ repo.head.target ].compact | |
options[:update_ref] = "HEAD" | |
commit = Rugged::Commit.create(repo, options) | |
index.write |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment