服务器上的Git post-receive hook错误

时间:2012-09-13 16:30:35

标签: git githooks

我正在尝试在我的服务器上使用git'post-receive'。我在钩子文件上使用以下代码:

#!/bin/bash
#CONFIG
LIVE="/home/ubuntu/public_html/testing"

read oldrev newrev refname
if [ $refname = "refs/heads/master" ]; then
  echo "===== DEPLOYING TO LIVE SITE ====="
  unset GIT_DIR  
  cd $LIVE
 # ssh-agent $BASH
 # ssh-add /home/ubuntu/.ssh/ubuntu
  git pull --verbose origin  master || echo "git-pull: returned error code"     
  echo "===== DONE ====="
fi

每当我尝试将某些内容从本地PC推送到服务器时,它会显示以下错误信息:

===== DEPLOYING TO LIVE SITE =====
remote: error: cannot open .git/FETCH_HEAD: Permission denied
remote: 
remote: git-pull: returned error code
remote: ===== DONE =====

任何人都可以帮助解决可能出现的问题吗?

为了确认,我尝试使用相同的用户凭据通过ssh终端运行命令,它运行正常。

提前致谢。

2 个答案:

答案 0 :(得分:2)

最后,我确实能够通过将目录(/ home / ubuntu / public_html / testing)的所有权更改为提交/运行挂钩的用户来解决它。

答案 1 :(得分:0)

每当我收到有关权限和FETCH_HEAD的错误消息时,都是因为我不小心做了一个root用户同时修补了一些内容,这会在root拥有的.git目录中创建文件,我的普通ssh用户可以不要覆盖。

我经常运行ls -laR .git | grep root(我确定有更好的方法,我不是系统管理员)来检查root是否拥有任何文件。简单地将它们拉回来可以让我继续照常进行。

相关问题