Post-接收钩子不报错但不复制文件

Post-Receive Hook Does Not Error But Does Not Copy Files

我正在尝试使用 git 将更改部署到本地托管服务器上的站点。当我将更改从我的本地目录推送到开发服务器时,post-receive 挂钩提供了我希望它正常工作时的反馈,但它实际上并没有更改工作树中的任何文件。

此外,我正在 mac 上开发,站点托管在网络共享的 windows 服务器上并挂载到 /Volumes/I$

这是钩子脚本

#!/bin/bash

GIT_DIR=/Volumes/I$/intranet_dev
WORK_TREE=/Volumes/I$/intranetdev

while read oldrev newrev ref
do
    if [[ $ref =~ .*/master$ ]];
    then
        echo "Master ref received.  Deploying master branch to test server..."
        mkdir -p $WORK_TREE
        git --work-tree=$WORK_TREE --git-dir=$GIT_DIR checkout -f
        echo "Git hooks deploy complete"
    else
        echo "Ref $ref successfully received.  Doing nothing: only the master branch may be deployed on this server."
    fi
done

裸存储库位于我标记为 "test" 的远程位置。当我发出以下命令时,我在终端中得到以下输出...

computername:intranet username$ git push test master
Counting objects: 6, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 566 bytes | 0 bytes/s, done.
Total 6 (delta 5), reused 0 (delta 0)
remote: Master ref received.  Deploying master branch to test server...
remote: Git hooks deploy complete
To /Volumes/I$/intranet_dev
   1d9eb1f..f49b533  master -> master

这看起来一切正常,但是更改的文件没有被复制过来。

您正在查看当前 HEAD。你确定那是附属于 master 分支的吗?为什么要依赖它?请尝试查看 master

要点,if [[ $ref = */master ]](或者只要我们安全,if [[ $ref = refs/heads/master ]] 正如@torek 指出的那样)就是你所需要的。