C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rugged-0.24.0/lib/rugged/repository.rb:224:in `push': Request failed with status code: 401 (Rugged::NetworkError) from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rugged-0.24.0/lib/rugged/repository.rb:224:in `push' from mytest.rb:34:in `<main>' 下面是我的代码 require 'rugged'git_email = '138XXXX@139.com'git_name = 'XXXX'repo_name = 'D://mytestcode//rubyOntest'repo = Rugged::Repository.new('D://mytestcode//rubyOntest')puts "1"index = repo.indexputs "3"oid = repo.write("This is a blob.", :blob)#index.add(:path => "readme.txt", :oid => oid, :mode => 0100644)index.add_allputs "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 => git_name, :time => Time.now }puts "6"options[:message] ||= "Making a commit via Rugged!--add all"options[:parents] = repo.empty? ? [] : [ repo.head.target ].compactoptions[:update_ref] = 'HEAD'puts "7"objuser=Rugged::Credentials::UserPassword.new(options)puts "8"Rugged::Commit.create(repo, options)puts "9"repo.push 'origin'# this is my errorputs "Done"
2 回答
Helenr
TA贡献1780条经验 获得超3个赞
objuser=Rugged::Credentials::UserPassword.new({username: '用户名', password: '密码'})
puts "add credentials"
Rugged::Commit.create(repo, options)
puts "Commit ..."
remote = repo.remotes["origin"]
puts remote.url
#remote = Rugged::Remote.lookup(@repo , 'origin')
#使用credentials进行授权即可。
remote.push("refs/heads/master", {credentials: objuser})
- 2 回答
- 0 关注
- 100 浏览
添加回答
举报
0/150
提交
取消