使用Rugged推送到Git

我在脚本中使用脚本来推送git,所以我选择Rugged来做那个,当我尝试推送回购时我的问题,它给了我错误,你能帮我吗?

require 'rugged' git_email = 'ettaheri.nizar@gmail.com' git_name = 'Nizar' repo_name = '/Users/euphor/Desktop/test/testignore1' repo = Rugged::Repository.new('/Users/euphor/Desktop/test/testignore1') puts "1" index = repo.index puts "3" oid = repo.write("This is a blob.", :blob) index.add(:path => "testignore1", :oid => oid, :mode => 0100644) puts "4" options = {} options[:tree] = index.write_tree(repo) puts "5" options[:author] = { :email => git_email, :name => git_name, :time => Time.now } options[:committer] = { :email => git_email, :name => 'Test Author', :time => Time.now } puts "6" options[:message] ||= "Making a commit via Rugged!" options[:parents] = repo.empty? ? [] : [ repo.head.target ].compact options[:update_ref] = 'HEAD' puts "7" Rugged::Commit.create(repo, options) puts "8" **repo.push 'origin'** # this is my error puts "Done" 

我的错误信息是:

/Library/Ruby/Gems/2.0.0/gems/rugged-0.23.0/lib/rugged/repository.rb:224:in push': Unsupported URL protocol (Rugged::NetworkError) from /Library/Ruby/Gems/2.0.0/gems/rugged-0.23.0/lib/rugged/repository.rb:224:in push’from vips.rb:43:in`’

看起来你没有正确安装libgit2(Rugged的后端)。 适用于Mac OS的最方便的打包解决方案,如果使用Homebrew,您需要它来安装其他库。

安装Homebrew

执行此行后,请按照屏幕上的说明操作:

 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 

安装openssh

 brew install openssh 

重新安装坚固的gem

 gem uninstall rugged gem install rugged 

现在你的代码段运行正常。