git post-receive钩子抛出“找不到命令”的错误,但似乎运行正常,手动运行时没有错误

我有一个post-receive钩子,它运行在一个使用gitolite设置的中央git仓库上,以触发临时服务器上的git pull。 它似乎工作正常,但运行时会抛出“命令未find”错误。 我试图追查错误的来源,但没有任何运气。 手动运行相同的命令不会产生错误。

错误将根据正在推送到中央存储库的提交所做的更改而变化。 例如,如果'git rm'被提交并被推送到中央仓库,错误信息将是“remote:hooks / post-receive:line 16:Removed:command not found”,如果'git add'被提交并被推送到中央repo错误消息将是“远程:钩子/ post-receive:行16:合并:命令未find”。 无论哪种情况,即使出现错误消息,登台服务器上运行的“git pull”也能正常工作。

这是post-receive脚本:

#!/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!" 

在登台服务器上执行git的命令是在ssh用户的〜/ .ssh / authorized_keys文件中,并且是:

 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) 

这是从我的本地仓库中删除文件的实际输出,在本地提交,并推送到中央的仓库回购:

 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$ 

正如你所看到的后接收脚本得到echo "Done!" 行,当我看着登台服务器上的git pull已成功运行,但仍然有唠叨的错误消息。

任何build议在哪里寻找错误消息的来源将不胜感激。 我试图将stderrredirect到/ dev / null,但宁愿知道问题是什么。

挂钩可能在没有PATH设置为理智的情况下运行。 你有没有尝试使用ssh的完整path? 否则,在脚本运行时查看环境variables。 你可以使用“导出”来转储它们的列表,他们可能不会是你的想法。