使用粗糙或砂砾的git推的示例

Sco*_*ott 7 grit rugged

我正在寻找一些代码示例,无论是坚固还是砂砾,都展示了如何做git push.

背景

我有耙任务deploy:stagingdeploy:production我用来部署我的应用程序.

我正在部署到heroku,所以这些任务基本上执行以下操作:

  1. 获取最新标签(例如git describe --abbrev=0)
  2. 将该标记所代表的版本推送到指定的远程(例如git push staging v1.00)
  3. 将版本存储在heroku配置var中(例如heroku config:add APP_VERSION=v1.00)

(还有一些检查,以确保我没有忘记在推之前创建一个新的标签等)

最初我使用来自Rakefile的系统调用来获取这些CLI命令; 然后我开始使用githeroku-api宝石.

然而git gem似乎被抛弃了(过去一年没有提交); 似乎Grit和坚固耐用现在是与Git合作的标准宝石.

不幸的是,由于缺乏文档,我无法弄清楚如何使用这些库中的任何一个进行git推送.

(在以下示例中,假设我正在推送的远程/分支是origin/master,并且已在本地repo中设置为远程)

从坚固开始:

$ irb
2.0.0-p0 :001 > require 'rugged'
 => true 
2.0.0-p0 :002 > repo = Rugged::Repository.new('/path/to/repo')
 => #<Rugged::Repository:0x007fe8b48821c0 @encoding=#<Encoding:UTF-8>> 
2.0.0-p0 :003 > remote = Rugged::Remote.lookup(repo, 'origin')
 NoMethodError: undefined method `lookup' for Rugged::Remote:Class
Run Code Online (Sandbox Code Playgroud)

现在为砂砾:

$ irb
2.0.0-p0 :001 > require 'grit'
 => true 
2.0.0-p0 :002 > repo = Grit::Repo.new('/path/to/repo')
 => #<Grit::Repo "/path/to/repo/.git"> 
2.0.0-p0 :004 > remote = repo.remotes.last
 => #<Grit::Remote "origin/master"> 
2.0.0-p0 :005 > repo.git.push(remote)
NoMethodError: undefined method `delete' for #<Grit::Remote "origin/master">
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.

mcK*_*ain 1

好吧,我想我已经明白了,但现在它要求我提供 gitHub 凭据,但我无法输入我的凭据,因为我收到“超时”错误。

这就是我所做的:

将远程仓库添加到项目中:

repo.git.remote({},'add','RemoteRepoName',' https://github.com/ /.git')

推送到github

Pusher = repo.git.push({:process_info => true, :progress => true}, 'RemoteRepoName', 'master')