Capistrano, local_repository, and deploy_via :copy

21 May 2008

Today I was working on a Rails app that's running on the same machine that hosts the Subversion repo. So I figured I'd use local_repository to make the deployments faster. You know, that's where you have this in your config/deploy.rb:

set :repository,  'file:///path/to/svn/#{application}/trunk'
set :local_repository, 'svn+ssh://my.server.com/path/to/#{application}/trunk'

With these settings, Capistrano checks out the code using the file:// URI which is much faster than going over svn+ssh. Anyhow, it was failing with a svn: Unable to open an ra_local session to URL error and I couldn't get it working... until I noticed that I had left the set :deploy_via, :copy line in from a previous setup. Doh! Once I removed that, all was well.

We could check for this with something like this in lib/capistrano/recipes/deploy/scm/base.rb:

$ diff -Naur base.rb base.new.rb 
--- base.rb     2008-05-21 19:50:07.000000000 -0400
+++ base.new.rb 2008-05-21 19:49:59.000000000 -0400
@@ -43,6 +43,7 @@
   # Creates a new SCM instance with the given configuration options.
   def initialize(configuration={})
     @configuration = configuration
     # The next line is broken into multiple lines only for blog formatting
+          logger.info 'WARNING: You probably don't want to use 'set :deploy_via, :copy' 
and a :local_repository together; remove 'set :deploy_via, :copy' and things will 
probably work as expected' if @configuration.variables[:deploy_via] == :copy && 
@configuration.variables[:local_repository]
   end

   # Returns a proxy that wraps the SCM instance and forces it to operate

Are there cases in which you'd actually want to use those together? I'm not sure. We'd probably want a better message than that, too :-)