Joomla Extensions Demo

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

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

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
111 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
936 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
1082 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
1085 days ago
Atlassian just acquired GreenHopper
Atlassian just acquired GreenHopper, a popular JIRA plugin with over 800 customers. GreenHopper
Jedit shortcuts reference
2495 days ago
Jedit shortcuts reference
Keyboard ShortcutsFilesControl-NNew file.Control-OOpen file.Control-WClose buffer.Control-E Control-
Metrics and Models in Software Quality Engineering  book - A
2737 days ago
Metrics and Models in Software Quality Engineering book - A
"For more than 50 years software has been a troublesome discipline. Software's problems are numerou
Good tools for developer
2803 days ago
Good tools for developer
TCPviewer dsplay TCP connections in realtime and ProcessXP shows all processes and their dependant
blog comments powered by Disqus
Category: Tools

Donations

Thank You for supporting my work
Subscribe to me on YouTube

Latest Articles

  • In this series of post I will outline some common techniques to help Joomla extensions development. As you know Jooml... ...
  • CedTag  has been updated to version 2.5.3 and correct a lot of bugs and contains some nice features. CedTag is t... ...
  • CedThumbnails has been updated to version 2.5.5 and contains 1 new features for both Joomla 1.7 and Joomla 2.5. For ex... ...
  • CedSmugmug  has been updated to version 2.5.2 and correct some bugs and contains some nice features. CedSmugmug&... ...
  • If you want an extra gigabyte of storage on your Dropbox account, the online cloud service invites you to compete in i... ...

Subscribe

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!