Locked SVN Repo

Have you ever been working on an SVN server and had to ask yourself, “Why in tar-nation is this file not commiting???!! And who is Joey to be so important to lock a file.” For which you gather all your rage and ask Joey why he had the audacity to lock the files you needed to commit? He tells you he didn’t lock them, nor is he working in the same area of the code. Then you discover that by some way he accidentally locked 1/4 of all the files scattered throughout the repository. Since you are very smart you went to the server command line and did:
svnadmin lslocks [path to repo]
And it told you all the locks in the system.

Now you should be thinking, how can I take that list and then unlock the whole server? I too faced this same problem. This is how I dealt with it. First don’t mess with svnadmin rmlock… I couldn’t make it work to save my life. The setup is like this, we are going to grep out some keywords from the svnadmin lslocks to get only paths, then we are going to use awk to help us build perfect paths, then we are going to use the svn client to finish the job. And it all fits on one line.
*Important: Make sure your local copy is updated to the latest revision.
svnadmin lslocks /usr/local/svn/repos/[repo-name]/ |grep Path | awk '{print "file:///usr/local/svn/repos/[repo-name]" $2}' | xargs svn unlock --force

Thanks to some nifty piping, you have just unlocked your whole SVN. Let me explain some key points here, “Path” next to grep will draw out something that looks like this:

Path: [Path to locked file]
Here is a really quick run down of awk, basically it takes any white space and then seperates the information into variables starting with $0 being the whole line, $1 being the first, $2, the second, etc. $1 would be the word “Path:” and $2 is our path. But that is not enough because we have to make it a qualified repo path, and since I am doing it on my local server I can use the “file:///” prefix. After that we send it to xargs and then use svn unlock and xargs will apend the argument to the end of the line. –force is also important because that will make sure you steal the lock in the unlock process.

FINE PRINT aka Caution: SVN locks were designed to protect files while a person is working on those files so no one else could over write them while they were developing on those files. The idea is that someone can get exclusive access to the files, change them, commit them, and then release the lock when the work is completed. If you are using this type of idea for your system, please send the list of locks to all of your developers and then have them manually unlock the locks they set. Otherwise you can ruin and destroy work in progress if you are not careful. Now if you do not care about locks and know what is being developed, by all means use the function above.

If you have a better way to unlock your svn repository I’d love to hear it, I created this method from my own knowledge of the shell. If you need some help or have questions, post a comment and I’ll get back with you.

Cheers,

-m

    • Daniel
    • June 22nd, 2011

    You made my day! Thank you very much!

  1. No trackbacks yet.