nwinkler nwinkler - 1 year ago 103
Bash Question

How to SVN relocate multiple directories

I would like to relocate multiple checked out SVN directories on my local machine, since our SVN server moved and now has a different IP address. Instead of doing this through a tool like SmartSVN or TortoiseSVN, I would like to use a script to do the directories in one sweep.

Each directory contains a different working copy - so either a different project or sometimes also a different branch or tag, therefore I can't just do the relocate in the root directory.

Answer Source

I found a partial solution here, and also an improved version in the comments, but I wanted to clean it up a bit and provide it here for other people as well

The IP addresses are fictional and need to be adjusted to local settings.

The script iterates over all directories that are managed by SVN and use the old location, then calls the svn switch command with the relocate option for each one.



for dir in `ls -1 */.svn/entries | xargs grep -H -l $OLD_REPO | grep -E -o ^[^\/]+`; do
    echo Switching sandbox $dir from $OLD_REPO to $NEW_REPO;

    OLD_ROOT=`svn info $dir | grep ^Repository\ Root | cut -f 3 -d ' '`
    NEW_ROOT=`echo $OLD_ROOT | sed "s|$OLD_REPO|$NEW_REPO|"`
    svn switch --relocate $OLD_ROOT $NEW_ROOT $dir;

If you also want to change the user while relocating, it's easy to add something like --username $USERNAME parameter to the command, and defining the $USERNAME at the top of the script.