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.
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" />