Search code examples
bashsvnversion-controlcmdbranch

Checkout a complete Subversion tree excluding tags/ and branches/


I'm working on a corporate source code tree that contains 100s of Maven sub-projects. Since each sub-project has its own layout of branches/ and tags/ sub-folders, the entire tree is laid out something like this:

root/
    some/intermediate/dirs/
        project1/
            branches/
                ...
            tags/
                ...
            trunk/
                ...
        project2/
            branches/
                ...
            tags/
                ...
            trunk/
                ...
        ...
        projectN/
            branches/
                ...
            tags/
                ...
            trunk/
                ...
    other/intermediate/dirs/
        projectN+1/
            ...

I need to check out the trunk/ versions of all the projects but unfortunately, the command $ svn co protocol://path/to/repo/root/ checks out complete versions of tags and branches leaving me with thousands of redundant source trees and taking forever.

Moreover, N is a very large number and it is not practicable for me to go in and check out each project's trunk individually.

Is there an svn command that will enable me to skip tags/ and branches/ trees?

I found a blog that explains how to write a Java program to accomplish this using the SVNKit but I was hoping I could get it done using a one-liner from the command line.

Update: A solution using only the svn executables is preferred, but if some shell scripting is needed, I would prefer a Windows batch script or, failing that, any bash or zsh script would do...


Solution

  • What you need is SVN sparse directories.

    You'll want a skeleton structure, and fill in only the trunks when you get to them. Something like (Bourne shell syntax):

    svn co --depth empty protocol://path/to/repo/root/
    for in in some intermediate dirs; do svn up --set-depth empty $i; cd $i; done
    svn up --depth immediates .
    for i in *; do svn up --depth infinity $i/trunk; done
    

    I'm assuming none of the directories in question contain spaces or shell metacharacters - add appropriate quoting if necessary.

    Beware when using sparse directories - it's easy to lose track of what's excluded and what doesn't actually exist...