« Perhaps Pluralize Means Something Other Than I Thought | Main | No Software Keys Required »

svn:externals

Listen to this articleListen to this article

This relatively unknown feature of subversion allows you to include one subversion repository URL inside another. By that I don't mean export and add, rather svn:externals allows you to create a virtual directory that links to an external repository.

I'm sure there are plenty of other uses but I mostly use svn:externals for adding plugins to my rails projects. For example, if you wanted to link to the Foreign Key Migrations plugin, from inside your rails project directory you would type:

simon$ svn propedit svn:externals vendor/plugins/

Then add the following lines:

foreign_key_migrations svn://rubyforge.org//var/svn/redhillonrails/trunk/vendor/plugins/foreign_key_migrations
schema_defining svn://rubyforge.org//var/svn/redhillonrails/trunk/vendor/plugins/schema_defining

And voila! Now when you update your project you'll see something like:

simon$ svn up 

Fetching external item into 'vendor/plugins/foreign_key_migrations'
External at revision 25.


Fetching external item into 'vendor/plugins/schema_defining'
External at revision 25.

At revision 2533.
simon$

Notice how subversion updates the virtual directories as well.

Be aware though that this does mean you'll always get the latest code when you update. This is exactly what I want but may not suitable on all projects. Sometimes a simple svn export is more appropriate.

We're currently toying with the possibility of using svn:externals to share common code between some projects that are presently all in one big code-soup project but will be split up over the next couple of months. I'll let you know what we decide to do in the end.

Comments

Is this the same thing that the script/plugin installer does when you specify the -x flag?
Thanks, Scott

This is a great feature. The CVS modules files (for those still using CVS) can do exactly the same thing. Very powerful means of having code in different structures and then pulled out and worked on as one development unit.

Perhaps you have also missed the more unknown feature of specifying
foreign_key_migrations -r25 svn://rubyforge.org//var/svn/redhillonrails/trunk/vendor/plugins/foreign_key_migrations

That locks your external to a certain revision. Perfect for making builds etc. Develop against head if needed, but then lock the revision when building. However, I do not know how to do that bit automatically...

No no, you're absolutely right. It's another reason I love it :)

Scott,

Yup. It's exactly the same thing. So for your plugins it's a no brainer however I thought I'd blog it because it's a feature that I think has loads more potential and is under-used.

Cheers,

Simon

also very useful when you have common code between applications.

Might be a wierd requirement, but recently we put together a desktop app which was supposed to have a central rails server component as a rails app (so basically we had two rails apps, one the server itself and the other the rails app which sat on each desktop). So basically there was a lot of code that was common between the two apps. So we just pulled it into another project and used svn:externals to sync the code.

Post a comment