I have a post-receive hook that runs on a central
git repository set up with gitolite
to trigger a
git pull on a staging server. It seems
to work properly, but throws a "command not found" error when it is run. I am trying
to track down the source of the error, but have not had any luck. Running the same commands manually does not produce an error.
The error changes depending on what was done in the commit that is being pushed
to the central repository. For instance, if '
git rm ' was committed and pushed
to the central repo the error message will be "remote: hooks/post-receive: line 16: Removed: command not found" and if '
git add ' was committed and pushed
to the central repo the error message will be "remote: hooks/post-receive: line 16: Merge: command not found". In either case the '
git pull' run on the staging server works correctly despite the error message.
Here is the post-receive script:
#!/bin/bash
#
# This script is triggered by a push
to the local
git repository. It will
# ssh into a remote server and perform a
git pull.
#
# The SSH_USER must be able
to log into the remote server with a
# passphrase-less SSH key *AND* be able
to do a
git pull without a passphrase.
#
# The command
to actually perform the pull request on the remost server comes
# from the ~/.ssh/authorized_keys file on the REMOTE_HOST and is triggered
# by the ssh login.
SSH_USER="remoteuser"
REMOTE_HOST="staging.server.com"
`ssh $SSH_USER@$REMOTE_HOST` # This is line 16
echo "Done!"
The command that does the
git pull on the staging server is in the ssh user's ~/.ssh/authorized_keys file and is:
command="cd /var/www/staging_site;
git pull",no-port-forwarding,no-X11-forwarding,no-agent-forwarding, ssh-rsa AAAAB3NzaC1yc2EAAAABIwAA... (the rest of the public key)
This is the actual output from removing a file from my local repo, committing it locally, and pushing it
to the central
git repo:
ben@tamarack:~/thejibe/testing/web$
git rm ./testing
rm 'testing'
ben@tamarack:~/thejibe/testing/web$
git commit -a -m "Remove testing file"
[master bb96e13] Remove testing file
1 files changed, 0 insertions(+), 5 deletions(-)
delete mode 100644 testing
ben@tamarack:~/thejibe/testing/web$
git push
Counting objects: 3, done.
Delta compression using up
to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 221 bytes, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: From
[email protected]:testing
remote: aa72ad9..bb96e13 master -> origin/master
remote: hooks/post-receive: line 16: Removed: command not found # The error msg
remote: Done!
To [email protected]:testing
aa72ad9..bb96e13 master -> master
ben@tamarack:~/thejibe/testing/web$
As you can see the post-receive script gets
to the echo "Done!" line and when I look on the staging server the
git pull has been successfully run, but there's still that nagging error message.
Any suggestions on where
to look for the source of the error message would be greatly appreciated. I'm tempted
to redirect stderr
to /dev/null but would prefer
to know what the problem is.