Adding an External SVN Resource With Tortoise SVN

Most of my projects are usually checked out at several different computers and several different operating systems. For Windows, there is The One SVN Client Above All Else, namely TortoiseSVN. As Christer and I’ve been working on an unnamed project lately, we’ve built up a set of resources in regards to basic functionality (user registration, user verification, access management, etc). These resources have become a small framework for a basic site, so I’ve adopted the set of files for several other projects. When using the “Framework” in other codebases, I still want to keep the framework versioned against the original SVN repository, so that if Christer commits his Überkool Must Have Feature v2.5 to the framework, I get all the magic with a single svn up.

The magical way ofdoing this is using the svn:external property to tell svn that you depend on an external repository. The property is set on the parent directory, and contains the value Directory RepositoryURL; i.e:

Property Value
svn:externals Framework https://svn.example.com/Framework/trunk/Framework
OtherRepository https://svn.example.com/OtherRepository/trunk/

To set a property using TortoiseSVN, right click on the parent directory (i.e. libs or whatever you prefer to call your directory of common code), and select “TortoiseSVN” and “Properties”. Click “Add” and select svn:externals from the pulldown menu. In the value field you simply add Framework https://svn.example.com/Framework/trunk/Framework. Close the dialogs and select SVN Update when right clicking on your libs directory. This will create a directory named Framework in libs and check out the svn repository to the directory.

If you want several repositories as external dependencies in the same directory, add each repository on a new line.

Voilá!

UPDATE: Erik Hansen adds:
In order for Tortoise to “Update” your local copy with the external files, you first need to commit the property change to the REPO before it will do that.

UPDATE: Harry asked:

How do I provide other usernames and passwords for the other repositories? If my memory serves me right, as long as you’ve checked out the resource previously with TortoiseSVN, it will remember your username and password. I’d like an update for this, tho, as I’ve not been able to test it myself at the present time.

UPDATE: Chris added:
If you want several repositories checked out as external sources, add each repository on a new line under the same svn:externals property. Each directory can only have one externals entry, but the property may contain several repositories as long as they’re each put on a new line.

18 thoughts on “Adding an External SVN Resource With Tortoise SVN”

  1. I was looking for how to do this. One thing you might want to mention: In order for Tortoise to “Update” your local copy with the external files, you first need to commit the property change to the REPO before it will do that.

  2. Thanks too. But one question remains… if you have got non-identical accounts to the diverse svn-repositories how do you cope with the login-process the “tortoise”-way?

  3. Hi,
    thanks for the information, worked perfect.
    One thing though, include a tip that multiple externals need to be placed in separate lines. I kind of deleted my first external by adding a new one. So each SVN has ONE property externals, which in Tortoise can be used for many externals splitting them with newlines…

    See here for full doc, but I liked your short version better. And you were more on the top at google :-)

    http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-dug-import.html

    Chris

  4. We’re using external to link files for our products. The only issue that we have is, that when we link other directories (within the same or a different repository), we can’t see the content in the repo or web browser. So it appears that it only links it when we export or check out that folder. Is there a way to view the content as it is linked?
    I’m wondering if that would be something in regards to the server configuration, but I didn’t set it up, would like to help our IT guy though to correct this “issue” (unless this behavior is intended).

    Thanks!

  5. The externals setting is evaluated at checkout, as the subversion client then pulls the code from the 3rd party repository using the supplied credentials for the user (if located on the same server, this works automagically). There is nothing more stored in the original repository other than the URL of the second subversion resource. This means that the web interface is unable to show the actual data from the other repository, since it simply doesn’t live in the repository.

    It would be possible for a web interface to redirect the browser to another web interface or at least show the URL to the other repository. Pulling the other repository would probably require too much updating and mumbling about, but I’m sure someone has solved that problem too. I have no suggestions of any free (or payware) repository browsers that do this currently.

  6. Thanks for this article!

    I have a question … this is working perfectly for me, unless the directory already exists. For example …

    The repo i want is, let’s say, on – http://example.com/includeme/ and has a directory structure of …
    app/file1.php
    app/file2.php

    Now my other project in which I wish to pull in this external repo has a directory called app already there. I get this error when trying to update to pull it in …

    External Failed: d:\myproject\app
    Error: Working copy ‘d:\myproject\app’ locked
    Error: Please execute cleanup command

    now, if app wasn’t already there, then no problem. trouble is, app will be there for every project, i just want to pull in file1.php and file2.php.

    Thanks!

  7. Thanks Mats, I just read in the docs that you can’t pull in a directory that already exists. Pulling each file 1 by 1 … when I might end up with hundreds of files (aka – silk icons) isn’t a solution.

    But I think the solution might be to first set up an empty directory, pull in the main external starter kit … and then begin adding files to the individual projects. That sound right? I have to test this shortly.

  8. The format changed sometime before/during version 1.6 — this was kicking my butt from the command line because of that. Using TortoiseSVN had a tooltip that the format is now: URL directory, not directory URL

  9. Erik Hansen’s comment, no. 1 is incorrect. The externals definition from your working copy is used when checking out or updating. No need to commit to repo first.

Leave a Reply

Your email address will not be published. Required fields are marked *