<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Grep My Mind &#187; svn commit hooks</title>
	<atom:link href="http://www.grepmymind.com/tags/svn-commit-hooks/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.grepmymind.com</link>
	<description>Wonder what’s on my mind? Now you know.</description>
	<lastBuildDate>Thu, 11 Jun 2009 20:00:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>svn pre-commit &amp; post-commit hooks</title>
		<link>http://www.grepmymind.com/2009/03/07/svn-pre-commit-post-commit-hooks/</link>
		<comments>http://www.grepmymind.com/2009/03/07/svn-pre-commit-post-commit-hooks/#comments</comments>
		<pubDate>Sat, 07 Mar 2009 16:47:55 +0000</pubDate>
		<dc:creator>Michael Tougeron</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[post-commit]]></category>
		<category><![CDATA[pre-commit]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[svn commit hooks]]></category>
		<category><![CDATA[svn hooks]]></category>

		<guid isPermaLink="false">http://www.grepmymind.com/?p=311</guid>
		<description><![CDATA[I have to say I love subversion (svn) hooks.  I&#8217;ve only been playing around with the concept fairly recently and I&#8217;m surprised that I lasted this long without them.  I wanted to take a few minutes and share my favorite ways of using them.  As well as a few that I don&#8217;t use but I [...]]]></description>
			<content:encoded><![CDATA[<p>I have to say I love <a href="http://subversion.tigris.org/">subversion</a> (svn) hooks.  I&#8217;ve only been playing around with the concept fairly recently and I&#8217;m surprised that I lasted this long without them.  I wanted to take a few minutes and share my favorite ways of using them.  As well as a few that I don&#8217;t use but I think could be pretty helpful.</p>
<p>Before we keep going, if you don&#8217;t know what svn hooks are you can read up on them at <a href="http://svnbook.red-bean.com/en/1.1/ch05s02.html">http://svnbook.red-bean.com/en/1.1/ch05s02.html</a>.  svnbook.red-bean.com is my reference site of choice whenever I need to look up a svn command.</p>
<p>My #1, all-time, greatest in the world, bestest favorite is a svn pre-commit hook to syntax check my <a href="http://php.net">PHP</a> code.  There is nothing I hate more than a developer checking in code with syntax errors and breaking qa or stage or even, god-forbid, production.  It&#8217;s as easy as setting up the hook to run a script that calls &#8220;/path/to/php -l /path/to/file.php&#8221; and on failure reject the commit.  This way code that has syntax errors will never make it into SVN.  Now if only open-source projects like <a href="http://framework.zend.com/">ZendFramework</a> did something like this before releasing their code.  To be fair, the syntax errors are in their documentation not in the /library/ files but that&#8217;s still pretty dumb &amp; annoying.</p>
<p>Another nice way to use a post-commit hook is to run something like <a href="http://pear.php.net/package/PHP_CodeSniffer">PHP_CodeSniffer</a> against the commit.  CodeSniffer is an awesome <a href="http://pear.php.net">PEAR </a>package that scans your file and flags coding standards violations.  It comes pre-packaged with sniffers for the PHPCS, <a href="http://pear.php.net/manual/en/standards.php">PEAR</a>, <a href="http://squiz.net">Squiz</a> and  <a href="http://framework.zend.com/manual/en/coding-standard.html">Zend</a>.  Set it up to run and if it finds coding standard violations you can have the hook send out nasty little blame messages.  <img src='http://www.grepmymind.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />   This isn&#8217;t something that I&#8217;d want to run on pre-commit just in case you really need to get something into production NOW.  But if I hosted an open source project, <a href="http://pear.php.net/manual/en/package.php.php-codesniffer.svn-pre-commit.php">I&#8217;d consider it</a>.</p>
<p>Having minified JavaScript &amp; CSS has become the standard way of serving JS &amp; CSS.  But who really wants to take the time to minify or combine them?  Once again, enter svn hooks.  One of the developers set this up for <a href="http://www.gamespot.com/">GameSpot</a> and it has been working great!  Basically it checks the commits against a defined naming standard, file.src.js or file.src.css, and then runs the <a href="http://developer.yahoo.com/yui/compressor/">YUI! Compressor</a> on it and commits in file.min.(js|css).  He also made it check a global.conf in the file&#8217;s directory so it came mash up smaller js files into a global.min.js so we serve one file instead of ten.</p>
<p>Of course, let&#8217;s not forget about what is probably the most common svn hook; the post-commit email hook.  I like <a href="http://opensource.perlig.de/svnmailer/">svnmailer</a> better than <a href="http://subversion.tigris.org/tools_contrib.html#mailer_py">mailer.py</a> that comes with svn by default.  I think it&#8217;s easier to configure/change and to setup rules for how you want the emails to look or where to go.</p>
<p>If you&#8217;re using a ticket tracking system like <a href="http://www.bugzilla.org/">Bugzilla</a> or <a href="http://trac.edgewall.org/">Trac</a> that doesn&#8217;t have its own way of peeking into svn (like <a href="http://www.atlassian.com/software/jira/">JIRA</a> can with this <a href="http://confluence.atlassian.com/display/JIRAEXT/JIRA+Subversion+plugin">plugin</a>) you can write a post-commit hook to update the ticket when something is committed.  You can see how Trac recommends you do it at <a href="http://trac.edgewall.org/browser/trunk/contrib/trac-post-commit-hook">http://trac.edgewall.org/browser/trunk/contrib/trac-post-commit-hook</a>.</p>
<p>To help you on the way to creating your own svn hooks, tigris has a few <a href="http://subversion.tigris.org/tools_contrib.html#hook_scripts">hooks that are distributed</a> with svn.  They can be quite helpful so you should take a look at them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.grepmymind.com/2009/03/07/svn-pre-commit-post-commit-hooks/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
