Wednesday, March 10, 2010

Subversion server moved, how to fix local working copies

I ran into a problem recently with a project from SourceForge. SF had changed the name on the Subversion server so it is now per project. The old repository url was

https://svn.sourceforge.net/svnroot/jedit/plugins/Beauty/trunk

and the new one is:

https://jedit.svn.sourceforge.net/svnroot/jedit/plugins/Beauty/trunk

Since I'm the only one working on this project, and the current code is what I last checked in, I didn't bother to do an update before making some significant changes, otherwise, I might have noticed the problem earlier. When I went to commit, I got this rather cryptic message:

Committing ...

svn: Commit failed (details follow):
svn: Repository moved temporarily to '/svnroot/jedit/plugins/Beauty/trunk'; please relocate
svn: OPTIONS request failed on '/svnroot/jedit/plugins/Beauty/trunk'


It took a little digging around to figure out the problem was that the name of the repository had changed. I knew about it, but it happened a while ago, so I'd forgotten.

I didn't want to have to check out from the new repository location and copy my old working files. Using "svn switch" won't work because "switch" requires the files to be within the same repository. All I needed to do was fix the "entries" files in my local .svn directories. This little script does it:

for i in `grep -rl 'https://svn.sourceforge.net' .*`; do
sed --in-place -e 's/https:\/\/svn.sourceforge.net/https:\/\/jedit.svn.sourceforge.net/g' "$i"
done

1st line: grep for the string I want to replace
2nd line: replace it. Notice that the slashes in the url have to be escaped.

A word of warning: The ".*" pattern on the 1st line matches "..", which means this will search and replace not only in the current working directory, but also the parent directory. In my case, that is a good thing, since I have a number of jEdit plugin projects in the parent directory and this changed them all at once for me. If you don't want that to happen, make a new, empty directory, copy your working copy directory into this new directory, so that when you run this script from within your working copy directory, there is nothing else in the parent directory to be affected.

3 comments:

phil pirj said...

Thanks man. Worked fine for me with an exception of I had to use -i instead of --in-place (OSX10.4)

phil pirj said...

BTW
find ./ -type f -exec sed -i ‘s/old/new/’ {} \;
works just the same

Vaghinak Petrosyan said...

There is much elegant solution for this

svn sw --relocate https://svn.sourceforge.net/svnroot/jedit/plugins/Beauty/trunk https://jedit.svn.sourceforge.net/svnroot/jedit/plugins/Beauty/trunk