windows - Git - 接收后未在 Windows 上运行

标签 windows git apache

我在我的 Windows Server 2008 R2 上运行 XAMPP 服务器。我正在运行 Git 64 位版本 2.16.1.windows.1 我想在从客户端推送后使用 post-receive Hook 更新我的网站。

我在服务器上创建了一个裸项目 MyProject.git 并将其克隆到 MyProject

我的钩子(Hook)是:

#!C:/Program\ Files/Git/usr/bin/sh.exe 
echo "Hook got triggered.." > hooks.txt
exec powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\hooks\post-receive.ps1"

Powershell 脚本是:

cd "C:/xampp/htdocs/webapp/myProject/"
git pull origin master
exec git-update-server-info

我搜索了类似的问题,但没有找到问题的解决方案。

如果我在 powershell 中手动运行脚本,它运行正常。根据我的日志, Hook 甚至会触发。

Apache 上的 Git 看起来配置正确,因为我可以毫无问题地推送到远程,如果我在 MyProject 文件夹中 pull 服务器,我从 repo 获得的文件是正确的.

我错过了什么?

编辑:

我将钩子(Hook)固定到:

#!C:/Program\ Files/Git/usr/bin/sh.exe
echo "Hook got triggered.."
exec powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\hooks\post-receive.ps1"

还有我的 powershell 脚本:

cd "C:/xampp/htdocs/webapp/myProject/"
unset GIT_DIR
git pull origin master
exec git-update-server-info

当我推送到远程时的响应是:

Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 296 bytes | 296.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
To http://git.mysite.com/myProject.git
  999aeb1..cf0df6f  master -> master

没有“Hook got triggered..”响应。

编辑 2: 我将钩子(Hook)更改为:

#!C:/Program\ Files/Git/usr/bin/sh.exe
echo "Hook got triggered.."
cd "C:/xampp/htdocs/webapp/drajv-tecaj/"
unset GIT_DIR
git pull origin master

如果使用 bash 手动执行脚本,脚本将正确运行。但是在我对客户端进行推送后脚本仍然没有运行。

编辑3 粘贴我要推送到的虚拟主机的配置:

<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/webapp"
    ServerName git.mysite.com
    <Directory "C:/xampp/htdocs/webapp">
        Options +ExecCGI +Indexes +FollowSymLinks
        Require all granted
    </Directory>
    <Directory "C:/Program Files/Git/mingw64/libexec/git-core/">
        Require all granted 
    </Directory>
    SetEnv GIT_PROJECT_ROOT C:/xampp/htdocs/webapp
    SetEnv GIT_HTTP_EXPORT_ALL
    ScriptAlias /git "C:/Program Files/Git/mingw64/libexec/git-core/git-http-backend.exe/"
    ScriptAliasMatch \
        "(?x)^/(.*/(HEAD | \
                    info/refs | \
                    objects/(info/[Apache Git server on Windows^/]+ | \
                             [0-9a-f]{2}/[0-9a-f]{38} | \
                             pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
                    git-(upload|receive)-pack))$" \
                    "C:/Program Files/Git/mingw64/libexec/git-core/git-http-backend.exe/$1"
</VirtualHost>

最佳答案

如“git post-receive not working correctly ”中所示,您需要取消设置 GIT_DIR 让您的 pull 在钩子(Hook)内正常工作。

cd "C:/xampp/htdocs/webapp/myProject/"
unset GIT_DIR
git pull origin master
exec git-update-server-info

关于windows - Git - 接收后未在 Windows 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48519719/

相关文章:

c++ - 从 dll 函数调用中正确获取 Windows 版本?

git - 检查git分支是否已 merge 到其他分支而不运行 `git merge`

regex - 使用基于查询字符串参数的 HTTP 身份验证保护 url

Apache a2enmod ssl 不会启用

java - 如何检索文件服务器中存储的图像?

c - 我想要更大的 pixbuf 渲染到 GtkSource Gutter

windows - 列出机器上安装的操作系统

linux - "Modern"带有 GLFW 的 Linux 上的 OpenGL

php - 支持 Git 的 Mac OS X PHP IDE

GitHub "fatal: remote origin already exists"