我在Windows Server 2008 R2上运行XAMPP服务器。我正在运行Git 64bit版本2.16.1.windows.1
在我从客户端推送之后,我想使用post-receive
挂钩来更新我的网站。
我在服务器上创建了一个裸项目MyProject.git
,并将其克隆到MyProject
。
我的钩子是:
#!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中手动运行脚本,它运行正常。基于我的日志,钩子甚至开火。
Apache上的Git看起来配置正确,因为我可以毫无问题地推送到远程,如果我在MyProject
文件夹中拉取服务器,我从repo获得的文件是正确的。
我缺少什么?
修改
我修好了我的钩子:
#!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被触发.."响应。
EDIT2: 我把我的钩子交给了:
#!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手动执行脚本,则脚本运行正常。但是在我推送客户端之后,脚本仍然没有运行。
EDIT3 粘贴我的虚拟主机配置,我推动:
<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>
答案 0 :(得分:2)
如&#34; git post-receive not working correctly&#34;中所示,您需要取消设置 GIT_DIR
,才能使您的内容正常工作。
cd "C:/xampp/htdocs/webapp/myProject/"
unset GIT_DIR
git pull origin master
exec git-update-server-info