7

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

背景

我有 rake 任务deploy:stagingdeploy:production我用它来部署我的应用程序。

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

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

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

最初,我使用 Rakefile 中的系统调用来执行这些 CLI 命令;然后我开始使用githeroku-api gems。

然而,git gem 似乎被放弃了(过去一年没有提交);看来,Grit 和坚固性现在是使用 Git 的标准宝石。

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

(在以下示例中,假设我推送到的远程/分支是源/主,并且已经在本地存储库中设置为远程)

从坚固开始:

$ 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

现在是砂砾:

$ 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">

任何帮助将不胜感激。

4

2 回答 2

1

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

这就是我所做的:

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

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

推送到github

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

于 2013-04-10T20:49:06.973 回答
1

使用 grit,repo.git.push 实际上通过 method_missing 调用 Git#native。它的签名是这样的:

def native(cmd, options = {}, *args, &block)

所以你想改为执行以下操作:

repo.git.push({}, remote)

是的,将 OPTIONAL 选项放在开头很愚蠢,但这就是它的编写方式。

于 2013-04-09T21:13:38.280 回答