Git - 后接收挂钩不能在远程Windows服务器上工作 [英] Git - post-receive hook not working on remote windows server

查看:167
本文介绍了Git - 后接收挂钩不能在远程Windows服务器上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我使用Git 1.7.9(Msysgit)并在本地有一个回购站和远程服务器上的裸回购。我可以读取,提交,推送等。我已经设置了一个post-receive钩子,它应该将文件检出到一个工作文件夹(部署过程的一部分),但它似乎不起作用。



以下是我的工作:


  1. 更改文件,阶段并提交它

  2. 推送到远程服务器 - 成功

  3. 预计会看到回显 - 看不到回显
  4. 检查服务器上的工作文件夹 - 最新文件不存在

  5. 登录服务器并手动运行挂钩脚本 - 将最新文件签出到工作文件夹中。

我改变了钩子,除了回显信息外,它什么也不做,我已经读过,我应该在推送后在控制台中看到它。但是这并没有被显示出来,所以我只能假设这个钩子没有被触发。



我在处理请求的服务器上用git dot aspx推送HTTP并通过gui在本地进行注入。之后,我尝试了Bonobo,并且在通过gui或bash控制台进行推送时钩子不起作用。



我假设某人在某处有工作,搜索我找到的所有日子都是没有帮助的解决方案,或者有同样问题的人没有回答。

(我是git newbie btw)。

干杯。

更新

我开始认为这可能与权限有关 - 但是Unix权限,而不是NTFS。当@eis提到我使用NTFS的权限时。但经过更多的挖掘,似乎Windows上的Git仍检查Unix文件权限。



所以我怀疑问题是post-receive文件是不可执行的,因为当我做一个 ls -o 它是-rw-r - r--(我相信)。如果我尝试通过bash和 chmod 777 post-receive 来更改它,那么执行 ls -o 的权限是相同的。

奇怪的是,只要我编辑post-receive(用记事本++),执行位就会被删除。 (我以.bat结尾的测试脚本确实保留了它的执行位...)



顺便说一句,我登录的用户是文件的所有者(根据 ls -o ),但我无法设置权限。



开始变得非常困惑现在。我缺少真正明显的东西吗?



更新2
$ b chmod 777 post-receive 也不是 chmod a + x post-receive 工作。我拿了一个新的干净的post-receive文件,将它上传到服务器,并检查了权限并执行了。如果我在Windows中重命名文件(以删除示例),则执行将被删除。如果我在bash中使用 mv execute来保留execute。
但是,无论何时编辑文件(在Windows中或在vi中使用bash),然后执行都会被移除。



所以,现在的问题是为什么它会被删除当我编辑文件时执行位?



希望这是最后的障碍,并且它没有执行的原因...

解决方案

你将不得不修补git来完成这项工作。 builtin / receive-pack.c中的检查用于访问(路径,X_OK)。在msysgit中,这转向了mingw_access,它抛弃了X_OK,因为它在Windows上是不受支持的。



在windows上,我们没有标志来指定文件是可执行文件。系统经常对此进行一些模拟。例如,tcl将在PATHEXT环境变量中查找任何扩展来决定文件是否可执行。我们不能这样做,因为钩子名称是硬编码的,没有任何扩展名。



相反,我建议更改访问测试以检查文件是否存在,然后调用 execv 在路径上。这个(在compat / mingw.c中)的mingw版本查找脚本文件,并将读取shbang行并启动一个合适的解释器(sh,perl等)。因此,修改 builtin / receive-pack.c:run_update_hook 应该让你为你工作。目前钩子运行使用 start_command ,我认为应该调用execv给你。



总之,访问测试,它可能会工作。


I'm trying to get a git post-receive hook working on Windows.

I'm using Git 1.7.9 (Msysgit) and have a repo locally and a bare repo on a remote server. I can fetch, commit, push etc. I've set up a post-receive hook that should checkout the files into a working folder (part of the deployment process) but it doesn't seem to work.

Here's what I do:

  1. Change a file, stage and commit it
  2. Push to remote server - successfully
  3. Expect to see the echo - don't see the echo
  4. Check working folder on server - latest files are not there
  5. Log onto the server and run the hook script manually - latest files are checkout out into the working folder.

I changed the hook so it does nothing except echo a message and I've read that I should see this in my console after pushing. But this is not being displayed so I can only assume the hook is not being fired off.

I'm pushing over HTTP with git dot aspx on the server handling the request and pusing via the gui locally. After that failed I tried Bonobo and the hook doesn't work when pushing via the gui or a bash console.

I'm assuming someone has this working somewhere but after two days of searching all I have found are solutions that don't help or people with the same problem that has gone unanswered.

(I'm a git newbie btw).

Cheers.

Update

I'm starting to think it may be to do with permissions - but Unix permissions, rather than NTFS. When @eis mentioned permissions I had assumed NTFS. But after more digging it seems that Git on Windows still checks for Unix file perms.

So I suspect the issue is that the post-receive file is not executable as when I do a ls -o it's -rw-r--r-- (644 I believe). If I try and change this through bash and chmod 777 post-receive then do ls -o the permissions are the same.

The strange this is that as soon as I edited post-receive (with notepad++) the execute bit gets removed. (my test script that ends in .bat does retain its execute bits though...)

BTW, the user I'm logged on as is the owner of the files (according to ls -o) and yet I can't set the permissions.

Starting to get really confused now. Am I missing something really obvious?

Update 2

Neither chmod 777 post-receive nor chmod a+x post-receive work. I took a new, clean post-receive file, uploaded it the to the server and checked the permissions and it had execute. If I rename the file (to remove sample) in Windows then execute is removed. If I do it in bash with mv execute is retained. But, whenever I edit the file (in Windows or in bash with vi) then execute gets removed.

So, the problem now is why does it remove the execute bits when I edit the file?

Hopefully this is the final hurdle and the cause of it not executing...

解决方案

You are going to have to patch git to make this work. The checks in builtin/receive-pack.c are for access(path, X_OK). In msysgit this diverts to mingw_access which throws away the X_OK bit as it is simple not supported on Windows.

On windows, we have no flag to specify a file is executable. Systems often do some emulation of this. For instance, tcl will look for any extension in the PATHEXT environment variable to decide that a file is executable. We can't do that here as the hook names are hardcoded without any extensions.

Instead, I suggest changing the access test to just check the file exists and then call execv on the path. The mingw version of this (in compat/mingw.c) looks for script files and will read the shbang line and launch an appropriate interpreter (sh, perl etc). So modifying builtin/receive-pack.c:run_update_hook should let this work for you. Currently the hook running uses start_command and I think that should call down to execv for you.

In short, change the access test and it will probably work.

这篇关于Git - 后接收挂钩不能在远程Windows服务器上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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