SVN pre-commit hook for avoiding changes to tags subdirectories

I don’t have enough reputation to “comment” on Raim’s answer above, but his worked great, with one exception, his grep pattern is wrong.

I simply used the below as my pre-commit hook (I didn’t have an existing one, you’d need to merge in that case):

#!/bin/sh

REPOS="$1"
TXN="$2"

SVNLOOK=/opt/local/bin/svnlook

# Committing to tags is not allowed
$SVNLOOK changed -t "$TXN" "$REPOS" | grep "^U\W.*\/tags\/" && /bin/echo "Cannot commit to tags!" 1>&2 && exit 1

# All checks passed, so allow the commit.
exit 0

The only problem with Raim’s grep pattern is that it only matched “tags” if it was at the “root” of your repo. Since I have several projects in my repo, the script as he wrote it allowed commits on tag branches.

Also, be sure to chmod +x as indicated, otherwise you’ll think it worked b/c the commit failed, but it failed b/c it couldn’t exec the pre-commit hook, not because the hook worked.

This was really great, thanks Raim. Much better and lighter weight than all other suggestions as it has no dependencies!

Leave a Comment