title: post-receive hook permission denied "unable to create file" error
body: <p>Just got <code>gitolite</code> installed on my webserver and am trying to get a <code>post-receive</code> hook that can point the <code>git dir</code> in apache's direction.</p>
  
  <p>This is what my <code>post-receive</code> hook looks like. Got this script from the <a href="http://toroid.org/ams/git-website-howto" rel="nofollow">Using Git to manage a web site</a>.</p>
  
  <pre><code>#!/bin/sh
  echo "post-receive example.com triggered"
  GIT_WORK_TREE=/srv/sites/example.com/public git checkout -f
  </code></pre>
  
  <p>I've also tried:</p>
  
  <pre><code>#!/bin/sh
  echo "post-receive example.com triggered"
  unset GIT_INDEX_FILE
  export GIT_WORK_TREE=/srv/sites/example.com/public
  export GIT_DIR=/home/git/repositories/example.com.git
  git checkout -f
  </code></pre>
  
  <p>This is the error response i'm getting back from <code>git push origin master</code> from my local workstation. These are files from within my repository.</p>
  
  <pre><code>remote: post-receive example.com triggered
  remote: error: unable to create file .htaccess (Permission denied)
  remote: error: unable to create file .tm_sync.config (Permission denied)
  remote: fatal: cannot create directory at 'application': Permission denied
  </code></pre>
  
  <p>Standalone script error</p>
  
  <pre><code>remote: sudo: no tty present and no askpass program specified
  remote: Sorry, try again.
  remote: sudo: no tty present and no askpass program specified
  remote: Sorry, try again.
  remote: sudo: no tty present and no askpass program specified
  remote: Sorry, try again.
  remote: sudo: 3 incorrect password attempts
  </code></pre>
  
  <p>Update:</p>
  
  <pre><code>git@vannevar:~$ sudo -l
  Matching Defaults entries for git on this host:
      env_reset, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin
  
  User git may run the following commands on this host:
      (root) NOPASSWD: /usr/local/sbin/prgetsimpleappscom
  git@vannevar:~$ /usr/local/sbin/prgetsimpleappscom
  -su: /usr/local/sbin/prgetsimpleappscom: Permission denied
  git@vannevar:~$ sh /usr/local/sbin/prgetsimpleappscom
  post-receive getsimpleapps.com triggered
  error: unable to unlink old 'application/config/development/database.php' (Permission denied)
  error: unable to unlink old 'application/config/production/database.php' (Permission denied)
  error: unable to unlink old 'application/config/quickbooks.php' (Permission denied)
  git@vannevar:~$ sudo sh /usr/local/sbin/prgetsimpleappscom
  [sudo] password for git: 
  Sorry, user git is not allowed to execute '/bin/sh /usr/local/sbin/prgetsimpleappscom' as root on vannevar.
  git@vannevar:~$ sudo /usr/local/sbin/prgetsimpleappscom
  [sudo] password for git: 
  sudo: /usr/local/sbin/prgetsimpleappscom: command not found
  git@vannevar:~$ nano /usr/local/sbin/prgetsimpleappscom
  git@vannevar:~$ 
  </code></pre>