Rails plugins & svn:externals

Rails plugins are cool. Installing them as svn:externals is cool (mostly). What is not so cool is that some plugins have svn:externals incompatible URLs. In my current project there are two such plugins:

When you install them with script/plugin install -x, they are installed as for-1.2 and trunk, respectively. This is because Rails’ plugin installer takes the final part of a URL as the plugin name and apparently there is no way to change it.

Of course, names like trunk are not very good. In bigger projects with several plugins it may be difficult to remember which name points to which plugin. It’s also easy to imagine that someday we might want to use another plugin that has a URL ending with trunk.

You cannot change names of external directories with svn move and mv tool also doesn’t seem to work. Fortunately, I found other ways to fix this situation.

One way…

If you have already installed plugin as external, using e.g.:

script/plugin install -x http://svn.globalize-rails.org/svn/globalize/branches/for-1.2

there’s a for-1.2 directory in your vendor/plugins directory. We can check with svn propget where does the plugin come from:

$ svn propget svn:externals . 
for-1.2 http://svn.globalize-rails.org/svn/globalize/branches/for-1.2

But in the long run it’s better to change it to real name (don’t forget to set your EDITOR environment variable):

$ svn propedit svn:externals .

In the editor just change for-1.2 to globalize, save and exit. Now, when you perform svn update, the plugin code will be downloaded once again, but this time to the appropriate directory. The old directory can be safely removed with script/plugin remove for-1.2 or just rm. Don’t forget to commit the changes to svn server!

What’s cool is that script/plugin now treats the plugin as if it was called globalize from the start. For example, to remove it you just need script/plugin remove globalize.

…or another

Another way requires that you take appropriate measures before installing plugin. Instead of using script/plugin to install the plugin, just check it out under correct name and the set it to svn:external later. Like this:

$ cd vendor/plugins/ 
$ svn checkout svn://rubyforge.org/var/svn/mocha/trunk mocha 
A    mocha/test 
A    mocha/test/unit 
[... snip ...] 
A    mocha/templates 
A    mocha/templates/html_with_google_analytics.rb 
Checked out revision 164.

Now plugin mocha is under correct directory but it’s still not svn:external, as can be seen using svn status. To fix this we need:

$ svn propedit svn:externals .

and in the editor add the following line anywhere in the file:

mocha svn://rubyforge.org/var/svn/mocha/trunk

Now svn status happily reports mocha as external and we can commit the changes.


3 responses to “Rails plugins & svn:externals

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: