Right now it is common to use version controlling system, continuous integration environment and some system for requirement management. Each day those tools are better but there are still plenty places for improvements. In current project I am using the following set of tools: JIRA + SVN + Jenkins.

Also we decided to divide task to following categories:

[list]

  • stories defined by product owner / team
  • submitted bugs,
  • others.

[/list]

For two first items there are of course connected entries in other tools. In this project I am using JIRA to manage both cases bugs and stories. But beside of that I would like to have a possibility to distinguish all cases in SVN repository. There was an agreement that we will use the following tags at begging of commit message in SVN:

[list]

  • [STORY-XXX],
  • [BUG-XXX],
  • [OTHER].

[/list]

XXX- number from JIRA

It was the easiest part. The next thing you need to do is to convince software developers to follow this rule. If you will not provide any tools they will forget about it. Of course you can use some tools to improve situation.

Let’s start from preparation of easy script, which will verify if developer provided correct commit message:

$commitMessageFile = Get-Content $args[2];

if (($commitMessageFile -eq $null) -or $commitMessageFile.length -eq 0)
{
  Write-Error "Commit message cannot be empty";
  exit 9;
}

$commitMessage = ($commitMessageFile)[0];

if (($commitMessage.length -eq 0) -or $commitMessage -eq $NULL)
{
  Write-Error "First line of commit message cannot be empty";
  exit 9;
}

$regexPattern = "^\[(((STORY|BUG|)-[0-9]*)|OTHER)\]\W.*"

if (!($commitMessageFile -match $regexPattern))
{
  Write-Error "Commit message does not have correct format.";
  exit 9;
}

Next thing that you need to do is saving this script somewhere on disk and change configuration of SVN. You need to open Settings of SVN and go to Hook Scripts:

TortoiseSVN - HookScripts

Then you need to add pre­_commit_hook and provide correct command to execute:

TortoiseSVN - Configure Hook Scripts

And that is all. The next time you will try to commit something your script will be executed before the code will be send to repository. Each commit with wrong commit message will be rejected. User will see the following message:

TortoiseSVN - Commit Failed

As you can see in the script you are using regular expression. So you have wide possibilities for tuning this solution for your needs. You can verify what you want in your commit message.