SVN Directory Lock
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. This script does not use the pysvn library. The reason for this is because I got too frustrated with the fact that the stupid library would not install on Red Hat Enterprise 4. I could not get either the RPM nor the source to install properly. It was easier to install Pexpect and simply script the command-line svn tools.
How to Use
When you create a lock no one will be able to commit to the locked directory or to any directory below it. The lock script will, of course, detect if you are commiting commiting a delete operation of an existing lock and the script will allow it.
Create a lock
To set a lock on a directory tree simply create a property on a directory called "lock":
svn propset lock TRUE trunk/project_a
Note that the value of the lock can be anything. I set it to TRUE, but you could make it a message or comment if you want.
Delete a lock
To remove a lock simply delete the property:
svn propdel lock trunk/project_a
I put the svn_dir_lock.py in my hooks directory. I add the folloing code to the pre-commit shell script:
SVNLOOK=/usr/bin/svnlook REPOS="$1" TXN="$2" python /home/svn/repository/hooks/svn_dir_lock.py -v "$TXN" "$REPOS" >&2 EXIT_STATUS=$? if [ $EXIT_STATUS -ne 0 ]; then echo "Delete locks before you checkin." >&2 exit 1 fi
<include src="/var/www/usr/local/apache2/htdocs/engineering/svn_dir_lock.py" highlight="python" />