We recently had a server DNS name change that affected our main SVN repository server, and required every checkout to be svn switch –relocate ‘ed.
In Eclipse I have every project checked out in ~/workspace/ so every directory with the matching server root would need to be switched. This shell script handled all the svn switch –relocate statements for me. Replace oldservername and newservername.
for dir in `ls -1 */.svn/entries | xargs grep -H -l oldservername | grep -E -o "^[^\/]+"`; do
svn switch --relocate `svn info $dir | grep ^Repository\ Root | cut -f 3 -d ' '` `svn info $dir | grep ^Repository\ Root | cut -f 3 -d ' ' | sed 's/oldservername/newservername/'` $dir
done
It may be best to make a backup of your project directories, especially if you have local uncommitted changes. This script works on bash-like command lines, such as Mac OS X.
hi brett,
found this blog entry while searching, and this script looks exactly like what i need. i recently installed an ethernet switch to replace my router, and in doing so the location of my svn server has had its ip changed.
stupidly, i used to use the full ip to access the svn server instead of a hostname, so all of my working copies now reference the old ip. i want to change all of the entries files so they now reference the hostname (and also the new ip) instead of the old ip and it looks like your script should work…although it doesn’t.
i have amended your script as advised, to the following:
old server ip = 192.168.0.172
new server hostname = newHub.local
for dir in `ls -1 */.svn/entries | xargs grep -H -l 192.168.0.172 | grep -E -o “^[^\/]+”`; do
svn switch –relocate `svn info $dir | grep ^Repository\ Root | cut -f 3 -d ‘ ‘` `svn info $dir | grep ^Repository\ Root | cut -f 3 -d ‘ ‘ | sed ‘s/192.168.0.172/newHub.local/’` $dir
done
but alas it does not seem to have any effect when i run the script.
do you have any idea why not?
thanks,
alex
by the way:
old server ip = 192.168.0.172
new server hostname = newHub.local
is not in the actual script file in case you were wondering!
I scriptified this with a few almost trivial changes:
* Use variables at the top of the script for more friendliness (could use command-line arguments, but meh)
* Change sed separators to pipes (|) instead of forward-slashes – helpful when changing protocols (e.g., from svn://x to http://x like I did) without needing to worry about escaping.
Just copy and paste below this line into a .sh script, put your server names into the appropriate places, and go for it (make sure you chmod +x the script).
#!/bin/bash
OLD_REPO=svn://youroldserver
NEW_REPO=http://yournewserver
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;
svn switch –relocate `svn info $dir | grep ^Repository\ Root | cut -f 3 -d ` `svn info $dir | grep ^Repository\ Root | cut -f 3 -d | sed s|$OLD_REPO|$NEW_REPO|` $dir;
done