1

我在 Windows 2008 R2 Server 机器上安装了 Bonobo Git Server。我创建了一个存储库并将post-receive.bat文件放在D:\Inetpub\Bonobo.Git.Server\App_Data\Repositories\REPO\hooks目录中。

这是文件的内容:

#!/D/Inetpub/Bonobo.Git.Server/App_Data/Git/sh.exe

BINPATH="/D/Inetpub/Bonobo.Git.Server/App_Data/Git/"
REPOPATH="/D/Inetpub/Bonobo.Git.Server/App_Data/Repositories/REPO/"
GIT="${BINPATH}git"

# Change working directory to the repo root
cd $REPOPATH

read oldrev
read newrev
read refname

branch=$($GIT rev-parse --symbolic --abbrev-ref $refname)

if [ "master" == "$branch" ]; then
    echo "receive $branch $refname" >> "${REPOPATH}hookstest.log"
fi

如果我从 shell 执行这个文件并输入“whatever any master”,那么文件“receive master master”将添加到hookstest.log. 但是,当我将更改推送到 REPO 时,文件不会更新,就像它没有被执行一样。

我不知道在哪里寻找发生的错误。大多数 linux 教程都提到该文件必须具有 +x 标志。这显然在 Windows 上不存在,但我检查了在 IIS 中运行 Bonobo Git Server 的用户对批处理文件具有执行权限。

我也在犹豫文件的名称,所以我复制了它并删除了 .bat 扩展名。那也没有帮助。知道如何让钩子在 Windows Server 上工作吗?

编辑

正如@crashmstr 所建议的,我创建了一个批处理文件(一个带扩展名,一个不带扩展名),其中包含:

date /t >> D:\Inetpub\Bonobo.Git.Server\App_Data\Repositories\REPO\testhooks.txt

当我手动执行文件时,即使创建了文件,这也不起作用。

4

2 回答 2

2

使用最新版本的 Bonobo(比 6.1 稍晚,但该区域没有任何变化),我刚刚在 repo 的 hooks 目录中创建了一个名为“pre-receive”的文件。

该文件的文件名没有扩展名,仅包含以下内容:

#!/bin/sh
echo "xx" > here.txt

当我向这个 repo 提交提交时,文件“here.txt”被写入 repo 文件夹的顶部。

如果这不起作用,那么我会从 SysInternals 运行 ProcMon,并将路径过滤器设置为包含“here.txt”(可能还有“pre-receive”)并检查为什么没有写入/读取这些文件。

观看使用 ProcMon 编写的“here.txt”表明它是由 .sh.exe 的副本编写的\App_Data\Git\sh.exe。我不太确定从 '#!/bin/sh' 得到的是谁和什么,\App_Data\Git\sh.exe但它似乎有效。

于 2017-05-06T09:21:44.680 回答
2

我不确定是什么问题。最后,我通过创建D:\Inetpub\Bonobo.Git.Server\App_Data\Repositories\REPO\hooks\post-receive具有以下内容的文件(无扩展名)使其工作:

#!/D/Inetpub/Bonobo.Git.Server/App_Data/Git/sh.exe

echo "BEGIN post-receive script"

APPPATH="/D/Inetpub/Bonobo.Git.Server/App_Data"
SVN="/D/csvn/bin/svn"

REPOPATH="$APPPATH/Repositories/REPO"
SVNSYNCPATH="$APPPATH/SVN-sync"
GIT="$APPPATH/Git/git"

mapping["master"]="trunk"
mapping["develop"]="development"

# Change working directory to the repo root
cd $REPOPATH

read oldrev newrev refname    

echo "oldrev - $oldrev"
echo "newrev - $newrev"
echo "refname - $refname"

branch=$($GIT rev-parse --symbolic --abbrev-ref $refname)
echo "branch - $branch"
echo ""

if [ "master" == "$branch" ]; then
    result=($($GIT diff $oldrev $newrev --name-status))
    echo "Detected $((${#result[@]}/2)) changes:"

    idx=0
    while [ $idx -lt ${#result[@]} ]
    do      
        status=${result[$idx]}
        filename=${result[$(($idx+1))]}
        echo -n "$status - $filename "

        case $status in
            "A")
                echo "added"
                ;;
            "M")
                echo "updated"
                ;;
            "D")
                echo "deleted"
                ;;
            "R")
                echo "renamed"
                ;;
            "C")
                echo "copied"
                ;;
            *)
                echo "unknown status"
                ;;
        esac

        idx=$(($idx+2))
    done
fi
echo ""

echo "END post-receive script"
于 2017-05-09T12:57:01.463 回答