<?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>World Wide Mike &#187; buildbot</title>
	<atom:link href="http://mmm.beachtemple.com/blog/tag/buildbot/feed/" rel="self" type="application/rss+xml" />
	<link>http://mmm.beachtemple.com/blog</link>
	<description>Notes from the Journey that is Life</description>
	<lastBuildDate>Sun, 12 Apr 2009 12:16:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>git post-receive Hook</title>
		<link>http://mmm.beachtemple.com/blog/2009/04/06/git-post-receive-hook/</link>
		<comments>http://mmm.beachtemple.com/blog/2009/04/06/git-post-receive-hook/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 00:16:09 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[Geek]]></category>
		<category><![CDATA[buildbot]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://mmm.beachtemple.com/blog/?p=188</guid>
		<description><![CDATA[Notes on setting up automated tasks when commits are pushed to a central git repository.]]></description>
			<content:encoded><![CDATA[<p>At my job we use <a href="http://git-scm.com/">git</a> for version control, and I wanted to do a few things whenever we pushed changes to the main tree. It took me a little bit of effort to figure out how it works, and below are my notes.</p>
<p>The <code>post-receive</code> hook is called when the repository receives changes. Let&#8217;s assume I have a git repository on my development machine that is a clone of a public git repository on a server. Then, when I run <code>git push</code> in my local repository in order to push my commits to the public repository, the <code>post-receive</code> hook is called on the public repository on the server.</p>
<h3>Email Notification</h3>
<p>On Debian-based systems there is an example email notification post-receive hook in <code>/usr/share/doc/git-core/contrib/hooks/post-receive-email</code>. It&#8217;s also available online from the <a href="http://github.com/git/git/tree/master">git repo on github</a> in the <code>contrib/hooks</code> directory.</p>
<p>In the repository that will be receiving commits (the public repository on the server, in the example above), first we need to make the <code>post-receive</code> hook executable:</p>
<pre>
$ cd /path/to/git/repo/.git/hooks
$ chmod +x post-receive
</pre>
<p>Then we need to call the <code>post-receive-email</code> script from inside this <code>post-receive</code> hook. Open <code>.git/hooks/post-receive</code> with your favorite editor and make sure this line exists:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">. <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>post-receive-email</pre></div></div>

<p>Notice we&#8217;re not executing the <code>post-receive-email</code> script, we&#8217;re sourcing it.</p>
<p>Next, we need to tell git where to send the email to. The <code>hooks.mailinglist</code> property controls this:</p>
<pre>
$ cd /path/to/git/repo
$ git config hooks.mailinglist "mailinglist@example.com"
</pre>
<p>At this stage emails will be sent each time changes are pushed to the public git repository containing a summary of the new changes.</p>
<p>By default, emails refer to the project as &#8220;UNNAMED PROJECT&#8221;. To change this, edit <code>.git/description</code>.</p>
<p>For further customization options, look inside <code>post-receive-email</code>. For example:</p>
<pre>
$ cd /path/to/git/repo
# envelopesender? see `man sendmail` for the -f switch
$ git config hooks.envelopesender "git@example.com"
$ git config hooks.emailprefix "[MY PREFIX] "  # note the trailing space
</pre>
<h3>Kicking Off a Buildbot Build</h3>
<p>You may also want to have Buildbot start a build from the <code>post-receive</code> hook. Like the email script, the <a href="http://buildbot.net/trac/browser/contrib/git_buildbot.py">Buildbot git script</a> expects revision hashes on standard input. The <code>post-receive</code> script then needs to be modified a little to pass the hashes it receives via standard input to all the scripts it invokes. Here&#8217;s a new copy of <code>post-receive</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> oldrev newrev refname
<span style="color: #000000; font-weight: bold;">do</span>
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$oldrev</span> <span style="color: #007800;">$newrev</span> <span style="color: #007800;">$refname</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">sh</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>post-receive-email
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$oldrev</span> <span style="color: #007800;">$newrev</span> <span style="color: #007800;">$refname</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>python <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>git_buildbot.py
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>This script first reads <code>oldrev</code>, <code>newrev</code>, and <code>refname</code> from standard input, then pipes those values into <code>post-receive-email</code> and <code>git_buildbot.py</code>. We loop until there is no more input, presumably because another push may happen while we&#8217;re executing.</p>
]]></content:encoded>
			<wfw:commentRss>http://mmm.beachtemple.com/blog/2009/04/06/git-post-receive-hook/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
