如何提交libgit2的Ruby绑定 [英] How to commit with Ruby bindings for libgit2

查看:128
本文介绍了如何提交libgit2的Ruby绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何使用libgit2的ruby绑定('rugged'gem)创建一个提交?我已经尝试了所有可以找到的例子,在libgit2使用指南和坚固的gem github页面上,并且没有任何用于创建或编辑提交的检查正在工作。



这在试图弄清楚如何提交到目前为止很有帮助,除了libgit2本身而不是ruby绑定。 http://librelist.com/browser//libgit2/2011/2/19/initing-a-repository-adding-files-to-the-index-and-committing/#d94ce8df18ff0202ce904180286a4a85



当我尝试提交时,按照Rugged Github页面上的步骤进行提交,我得到了这个;

 撬(主)GT; Rugged :: Commit.create(repo,:author => author,:message =>Hello world \\\
\\\
,:committer => author,:parents =>父母,:tree => ; tree)
TypeError:错误的参数类型nil(期望的字符串)

当我尝试遵循libgit2使用指南,它基本上说要获得提交,然后使用 commit.message = 类似命令对其进行编辑,但随后我得到noMethodErrors,因为没有' message ='method。

libgit2使用指南: http ://libgit2.github.com/api.html

坚固的文档0: http://rubydoc.info/gems/rugged/0.16.0/frames

坚固的Github页面: https://github.com/libgit2/rugged



编辑:我如何重现这一点; http://pastebin.com/wnta8FWm

Edit_n + 1:我也试过使用通过尝试

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

但是,这只是产生了与以前完全相同的错误输出。

解决方案

TL; DR ---这是为我修复的: gem install --prerelease rugged



经过一些挖掘和大量试验后,我想我已经发现了这个问题。



当我做了 gem install rugged 它给了我0.16.0版本。这是我遇到麻烦的版本,当我尝试gem附带的测试时,许多测试都失败了,许多失败的测试似乎与提交和写入提交有关。

Rugged gem的Rubygems页面显示虽然有一个0.17.0.b6版本可用,但令我感到困惑,因为我从未遇到'--prerelease'选项为 gem 。该版本必须是预发行版本,因为在执行 gem install --prerelease rugged 版本0.17.0.b6后(也是如此)。



现在有0.17.0.b6,我可以按照文档没有问题。



另外一个注释,我读过的文档doesn不要提到它,但是 ext / rugged_commit.c 中的源代码具有提及:update_ref =>的注释

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.

解决方案

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.

这篇关于如何提交libgit2的Ruby绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆