接收后:没有该文件或目录

接收后:没有该文件或目录

尝试推送到远程 Amazon EC2(Ubuntu Linux)实例时出现错误。我已授予所有相关目录和文件完全权限。我尝试使用 post-receive 钩子将项目移动到我的生产目录/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

我的接收后文件(位于裸存储库:)/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

看起来问题在于脚本没有放在正确的位置。本地存储库和服务器上post-receive的输出是什么?git remote -vls -l /home/ubuntu/myapp/myapp.git/hooks

关于脚本本身的一些提示:

  • 使用更多引号™
  • Bash(和 POSIX shell)使用单个等号表示[
  • -o已弃用;你应该使用[ foo = bar ] || [ baz = ban ]
  • 用于set -o errexit在第一次出现错误时退出脚本;它应该使调试变得更容易
  • 使用set -o xtraceexec > /tmp/post-receive.log 2>&1(临时)获取脚本所执行操作的调试日志。

相关内容