Kore Nordmann - PHP / Projects / Politics ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :Author: Kore Nordmann :Date: Wed, 16 Sep 2009 17:12:05 +0200 :Revision: 4 :Copyright: CC by-sa ================ SVN commit hooks ================ :Description: Thomas moderated a discussion during the PHP-Unconference-Hamburg on SVN commit hooks. It showed that there is interest in my commit message parser, so that I make it available now… Thomas__ moderated a discussion__ during the `PHP-Unconference-Hamburg`__ on SVN commit hooks. It showed that there is interest in my commit message parser, so that I make it available now under New-BSD-license. I created a SVN repository which contains the commit message parser, a lint checker and the basic infrastructure for more commit hooks, with the discussed reporting facilities. The basic idea ============== The basic idea is to ensure that all developers in your team follow certain standards, when contributing code to your project. In some cases some developers continue to write code which does not follow your coding standards, sometimes even accidentally commit code, which does not compile, or do not pay enough attention to their commit messages. One way to keep your developers thinking about this are commit hooks, for example in SVN, which reject commits which do not follow the defined standards, or inform the developer itself, the project manager, or some public list about violations in a recent commit. The checks ========== There are several possible checks, which have been developed and proved valuable in different projects: - Simple lint checking It ensures that the committed files actually compile. This should be a hard criteria for accepting commits, as this might break the checkouts of all other developers and thus decrease the productivity. - Commit message verification For arbit__ I implemented a validator for commit messages, which ensures the commit messages follow a `defined standard`__. This not only ensures the commit messages are parseable later on, but also causes the developers paying more attention to the contents of their commit messages. It showed that such checks can noticeably increase the quality of commit messages in projects. - Code sniffer checks Code sniffer can ensure that your code follows your coding standards, each method is documented, and so on. It is arguable if you want to prevent code from being committed if it does not follow the coding standards, but I think you should at least inform the developer in a post-commit-hook. The implementation ================== After the discussion on the unconf I quickly hacked together the basic infrastructure for such checks, so that it fulfills the following goals: 1) Checks should be pluggable and easily configurable 2) The checks should be possible to configure for pre-commit and post-commit hooks. 3) For proper reporting on post- and pre-commit-hooks it should be possible to configure the reporting accordingly to either send mails, or echo the errors to STDOUT for pre-commit-hooks – with future possible custom reporters, of course. The code is available in the following SVN repository, including tests:: svn://kore-nordmann.de/php-commit-hooks I also configured a mailing list for the discussion and future deveopment of those standards – you can subscribe at pch-subscribe@kore-nordmann.de (the ML itself resides under pch@kore-nordmann.de). Please test the yet available stuff and join a discussion on the mailing list. This is at a very early stage of publishing, but I am sure you can deal with that. :) __ http://www.a-basketful-of-papayas.net/ __ http://www.php-unconference.de/wiki//index.php?title=PhpUnconf2009SundaySessionA4 __ http://www.php-unconference.de/wiki//index.php?title=Hauptseite __ http://arbitracker.org/news.html __ http://tracker.arbitracker.org/arbit/development_wiki/view/CodingGuidelines#commit_messages .. Local Variables: mode: rst fill-column: 79 End: vim: et syn=rst tw=79 Trackbacks ========== Comments ======== - Paul at Wed, 23 Sep 2009 18:49:29 +0200 Hello, This project looks interesting. Can you please contrast it with what can be accomplished using a Continuous Integration server such as Xinc (http://xinc.googlecode.com)? Thanks! Paul - Basilio Vera at Tue, 29 Sep 2009 13:18:50 +0200 Paul, with this hooks you can forbid commits, with a CI server you are able to use the same rules once have been accepted in the repository, and here's a subtle difference... With several developers it's very common to have a lot of code in repository that violates the rules. ;) In our company we are even using Pre-Commit Client hooks (feature providen by TortoiseSVN) to check if the UnitTesting is good enough (min asserts number, code coverage of 70%) to every class you are trying to commit. ;) - ornela @ cheap host at Thu, 22 Jul 2010 16:44:05 +0200 it is very important for larger projects that all developers follow the standards. Interesting project. - Palace 24 at Fri, 27 Aug 2010 11:17:31 +0200 Thanks for sharing this application here. I needed it for my project. The reason i liked it because it is very simple and easy as you told above. I admire you for making very simple and useful application.. - Daniel at Tue, 31 Aug 2010 10:41:12 +0200 Hey Kore, were do I get systemProcess.php from? - Kore at Tue, 31 Aug 2010 12:17:53 +0200 The git repository at http://github.com/kore/php-commit-hooks contains a makefile, which checks out all dependencies, just type `make init` and systemProcess will be automatically fetched. Check the Makefile for the repository URL. - Adam at Mon, 13 Sep 2010 09:03:42 +0200 very interesting.although as you said,its still early stages,i surely can deal with it and needless to say,its gonna be of great help to make sure that all developers maintain standards. - shingles symptoms at Fri, 17 Sep 2010 17:58:45 +0200 Paul, with this hooks you can forbid commits, with a CI server you are able to use the same rules once have been accepted in the repository, and here's a subtle difference. With several developers it's very common to have a lot of code in repository that violates the rules - Lupus symptoms at Fri, 24 Sep 2010 15:46:41 +0200 Thanks for sharing this application here. I needed it for my project. The reason i liked it because it is very simple and easy as you told above. I admire you for making very simple and useful application - resignation letter sample at Mon, 01 Nov 2010 11:34:27 +0100 it is very important for larger projects that all developers follow the standards. Interesting project. - chad weber at Mon, 08 Nov 2010 20:41:17 +0100 It is really a nice post,although as you said,its still early stages,i surely can deal with it and needless to say,its gonna be of great help to make sure that all developers maintain standards. - Sarcoidosis at Fri, 03 Dec 2010 14:06:43 +0100 I am just making a report for my MBA about SVN commit hooks implementation and I was just surfing the internet to find a good reliable source. This is a good method described here and fits my project perfectly. Thanks in advance. - Proxy at Mon, 03 Jan 2011 18:57:04 +0100 I liked the post, the implementation is quite interesting, any updates on this? - Rift Guide at Fri, 04 Mar 2011 22:55:47 +0100 How does fare against something like xinc or any other Continuous Integration server? - telugu songs at Sun, 06 Mar 2011 17:35:41 +0100 When Subversion calls the .bat file it does so with no environmental variables set, you will therefore have to manually set PATH= so that you do not receive "XYZ is not recognised as an internal or external command" errors. - Fatty Liver Cure at Tue, 31 May 2011 11:49:02 +0200 Very interesting - Kudos ! :) For as long as I can remember me and my team had issues with how to prohibit tabs from C++ files. At the end we found our solution in a simple Python hook script. Usually the solutions are right in front of us and we can't see them there on teh surface because we are digging to deep...like damping red wine stains with white wine to eliminate stains (still can't believe that works :))... Anyway, we used a pre-commit hook and then tested it by doing two things: 1. By setting up a throw away temporary repository as a sandbox 2. Finding a way to live test the hook script on teh repository befre it's actually installed Anyway, some interesting idease in your post... - Mohan at Wed, 23 Nov 2011 16:16:35 +0100 Paul, with this hooks you can forbid commits, with a CI server you are able to use the same rules once have been accepted in the repository, and here's a subtle difference... With several developers it's very common to have a lot of code in repository that violates the rules. ;) http://www.staphinfectiononline.com - Gucci pas cher femme at Tue, 29 Nov 2011 07:19:13 +0100 jour surpasser son idole et de gagner son Championnat WWE quatrième femme en moins de trois years.Yet, le recul, qui est vraiment surpris - shagu at Mon, 19 Dec 2011 08:07:25 +0100 here is my script #!/bin/sh REPOS=”$1" TXN=”$2" # Make sure that the log message contains some text. SVNLOOK=/usr/local/bin/svnlook $SVNLOOK log -t “$TXN” “$REPOS” | grep “[A-z a-z]” && exit 0 echo “Please write a log message describing the purpose of your changes and then try c ommitting again.” 1>&2 exit 1 (if i need to make or force commands only for cpp files,what logic i should follow?)