1

我正在尝试设置 capistrano 并想在服务器上测试之前在本地测试我的配置,但是当我运行 cap deploy -n 时,不断收到以下与 git 相关的错误

/Users/josh/.rvm/gems/ruby-1.9.3-p448@wgbh/gems/capistrano-2.15.5/lib/capistrano/recipes/deploy/scm/git.rb:234:in `block in query_revision': undefined method `sub' for nil:NilClass (NoMethodError)

并导致如下:

  * 2013-08-26 12:12:30 executing `deploy'
  * 2013-08-26 12:12:30 executing `deploy:update'
 ** transaction: start
  * 2013-08-26 12:12:30 executing `deploy:update_code'
  * executing locally: "git ls-remote git@github.com:GIT_REPO GIT_BRANCH"
*** [deploy:update_code] rolling back
  * executing "rm -rf /u/apps/APP_NAME/releases/20130826161230; true"

我试图追溯这一点,但我似乎无法弄清楚是什么原因造成的。我的 deploy.rb 如下所示:

require "bundler/capistrano" 

set :application, "APP_NAME"
set :deply_to, "/the/server/path"
set :user, "SERVER_USER"

set :repository,  "git@github.com:GIT_REPO_PATH"
set :scm, :git
set :scm_username , "GIT_USER_NAME"
#this allows you to choose a branch in the command line or default to master with 'cap -S branch=branchname deploy'
set :branch, fetch(:branch, "master")

#tells is to do resuse a single remote git clone
set :deploy_via, :remote_cache

server "THE_SERVER_NAME", :app, :web, :db, :primary => true

after 'deploy:update_code', 'deploy:migrate'

# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
 task :start do ; end
 task :stop do ; end
 task :restart, :roles => :app, :except => { :no_release => true } do
  run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
 end
end

有没有其他人遇到过这个错误?我找到了这篇文章,但遵循一个建议根本不会改变错误。

4

2 回答 2

4

问题似乎是在空运行模式下 run_locally 函数返回一个数组,而不是预期的字符串。

请参阅 https://github.com/capistrano/capistrano/blob/legacy-v2/lib/capistrano/recipes/deploy.rb#L133

不确定 git 配方是否有一种简单的方法可以确定它处于空运行模式。如果你只是破解这样的事情:

# in recipes/deploy/scm/git.rb ~line 229
result = yield(command)
return "666" if result.class == Array  # better would be: dry_run?

然后 -n 调用继续。

于 2014-01-31T16:15:23.597 回答
1

查看引用错误的来源:

      command = scm('ls-remote', repository, revision)
      result = yield(command)
      revdata = result.split(/[\t\n]/)
      newrev = nil
      revdata.each_slice(2) do |refs|
        rev, ref = *refs
        if ref.sub(/refs\/.*?\//, '').strip == revision.to_s # Explosion!
        ...
      end

似乎没有为选定的分支或存储库加载修订数据(调用它ref时为零)。sub尝试自己运行指定的命令 ( git ls-remote git@github.com:GIT_REPO GIT_BRANCH),这有望生成更具体的错误消息,可能涉及分支或存储库本身。

于 2013-08-26T17:26:42.310 回答