简体   繁体   中英

How to commit with Ruby bindings for libgit2

Does anyone know how to create a commit using the ruby bindings (the 'rugged' gem) for libgit2? I've tried all the examples I can find, on the libgit2 usage guide and on the rugged gem github page, and none of the exampes for creating or editing a commit are working.

This has been helpful in trying to figure out how to commit so far, except it's for libgit2 itself and not the ruby bindings. http://librelist.com/browser//libgit2/2011/2/19/initing-a-repository-adding-files-to-the-index-and-committing/#d94ce8df18ff0202ce904180286a4a85

When I try and make a commit, following the steps on the Rugged Github page, I get this;

pry(main)> Rugged::Commit.create( repo, :author=>author, :message=>"Hello world\n\n", :committer=>author, :parents=>parents, :tree=>tree )
TypeError: wrong argument type nil (expected String)

And when I try to follow the libgit2 usage guide, which basically says to get the commit and then just edit it using commit.message= like commands, but then I get noMethodErrors because there is no 'message=' method.

libgit2 usage guide: http://libgit2.github.com/api.html
Rugged documentation 0: http://rubydoc.info/gems/rugged/0.16.0/frames
Rugged Github page: https://github.com/libgit2/rugged

Edit: How I reproduce this; http://pastebin.com/wnta8FWm
Edit_n+1: I also tried using the sha of the tree instead of a Rugged::Tree object, by trying

x=Rugged::Commit.create( repo, :author=>author, :message=>"Hello world\n\n", :committer=>author, :parents=>parents, :tree=>tree.oid )

But that just produced the exact same error output as before.

Rugged::Commit.create(repo, data) is not what's in the README. What code are you running? That simply looks like you're missing a required field. What fields are you filling and how?

TL;DR --- This is what fixed it for me: gem install --prerelease rugged

After some digging and a lot of experimenting, I think I've figured out the problem.

When I did gem install rugged it gave me version 0.16.0 . This was the version I was having trouble with, and when I tried the tests that came with the gem many of the tests failed and many of those that failed seemed to be related to commits and writing commits.

The Rubygems page for the Rugged gem shows that there is a 0.17.0.b6 version available though, which confused me because I had never encountered the '--prerelease' option for gem . That version must be a prerelease because after doing gem install --prerelease rugged version 0.17.0.b6 was installed (as well).

Now with 0.17.0.b6 I am able to follow the documentation without problems.

One extra note, the documentation that I've read doesn't mention it but the source code in ext/rugged_commit.c has comments that mention an :update_ref=>'' option when creating a commit which you can use to update the ref to point to the new commit. Without this option, the commit will be created and written to the ODB, but no references will be updated and so the commit won't be accessible from any of your branches.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM