Monthly Archives: October 2010

Example Git pre-receive and post-receive Hooks to Avoid a Signal 13 Error

Git has a very nice set of example hooks that you can find just by creating a new repo. The following is an easy way to see them all:

mkdir myrepo
cd myrepo
git init
ls .git/hooks/

If you do that you will end up with a list something like this:

applypatch-msg.sample  post-commit.sample   post-update.sample     pre-commit.sample          pre-rebase.sample
commit-msg.sample      post-receive.sample  pre-applypatch.sample  prepare-commit-msg.sample  update.sample

I recently did this thinking I would create a pre-receive hook. Since there isn't a sample for pre-receive I went to the git hooks reference to see if there was anything special I needed to know. I didn't pay any attention to the fact that git will send something in on STDIN when it runs the hook and as it turns out that is important. In some instances if you don't read STDIN you will get an error message like the following when you try to push and the hook gets used:

fatal: The remote end hung up unexpectedly
error: error in sideband demultiplexer
error:  died of signal 13

The fix for this is to make sure you read STDIN when creating pre-receive and post-receive hooks. The following example shell script will show the commit information for each new revision id when you push and the hook is executed:

while read oldrev newrev refname
  # Do something with $oldrev $newrev $refname 
  git show --no-color --root -s --pretty=medium $newrev

The key part in the above is the "while read" that reads STDIN. So whatever language you write your hook in just make sure you read everything from STDIN before completing the script.

Getting Started with JRuby Webapps using Rack and Sinatra

Going to JRubyConf inspired me enough to expand my knowledge of JRuby. This is a quick guide for anyone looking to see what can be done with JRuby and Sinatra.

Of course the first step is to install the Java JDK. Download, install and then set it up in your path. I'm using JDK 6 update 21 on Linux for this post in case it matters.

There are a couple ways to install JRuby after you have Java installed. The hard way is to download JRuby and install it by hand. The easy way is to use Ruby Version Manager to install it. Using RVM will let you switch between Ruby versions as well as giving you a simple command to install JRuby:

rvm install jruby
rvm use jruby

Continue reading