[英]Capistrano error when using git
我正在嘗試設置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
還有其他人遇到此錯誤嗎? 我找到了這篇文章,但是遵循一個建議根本不會改變錯誤。
問題似乎是在空運行模式下,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調用繼續。
查看所引用錯誤的來源:
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
似乎沒有為所選分支或存儲庫加載任何修訂數據(在調用sub
時, ref
為nil)。 嘗試自己運行指定的命令( git ls-remote git@github.com:GIT_REPO GIT_BRANCH
),該命令有望生成更具體的錯誤消息,可能涉及分支或存儲庫本身。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.