2

I'm getting an error when trying to push to a remote Amazon EC2 (Ubuntu Linux) instance. I've given all related directories and files full permissions. I'm trying to use a post-receive hook to move the project to my production directory at /var/www/myapp:

$ git push prod-server master

Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 292 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: error: cannot run hooks/post-receive: No such file or directory
To prod-server:/home/ubuntu/myapp/myapp.git
   8944048..a445d1d  master -> master

My post-receive file (located in bare repository: /home/ubuntu/myapp/myapp.git/hooks/):

#!/bin/bash
while read oldrev newrev ref
do
  branch=`echo $ref | cut -d/ -f3`
  if [ "prod-server" == "$branch" -o "master" == "$branch" ]; then
    git --work-tree=/var/www/myapp/ checkout -f $branch
    echo 'Changes pushed to Amazon EC2 PROD-SERVER directory!'
  fi
  if [ "test" == "$branch" ]; then
    git --work-tree=/var/www/myapp/test/ checkout -f $branch
    echo 'Changes pushed to Amazon EC2 PROD-SERVER test directory!'
  fi
done

1 Answer 1

0

It looks like the problem is with the post-receive script not being in the right place. What is the output of git remote -v in the local repository and ls -l /home/ubuntu/myapp/myapp.git/hooks on the server?

Some tips for the script itself:

  • Use More Quotes™
  • Bash (and POSIX shells) use a single equals sign for [
  • -o is deprecated; you should instead use [ foo = bar ] || [ baz = ban ]
  • Use set -o errexit to exit the script at the first error; it should make debugging much easier
  • Use set -o xtrace and exec > /tmp/post-receive.log 2>&1 to (temporarily) get a debug log of what the script does.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .