Updated: October 6th, 2009

Introduction

Every time I have to deal with svn:externals in SVN, I forget the command line syntax. Every single damn time. Normally, I use SVN GUI clients, such as SmartSVN, which make it very simple to add an svn:externals property. But for command line, it always takes looking at 25 different sites on google, which are all incredibly unhelpful for this question for some reason. Trying "svn help propset" on the command line was bloated and equally useless.

So this time I needed to write it down and make sure everyone who needed help with svn:externals would find exactly what they need here. I hope this page will soon come up on top of all the unhelpful results on google for "propset svn:externals" and other related queries.

The Problem

I want to set a simple svn:externals property in one of my project's directories, lets say 'plugins' (talking about WordPress here). The outcome would be a directory called 'akismet' within 'plugins' that points to a remote svn url.

Various combinations of trying to do it produced pathetic results, like

svn propset svn:externals akismet http://plugins.svn.wordpress.org/akismet/trunk
svn: Setting property on non-local target 'http://plugins.svn.wordpress.org/akismet/trunk' needs a base revision
svn propset svn:externals . akismet http://plugins.svn.wordpress.org/akismet/trunk
svn: Error parsing svn:externals property on 'akismet': '.'
svn propset svn:externals akismet http://plugins.svn.wordpress.org/akismet/trunk akismet
svn: Setting property on non-local target 'http://plugins.svn.wordpress.org/akismet/trunk' needs a base revision

The Solution

Finally, thanks to this post, I found the right command:

svn propset svn:externals 'akismet http://plugins.svn.wordpress.org/akismet/trunk' .
property 'svn:externals' set on '.'

Note that dot at the end of the command and the quotes around the directory name and url.

Now commit via

svn commit

and then

svn up
Fetching external item into 'akismet'
A    akismet/akismet.gif
A    akismet/akismet.php
A    akismet/readme.txt
Updated external to revision 127962.
 
Updated to revision 16.

There, was it that hard, forum gurus and blog fiends?

Edit: in order to set multiple directory/url pairs in a single svn:externals property, you should put the individual dir/url pairs into a file (let's call it 'svn.externals'), like so

akismet http://svn.wp-plugins.org/akismet/trunk
all-in-one-seo-pack http://svn.wp-plugins.org/all-in-one-seo-pack/trunk

and then apply the property using

svn propset svn:externals -F svn.externals .

You should also just check in 'svn.externals' to easily keep track of it.

● ● ●

Artem Russakovskii is a San Francisco programmer, blogger, and future millionaire (that last part is in the works). Follow Artem on Twitter (@ArtemR) or subscribe to the RSS feed.

In the meantime, if you found this article useful, feel free to buy me a cup of coffee below.



Share
  • grundic

    Also you can't set property if you don't have a local working copy. If folder is tooo big to checkout completely you can run this command:

    svn co svn://branck/blah -N

    So easy, but I also spend lot of time figuring this out. Hope, this helps.

  • http://xentek.net/ Eric Marden

    If you have your SVN_EDITOR set in your .bash_profile (i.e. export SVN_EDITOR=/usr/bin/vi), you can do this a lot easier with this command (run from inside the dir you want to create the external link in):

    svn pe svn:externals .

    This will open up your editor, and allow you to easily manage the "foldername http://repos/path" entries from a much nicer interface.

    I use svn:externals so much I set up a bash alias that shortens the command even further to just: svnext

    In fact, I've got a whole library of little svn shortcuts set up as aliases in .bash_profile that make working with svn on the command line easier and more powerful than any GUI.

  • http://www.superwebdeveloper.com pbgswd

    I dont know all Eric's tricks but I really like the what you can do with these techniques. Its a huge huge huuuuuge labor saver.

    I worked out the process for pulling WordPress core and plugins and themes in one script.

    http://www.superwebdeveloper.com/2009/11/07/installation-script-using-wordpress-subversion-repositories/

  • JustAnotherDude

    Also, every page says "you can even specify a specific revision", but few actually give an example of the syntax for referencing a specific revision.

    Augmenting the example above you do it like this:

    svn propset svn:externals 'akismet -r 22 http://plugins.svn.wordpress.org/akismet/trunk' .

    Notice the "-r 22" where 22 is the desired revision number.

  • http://www.stylecandy.com/ Gareth

    Hey, thanks this helped out quite a bit I ended up doing it slightly differently but got it working which is the main point.

    Regards

  • Diego

    How can I commit different externals on their own repo?
    Thanks

    • http://beerpla.net Artem Russakovskii

      Diego, I believe this is impossible. See this post on StackOverflow for details. In short, you can try to use Eclipse's commit which handles this automatically.

  • http://www.graq.co.uk GRAQ

    Thanks Artem!

    Am creating an install routine for WordPress builds, loading public and private plugins and themes. Perfect.

  • Kalle

    *love* <– this is all I wanted to say, really, for you saving my ass on an increasingly frustrated "gaah" moment of trying to propset the svn:externals deal, but I got a "comment too short" whine at me. Bah :)

    • http://beerpla.net Artem Russakovskii

      Glad I could help :-]

  • john random hacker

    thank you very much. svn sucks. git ftw!

  • cheapshot

    Thanks Russakovskii.
    I had the same problem.
    I was used to command line and then forced to use SmartSVN because this trouble, that is not covered on svn redbook. It's a pity that properties on svn is so documentation missed.

  • Timothy Nott

    Thanks for the post. Saved me eons, I'm sure.

  • Eric

    I use a slightly different version. It let's you edit multiple externals via your editor of choice (ie. Vi)

    Assume you have an externals folder called 'ext'

    cd into that directory and then you can run 'svn propedit svn:externals .'

    That will allow you to edit all externals defined in that directory through your editor.

  • Jean Deruelle

    Thanks for the post, worked great !

    We use it for having a main docs directory (http://mobicents.googlecode.com/svn/trunk/docs/) on Mobicents (http://www.mobicents.org/) which gather the docs from multiple subprojects that the main content authoring person can checkout without checking out the full SVN

  • Srikanth

    Hi,

    I am a SUBVERSION NEWBIE and I had a requirement in which we need to force each and every user to enter comment in a specified format like
    BUG ID:
    REV NO:
    …like. And Clearly I am dumb about how to start. Looking for your valuable help on this.

    Thank you,
    Srikanth

    • Ismael Casimpan

      Hi there Srikanth. You need to know scripting like bash or perl. You can do what you want via the hook scripts. In your repository hooks directory (say /var/repo/svnrepo01/hooks), you can look at pre-commit.tpl to start with.

      I'm sorry I cannot spoon-feed you with everything but if you know scripting, that's all that you need to start from.

      Good Luck!
      Ismael Casimpan

  • Ricky

    It's worth pointing out here when using the svn client commands under the Windows environment the single quotes need to be replaced for double quotes or you will get the following svn error:

    svn: Cannot specify revision for setting versioned property 'svn:externals'

  • Aj

    Thank you! The documentation on this is pretty lame. Took a few minutes of Google searching to figure out my mistake.

  • KNRO

    Thanks! I've done this so many times before, but when I needed to do it again, I forgot!

  • Mike

    The format changed sometime during or before SVN version 1.6. The TortoiseSVN client had a tooltip showing that the format is now:
    URL directory-name
    not:
    directory-name URL

  • Andrew

    Thanks!!! You save my day!

  • Patrick Salami

    Thanks for the info! This was very helpful. However, I noticed a small issue: I tried this with SVN 1.6.6 and after I issue the propset command, I tried to do the commit but it complained that the directory was out of date. I had to do svn up *before* doing svn commit in order for it to work.

  • Aaron Newton

    Awesome stuff bro.

    Externals seems like a good option when I'm in a non-Java environment (which is pretty often) and lack a tool like Maven – very handy.

  • aaron

    My svn, version 1.6.6 has the externals parameters in the reverse order.
    For my system, your command would be

    svn propset svn:externals 'http://plugins.svn.wordpress.org/akismet/trunk akismet'

  • Lucas Souza

    Thanks, very useful!

  • steve

    Thank you!
    As commented above, I needed to use double-quotes on Windows, and needed the "svn udpate" before the "svn commit".

    The concept I had been missing is that the 2nd arg to propset is the property value, and this needs to be within quotes because it contains a space, in order for it to parse correctly.

    Glad that your solution came out near the top of the google search!

  • eplinux

    hi ,I have a trouble;
    svn ps svn:externals 'servicebase svn://search.svn/servicebase' .
    svn ci
    svn up
    then svn up print skip '.' and servicebase dir have not files

  • Ben

    Nobody has provided an example of how to pin svn:externals at a specific revision number with SVN 1.7 on Windows platforms. So, here it is (don't forget the period at the end):

    svn propset svn:externals — "-r661 ^/../framework/trunk/database database" .

    Windows requires the double-dash before the argument, otherwise SVN returns an error:

    svn: E205000: Syntax error in revision argument '661 ^/../framework/trunk/database database'

    • Ben

      It appears that WordPress converted the double-dash ("- -", without the space) to an em-dash in my previous comment. So, be sure to replace the em-dash with two regular dashes (minus signs).

  • Rajneesh

    Commands to link a file:

    touch abc.xml

    svn propset svn:externals 'abc.xml https://svn.com/svn/product/trunk/conf/jboss/common/server/default/deploy/abc.xml-mysql' .
    property 'svn:externals' set on '.'

    svn stat
    X abc.xml
    M .

    svn ci . -m "rajneesh – attempting to create soft link between abc.xml and abc.xml-mysql"

  • Marc

    Thanks! FYI: this site came on top when I googled for "svn add externals command".

  • Charles Hasegawa

    Thanks! I always forget how to "apply" changes to the .externals file when I update it

  • Pingback: Various SVN Notes | thoughts of a pragmatic programmer

  • http://webreaktor.net/ Jonathan Gruber

    Saved me alot of head scratching. Thanks!