Saturday, February 04, 2012

Demo Joomla! 1.5

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

Follow Me

Follow cedricwalter on Twitter Subscribe via RSS Subscribe via RSS Follow us on Facebook Follow us on Google+

Demo Joomla! 2.5

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

Support

Do not submit a bug report if you need technical support or have questions.

Forums

Post your suggestions ask for help in the community forums

Wiki

Visit the Wiki extensive and up to date documentation at your fingertips.

Contact Me

Missing images/links, any comments, suggestions, need help? Contact me

Skype

Need desperately help?
Skype Me™! But dont abuse of it!

How to check commit comments on SVN Commit

User Rating:  / 0
PoorBest 

subversion.logo

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:

  • The first one “checkCommentNotEmpty.sh” is for checking that nobody submit an empty SVN commit comment
  • The second one “checkCommentSyntax.sh” is able to enforce SVN commit comment pattern using regular expressions

Creating and Installing a Hook Script

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

  • start-commit Before the commit transaction starts
  • pre-commit After the commit transaction starts but before the transaction is committed
  • post-commit After the commit transaction completes
  • pre-revprop-change Before a revision property is changed Repository Path,
  • post-revprop-change: After a revision property is changed Repository Path
  • pre-lock:  Before the lock being acquired
  • post-lock:  After the lock being acquired

You’ll find examples in the hook directory named

  • post-commit.tmpl
  • pre-unlock.tmpl
  • post-lock.tmpl
  • pre-commit.tmpl
  • start-commit.tmpl
  • post-revprop-change.tmpl
  • pre-lock.tmpl
  • post-unlock.tmpl
  • pre-revprop-change.tmpl

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:

  1. the path to the root of the repository
  2. the transaction identifier
#!/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)

Avoid empty comment in SVN commits

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

noEmptySVNCommitComment

Enforce SVN commit comment pattern using regular expressions

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

checkSVNCommitCommentWithRegularExpressions

Want more?

You can automated code reviews with Checkstyle using pre-commit script and so Stop rule-breaking code before it enters your code base!

References

http://subversion.tigris.org/tools_contrib.html#hook_scripts List of some Hook scripts examples written in python/bash

You might also like:
Search And Replace Within Zip Files with Regular Expressions
4 days ago
Search And Replace Within Zip Files with Regular Expressions
There is a lot of shareware and freeware (jEdit, Notepad++) to do complex search and replacement in
The Build Tool Report: Turnaround Times using Ant, Maven, Ec
829 days ago
The Build Tool Report: Turnaround Times using Ant, Maven, Ec
          Even if the sample is quite small (600 responses), it still interesting goin
Web page as Graphs with source code
975 days ago
Web page as Graphs with source code
Webpages as Graphs With this funny applet, you can judge of the complexity of a web page by just
Atlassian just acquired GreenHopper
978 days ago
Atlassian just acquired GreenHopper
Atlassian just acquired GreenHopper, a popular JIRA plugin with over 800 customers. GreenHopper
blog comments powered by Disqus
Parent Category: Java
Category: Tools

Donations

Thank You for supporting my work

Latest Articles

  • Thanks to Ondřej Surý,  maintainer for some Debian packages, you can have the latest PHP5 maintained by Debian ... ...
  • Munin is a networked resource monitoring tool that can help analyze resource trends and "what just happened to ki... ...
  • The General Robotics, Automation, Sensing and Perception (GRASP) Lab, located at the University of Pennsylvania, is al... ...
  • There is a lot of shareware and freeware (jEdit, Notepad++) to do complex search and replacement in files but none is su... ...
  • Data URI scheme is a URI scheme that provides a way to include data in line in web pages as if they were external reso... ...

Latest Comments

Popular Posts

rockettheme advertisement

dropbox logo

Help Us & Leave Feedback!

  • Do you have an excellent article idea you would like to read about here? Share it!
  • Do you have some interesting tips how we could improve our site?
  • Something missing here? Help us make this blog a better place, leave feedback!
We would love to hear from you! Be active! Write us now!

Blogs

Didier Beck Tech Head Brothers

google+ badge