Visit the Joomla! 1.5 demo site to see my extensions live running




/ 0
If you are using Subversion/CVS, you might have come across the issue where multiple developers working on a set of files are committing without any comments.
Subversion’s hook scripts provide a powerful way to associate actions with repository events. For example, the pre-commit hook allows you to check — and possibly abort — a transaction before it actually gets committed. I will provide you now two easy Unix bash scripts that avoid bad developer behaviors:
Your Subversion repository already has some template hook scripts. For example, the pre-commit template is in PATH_TO_REPOS/hooks/pre-commit.tmpl. These templates contain instructions on what the hook script does and what parameters it can expect.
You can hook your own script on the following events
You’ll find examples in the hook directory named
If you cant find them, brute force your server to locate them
# find / –name pre-commit
or
# locate pre-commit
On Debian you will find them at
/data/svn-repos/{yourRepository}/hooks
Create a file pre-commit with that content, nothing force you to put a huge bash script in pre-commit. In my example below, I prefer to divide pre-commit checks in multiple files. The pre-commit hook gives you a way to catch the transaction before it becomes a revision. Subversion passes this hook two parameters:
#!/bin/sh
set -e
/data/svn-repos/{yourRepository}/hooks/checkCommentNotEmpty.sh "$1" "$2"
/data/svn-repos/{yourRepository}/hooks/checkCommentSyntax.sh "$1" "$2"
Note that after installation, every commit will run these two scripts. Check your permissions, scripts have to be runnable for the user (www-data on debian)
Save this file in /data/svn-repos/{yourRepository}/hooks/checkCommentNotEmpty.sh
#!/bin/sh
REPOS="$1"
TXN="$2"
SVNLOOK=/usr/bin/svnlook
if [`$SVNLOOK log -t $TXN $REPOS` != ""]; then
echo "" 1>&2
echo "*** Your commit has been blocked because you did not give any log message or your log message was too short." 1>&2
echo "Please write a log message describing the purpose of your changes and then try committing again." 1>&2
exit 1
else
exit 0
fi
Example in Eclipse, if you break the rule
Save this file in /data/svn-repos/{yourRepository}/hooks/checkCommentSyntax.sh
This script use Bash script REGEX capabilities, I check against what could be a typical JIRA issues entry
If any developer try to use a commit statement not starting with for example PRODUCT-xxxx, the commit will be blocked.
#!/bin/sh
REPOS="$1"
TXN="$2"
SVNLOOK=/usr/bin/svnlook
regex="PRODUCT-[0-9]*"
if [[ `$SVNLOOK log -t $TXN $REPOS` =~ ${regex} ]]; then
exit 0
else
echo "" 1>&2
echo "*** Your commit has been blocked because you give an invalid commit comment" 1>&2
echo "Please make your commit comment start with PRODUCT-XXX" 1>&2
exit 1
fi
Example in Eclipse, if you break the rule
http://subversion.tigris.org/tools_contrib.html#hook_scripts List of some Hook scripts examples written in python/bash
Privacy Statement | Copyright Notice | Licenses
1999-2011 Cedric Walter - All Rights Reserved






