# Git commit hooks

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /homepages/3/d35174004/htdocs/tecnocode/wp-content/plugins/latex/latex.php on line 91

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in /homepages/3/d35174004/htdocs/tecnocode/wp-content/plugins/latex/latex.php on line 92

I recently wrote/extended a couple of git commit hooks which have turned out to be rather useful. Once is a fairly standard commit-msg hook to check the format of the first line of a commit message is either "Release version x.y.z", "[tag] Message" or "Bug 123456 — Title":

tags="core|atom|gd|media|build|docs|tests|calendar|contacts|documents|picasaweb|youtube"
test "" != "$(grep -P '^(Release version [0-9]+.[0-9]+.[0-9]+| [\S].+[\S]|Bug [0-9]+ — [\S].+[\S])$' "$1")" || { echo -e >&2 "First line of commit message should be in one of the following formats:\n * 'Bug 123456 — Title'\n * '[tag] Message'\ \n * 'Release version x.y.z'\nValid tags are:\n *${tags//|/\n * }"
exit 1
}

Just define the tags your project allows in the tags variable, separated only by pipes.

The other hook is a pre-commit hook to ensure any new API has a Since: tag if it's got a gtk-doc comment. It's implemented as a modification of the sample pre-commit hook, so here's the diff:

--- /home/philip/Downloads/4m8QcjYs.txt    2010-03-28 19:14:50.432440248 +0100
+++ pre-commit    2010-03-22 20:37:47.612794352 +0000
my $filename; my$reported_filename = "";
my $lineno; + my$in_gtk_doc_comment = 0;
+    my $used_since_tag = 0; sub bad_line { my ($why, $line) = @_; if (!$found_bad) {
@@ -64,6 +68,19 @@
if (/^([<>])\1{6} |^={7}$/) { bad_line("unresolved merge conflict",$_);
}
+        if (/^\s*\/\*\*$/) { +$in_gtk_doc_comment = 1;
+        $used_since_tag = 0; + } + if ($in_gtk_doc_comment && /^\s*\*\*\/$/) { +$in_gtk_doc_comment = 0;
+        if (!$used_since_tag) { + bad_line("new gtk-doc commented API without a Since: tag",$_);
+        }
+        }
+        if ($in_gtk_doc_comment && /\*\s+Since:\s+[0-9]+.[0-9]+.[0-9]+$/) {
+        $used_since_tag = 1; + } } } exit($found_bad);

It looks for the start of a gtk-doc comment block in any added code, and errors if it doesn't find a Since: tag before the end.

Hopefully these'll be useful to somebody. They've both turned out to be more useful to me than I'd hoped, so hopefully my commit messages make a little more sense now. The code for both of them is in the public domain.

# MCUS 0.3.0 released

Just a little note to say that:

1. I'm still alive, and
2. I've released version 0.3.0 of my microcontroller simulator, MCUS.

It's had a UI overhaul, and I've added accessibility support to the custom widgets (and improved it for the rest of the interface too). It's primarily intended for use in schools in the UK who teach A-level electronics, but I suppose it could be adapted to work for other purposes. It can be downloaded as a tarball (source), NSIS installer or ZIP package (for Windows).