Advanced Rails - Building Industrial-Strength Web Apps in Record Time

(Tuis.) #1

310 | Chapter 10: Large Projects


There is a neat Subversion trick to add an existing directory tree “in place” to an
empty repository. You can use this when putting an existing application under ver-
sion control:


$ svn mkdir svn://repo/my_app/trunk

$ cd my_app
$ svn co svn://repo/my_app/trunk.
$ svn add *
$ svn ci

To add only certain directories without their contents, pass the-N(--non-recursive)
flag tosvn add. This is very useful when setting contents of certain directories to be
ignored; for example, these commands will add thepublic/attachmentsdirectory
while ignoring its contents:


$ svn add -N public
$ svn add -N public/attachments
$ svn propset svn:ignore "*" public/attachments

Subversion Externals and Piston


Subversion has anexternalsfacility for pulling in code from other repositories. When a
folder is designated as an external, it is paired with a remote repository. When
updating the working copy, code will be pulled from that repository in addition to
the main project repository.


In Rails, there are two reasons you would want to do this. The first is to lock Rails to a
certain version (or to track edge Rails). The second is for plugins: you may want to
follow updates to a plugin’s Subversion repository, so you can lockvendor/plugins/
plugin_nameto the plugin’s development repository. Thescript/plugincommand
even provides a flag that adds the plugin as an external rather than downloading it:


$ script/plugin install -x some_plugin

This works for small-scale applications, but the dependencies can quickly become
a mess. Most of the time, you will not want to follow the bleeding edge of Rails or
a plugin, but instead lock to a known-stable version. Althoughsvn:externalshas a
feature to do that, it can get messy. The biggest problem is that any local changes
you make to the external code are not versioned. In addition, updates are slow as
they must query each external server.


The best solution at this point is François Beausoleil’s Piston (http://piston.rubyforge.
org/). Rather than pulling a copy of the code from the remote Subversion server, Pis-
ton stores a copy locally, in your project’s own Subversion repository. It uses proper-
ties on the folder to track the current version at the remote repo. To Subversion, the
directory is just another set of files in your project. This means that updates are fast,
as they only talk to one server. You also only get external updates when you ask for
them (piston update).

Free download pdf