How To Manually Recursively UNLOCK files in Subversion (svn)

Today, something bizarre happened to me – another developer asked me to unlock a file he needed in subversion.  Huh?   Turns out I had locked 379 random files throughout the subversion repository through no fault of my own. 

The previous week we had a power outage and I had issues with subversion for a while.  Doing an update on my local working directories would hang, leaving local locks which I had to cleanup.   I upgraded to the latest version of tortoise, but never did any commits. Ultimately, whatever was affecting the subversion server was resolved and everything appeared to be working correctly. 

Normally, I’d use svnadmin to cleanup the locks, but since I don’t have access to the server, I had to figure out a way using only my subversion client.   The problem is, there just isn’t an easy way to do this.

When confronted with the horrifying prospect of spending hours using tortise’s subversion repository browser to look in hundreds and hundreds of directories searching for locked files, I decided that the Linux command line was a much efficient way to go.

First, we need to get a list of status updates:

$ svn status –u

However, this list contains more than locked files.  We need to filter that list down to only locks, and put it into a file:

$ svn st –u | grep “^…..O” > locks.txt

Next, I piped the file to sed and replaced the first two columns and whitespace with the url of the repository.  This will build a list of URLs that needed to be unlocked, prepended with the repository URL so that the svn unlock command can use.

 $ cat locks.txt | sed ‘s/…..O[ \t]*[0-9]*[ \t]*/http:\/\/server\/svn\/path\/to\/project\//’ > locked-urls

Next, I quickly cobble together a bash script to read each line and put it into a variable ($line) and execute “svn unlock $line.” 

Within fifteen minutes I was done.  Nice.


This entry was posted in SCM. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s