Repairing SVN Working Copies
May 30th, 2008Unfortunately an all too common problem with Subversion is accidentally deleting the .svn directory used to track changes on a working copy. The accepted solution seems to be to check out to somewhere else the directory to which .svn belongs and then copy the new .svn directory into where the working copy’s should have been.
I wrote the following bash script to automate this repair process:
#!/bin/bash
if [ "$1" == "help" ]; then
echo "Useage: svnrepair repository_dir local_dir"
exit 1;
fi
if [ -n $1 ] || [ "$1" == "." ]; then
repo_dir=`svn info | awk '/URL: (.*?)/ {print $2}'`
else
repo_dir=$1
fi
if [ -n $2 ] || [ $2 == "." ]; then
local_dir=`pwd`
else
local_dir=$2
fi
svn co $repo_dir delme; cp -r delme/.svn $local_dir; rm -rf delme