Git-接收后未在Windows上运行 [英] Git - post-receive not running on windows

查看:100
本文介绍了Git-接收后未在Windows上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am running XAMPP server on my Windows Server 2008 R2. I am running Git 64bit version 2.16.1.windows.1 I would like to use post-receive hook to update my website after i do pa push from my client.

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

I created a bare project MyProject.git on server and cloned it to 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脚本是:

Powershell script is:

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

我搜索类似的问题没有任何运气来解决问题.

I searched similar questions without any luck for solution of to problem.

如果我在Powershell中手动运行脚本,则运行正常.根据我的日志,钩子实例甚至触发了.

If i run the script manually in powershell it runs ok. Based on my log the hook inst even firing.

Apache上的Git看起来配置正确,因为我可以毫无问题地推送到远程,并且如果我在MyProject文件夹中的服务器上进行拉动,则从回购中获取的文件是正确的.

The Git on Apache looks like it's configured correctly, because i can push to remote without problems and if i do a pull on the server in MyProject folder, the files that i get from repo are correct.

我想念什么?

我将钩子固定在:

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

我的powershell脚本执行以下操作:

And my powershell script to:

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

当我按下遥控器时的响应是:

Response when i push to remote is:

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

没有挂钩被触发.."响应.

There is no "Hook got triggered.." response.

我已将钩子更改为:

I chaneged my hook to:

#!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手动执行脚本,脚本将正确运行.但是,在我执行客户端操作后,脚本仍未运行.

The script runs correctly if executed manually usin bash. But the script is still not running after i do a push on client.

EDIT3 粘贴我要推送到的虚拟主机的配置,

EDIT3 Pasting my config for virtual host, that I'm pushing to:

<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不能正常工作",则需要取消设置 GIT_DIR ,以确保钩子内的拉力正常工作.

As seen in "git post-receive not working correctly", you would need to unset GIT_DIR for your pull to work correctly from within a hook.

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

这篇关于Git-接收后未在Windows上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆