SVN Directory Lock

Jump to navigationJump to search

SVN does not allow directories to be locked. You can lock individual files, but not entire directory trees. The following pre-commit hook will allow for advisory directory locks. That is, a directory lock will prevent a commit, but anyone can set or clear a lock.

Often it is useful to lock an entire directory to be sure that it remains consistent during testing or deployment.

This scripts requires that Pexpect be installed. Pexpect is a standard Debian/Ubuntu/RedHat package. This script does not use the pysvn library. The reason for this is because I got frustrated that the stupid library would not install on Red Hat Enterprise 4. I could get neither the RPM nor the source to install. It was easier to use Pexpect to script the command-line svn tools.

How to Use

When you create a lock no commit will be allowed to the locked directory or to any directory below it. The only exception is for a commit that deletes the lock itself. This is to allow a directory to be unlocked.

Create a lock

To set a lock on a directory tree simply create a property on a directory called "lock" and then commit the directory.

svn propset lock TRUE trunk/project_a
svn commit trunk/project_a

The lock script does not care what value the lock property is set to. The script only checks if the lock exists or not. The example above set the lock property value to TRUE, but the value could have been a descriptive text message giving the reason for the lock.

svn propset lock 'Locked for bug hunting. Ask the build engineer if you have questions.' trunk/project_a
svn commit trunk/project_a

Others can then see the value of the lock for a description of why the lock was set.

$ svn propget lock trunk/project_a
Locked for bug hunting. Ask the build engineer if you have questions.

Delete a lock

To remove a lock delete the lock property:

 svn propdel lock trunk/project_a

Repository Installation

I put the in my hooks directory. I add the folloing code to the pre-commit shell script:

python /home/svn/repository/hooks/ -v "$TXN" "$REPOS" >&2
if [ $EXIT_STATUS -ne 0 ]; then
    echo "Delete locks before you checkin." >&2
    exit 1
fi Source

<include src="/home/noahspurrier/" highlight="python" />