<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Wolfmans Howlings: Allow a different local and remote subversion repository path for Capistrano</title>
    <link>http://blog.wolfman.com/articles/2006/11/15/allow-a-different-local-and-remote-subversion-repository-path-for-capistrano</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>A programmers Blog about Ruby, Rails and a few other issues</description>
    <item>
      <title>Allow a different local and remote subversion repository path for Capistrano</title>
      <description>&lt;p&gt;One of the things that bugs me about Capistrano is the requirement
that access to the remote subversion repository have the same path
from the local machine and the remote machine. This is never the case
in my experience.&lt;/p&gt;

&lt;p&gt;I have been getting around it by setting the path to
svn://localhost/... and running ssh locally to port forward the SVN
port to the remote host. This sucks as I usually forget to run ssh in
another window first.&lt;/p&gt;

&lt;p&gt;So I added an optional configuration variable to be set in deploy.rb
called &lt;code&gt;local_repository_path&lt;/code&gt;, so now you set the repository path as
normal, which is the path the remote server uses to access the SVN
repository, and you set the path that the local machine (your
workstation) uses to access the same repository...&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;set :repository, "svn://localhost/#{application}/trunk"
set :local_repository_path, "svn+ssh://myremotehost.com/path/to/repostitory/#{application}/trunk"
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Ideally one would patch the Capistrano distribution to achieve this,
but thanks to the magic of ruby you can patch it from your own
setup so I put the following into &lt;code&gt;lib/tasks/patch_capistrano.rb&lt;/code&gt;&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;
&lt;span class="comment"&gt;# Patch the svn scm to allow a local svn repository path as well as&lt;/span&gt;
&lt;span class="comment"&gt;# the remote one as most systems I use have a different path depending&lt;/span&gt;
&lt;span class="comment"&gt;# on whether you access svn from the local machine or remote machine&lt;/span&gt;

  &lt;span class="keyword"&gt;module &lt;/span&gt;&lt;span class="module"&gt;Capistrano&lt;/span&gt;

    &lt;span class="comment"&gt;# override the two scm methods that access svn from the local machine&lt;/span&gt;
    &lt;span class="keyword"&gt;module &lt;/span&gt;&lt;span class="module"&gt;SCM&lt;/span&gt;

      &lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Subversion&lt;/span&gt;
        &lt;span class="comment"&gt;# Return an integer identifying the last known revision in the svn&lt;/span&gt;
        &lt;span class="comment"&gt;# repository. (This integer is currently the revision number.)&lt;/span&gt;
        &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;latest_revision&lt;/span&gt;
          &lt;span class="attribute"&gt;@latest_revision&lt;/span&gt; &lt;span class="punct"&gt;||=&lt;/span&gt; &lt;span class="keyword"&gt;begin&lt;/span&gt;
            &lt;span class="ident"&gt;configuration&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;logger&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;debug&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;querying latest revision...&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;
            &lt;span class="ident"&gt;match&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;svn_log&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;configuration&lt;/span&gt;&lt;span class="punct"&gt;[&lt;/span&gt;&lt;span class="symbol"&gt;:local_repository_path&lt;/span&gt;&lt;span class="punct"&gt;]).&lt;/span&gt;&lt;span class="ident"&gt;scan&lt;/span&gt;&lt;span class="punct"&gt;(/&lt;/span&gt;&lt;span class="regex"&gt;r(&lt;span class="escape"&gt;\d&lt;/span&gt;+)&lt;/span&gt;&lt;span class="punct"&gt;/).&lt;/span&gt;&lt;span class="ident"&gt;first&lt;/span&gt; &lt;span class="keyword"&gt;or&lt;/span&gt;
            &lt;span class="keyword"&gt;raise&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;Could not determine latest revision&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;
            &lt;span class="ident"&gt;match&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;first&lt;/span&gt;
          &lt;span class="keyword"&gt;end&lt;/span&gt;
        &lt;span class="keyword"&gt;end&lt;/span&gt;

        &lt;span class="comment"&gt;# Return a string containing the diff between the two revisions. +from+&lt;/span&gt;
        &lt;span class="comment"&gt;# and +to+ may be in any format that svn recognizes as a valid revision&lt;/span&gt;
        &lt;span class="comment"&gt;# identifier. If +from+ is +nil+, it defaults to the last deployed&lt;/span&gt;
        &lt;span class="comment"&gt;# revision. If +to+ is +nil+, it defaults to HEAD.&lt;/span&gt;
        &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;diff&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;actor&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;from&lt;/span&gt;&lt;span class="punct"&gt;=&lt;/span&gt;&lt;span class="constant"&gt;nil&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;to&lt;/span&gt;&lt;span class="punct"&gt;=&lt;/span&gt;&lt;span class="constant"&gt;nil&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
          &lt;span class="ident"&gt;from&lt;/span&gt; &lt;span class="punct"&gt;||=&lt;/span&gt; &lt;span class="ident"&gt;current_revision&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;actor&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
          &lt;span class="ident"&gt;to&lt;/span&gt; &lt;span class="punct"&gt;||=&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;HEAD&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;
          `&lt;span class="ident"&gt;svn&lt;/span&gt; &lt;span class="ident"&gt;diff&lt;/span&gt; &lt;span class="comment"&gt;#{configuration[:local_repository_path]}@#{from} #{configuration[:local_repository_path]}@#{to}`&lt;/span&gt;
        &lt;span class="keyword"&gt;end&lt;/span&gt;

      &lt;span class="keyword"&gt;end&lt;/span&gt;
    &lt;span class="keyword"&gt;end&lt;/span&gt;

  &lt;span class="keyword"&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Then simply add this line to your config/deploy.rb...&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;require 'lib/tasks/patch_capistrano'
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;and everything works fine now.&lt;/p&gt;

&lt;p&gt;Note there are only two scm methods that access SVN from the local
machine, &lt;code&gt;latest_revision&lt;/code&gt; and &lt;code&gt;diff&lt;/code&gt;. I have patched both.&lt;/p&gt;

&lt;p&gt;I'll tidy this up, make the default for &lt;code&gt;local_repository_path&lt;/code&gt; be
&lt;code&gt;repository&lt;/code&gt;, and submit the patch to the Capistrano folks, who will
hopefully commit it to the source code, as it won't affect existing
users, but will make the rest of us a little happier.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://technorati.com/tag/capistrano+local+svn" rel="tag"&gt;&lt;/a&gt;
&lt;a href="http://technorati.com/tag/capistrano+local+repository" rel="tag"&gt;&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Wed, 15 Nov 2006 14:04:28 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:7e0dc63c-7ef2-49d9-bb32-bdadb8069799</guid>
      <author>Jim Morris</author>
      <link>http://blog.wolfman.com/articles/2006/11/15/allow-a-different-local-and-remote-subversion-repository-path-for-capistrano</link>
      <category>Rails</category>
      <category>rails</category>
      <category>capistrano</category>
      <category>subversion</category>
      <trackback:ping>http://blog.wolfman.com/articles/trackback/73</trackback:ping>
    </item>
    <item>
      <title>"Allow a different local and remote subversion repository path for Capistrano" by Rob Dupuis</title>
      <description>&lt;p&gt;When reading variable xxx In capistrano 2.1 (poss 2.0 too?) the scm recipes check for a local&lt;em&gt;xxx equivalent. So you can just use :local&lt;/em&gt;repository if you need to configure a different local repo url.&lt;/p&gt;</description>
      <pubDate>Tue, 16 Oct 2007 06:48:17 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:bafa04b4-40f0-496d-8c9b-7dce7de08411</guid>
      <link>http://blog.wolfman.com/articles/2006/11/15/allow-a-different-local-and-remote-subversion-repository-path-for-capistrano#comment-153</link>
    </item>
    <item>
      <title>"Allow a different local and remote subversion repository path for Capistrano" by Marcelo</title>
      <description>&lt;p&gt;Thanks a lot!&lt;/p&gt;</description>
      <pubDate>Wed, 14 Feb 2007 10:13:11 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:55cd5ead-a68d-445b-813a-9b5637a59950</guid>
      <link>http://blog.wolfman.com/articles/2006/11/15/allow-a-different-local-and-remote-subversion-repository-path-for-capistrano#comment-51</link>
    </item>
  </channel>
</rss>
