title: git pre-receive hook - getting the newest code
body: <p>I am trying to write a <code>pre-receive hook</code> for git that will pull the latest version of the code being pushed and run unit tests against it.  My code is below, but when it gets to "git checkout $newrev", I get:</p>
  
  <blockquote>
    <p>remote: fatal: reference is not a tree: 188de39ca68e238bcd7ee9842a79397f39a5849e</p>
  </blockquote>
  
  <p>What do I need to do to get a checkout of the code being pushed before the receive has happened?</p>
  
  <pre><code>#!/bin/bash
  while read oldrev newrev refname
  do
    echo "Preparing to run unit tests for $newrev"
    TEST_DIR=/opt/git/sommersault-push-tests/sommersault
  
    # check out this version of the code
    unset GIT_DIR
    echo $refname
    cd $TEST_DIR
    git checkout $newrev
  
    ...do more stuff...
  done
  </code></pre>