Reputation: 721
I am trying to setup capistrano and want to test my config locally before testing on the server, but when I run cap deploy -n keep getting the following error relating to 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)
and leading up to this as follows:
* 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 [email protected]:GIT_REPO GIT_BRANCH"
*** [deploy:update_code] rolling back
* executing "rm -rf /u/apps/APP_NAME/releases/20130826161230; true"
I have tried to trace this back, but I can't seem to figure out what is causing it. My deploy.rb looks as follows:
require "bundler/capistrano"
set :application, "APP_NAME"
set :deply_to, "/the/server/path"
set :user, "SERVER_USER"
set :repository, "[email protected]: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
Has anyone else experienced this error? I found this post but following the one suggestion does not change the error at all.
Upvotes: 1
Views: 1558
Reputation: 41
The issue appears to be that when in dry run mode the run_locally function returns an array, not the expected string.
See https://github.com/capistrano/capistrano/blob/legacy-v2/lib/capistrano/recipes/deploy.rb#L133
Not sure if there is an easy way for the git recipe to figure out that it is in dry run mode. If you just hack in something like this:
# in recipes/deploy/scm/git.rb ~line 229
result = yield(command)
return "666" if result.class == Array # better would be: dry_run?
Then the -n invocation continues.
Upvotes: 4
Reputation: 16074
Looking at the source for the referenced error:
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
It seems likely no revision data is being loaded for the selected branch or repository (ref
is nil when sub
is called on it). Try running the specified command yourself (git ls-remote [email protected]:GIT_REPO GIT_BRANCH
) which should hopefully generate a more specific error message, probably involving the branch or the repository itself.
Upvotes: 1