简体   繁体   English

Git-接收后挂钩在远程Windows服务器上不起作用

[英]Git - post-receive hook not working on remote windows server

I'm trying to get a git post-receive hook working on Windows. 我正在尝试让git post-receive挂钩在Windows上正常工作。

I'm using Git 1.7.9 (Msysgit) and have a repo locally and a bare repo on a remote server. 我正在使用Git 1.7.9(Msysgit),在本地有一个存储库,在远程服务器上有一个裸存储库。 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. 我正在处理请求的服务器上使用git dot aspx推送HTTP,并通过gui在本地进行暂停。 After that failed I tried Bonobo and the hook doesn't work when pushing via the gui or a bash console. 失败之后,我尝试了Bonobo,通过gui或bash控制台进行推送时,钩子不起作用。

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). (我是git newbie btw)。

Cheers. 干杯。

Update 更新

I'm starting to think it may be to do with permissions - but Unix permissions, rather than NTFS. 我开始认为这可能与权限有关,但与Unix权限有关,而不是NTFS。 When @eis mentioned permissions I had assumed NTFS. 当@eis提到权限时,我假设使用NTFS。 But after more digging it seems that Git on Windows still checks for Unix file perms. 但是经过更多挖掘之后,Windows上的Git似乎仍在检查Unix文件的烫发情况。

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). 因此,我怀疑问题在于,接收后文件无法像我执行ls -o时那样执行-rw-r--r--(我相信是644)。 If I try and change this through bash and chmod 777 post-receive then do ls -o the permissions are the same. 如果我尝试通过bash和chmod 777 post-receive更改它,则执行ls -o权限是相同的。

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...) (我的测试脚本以.bat结尾,但是确实保留了其执行位...)

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. 顺便说一句,我作为文件所有者(根据ls -o )登录的用户,但是我无法设置权限。

Starting to get really confused now. 现在开始变得非常困惑。 Am I missing something really obvious? 我是否真的缺少明显的东西?

Update 2 更新2

Neither chmod 777 post-receive nor chmod a+x post-receive work. chmod 777 post-receivechmod a+x post-receive chmod 777 post-receive均不工作。 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. 如果我在Windows中重命名该文件(以删除示例),则执行将被删除。 If I do it in bash with mv execute is retained. 如果我用mv在bash中执行,则会保留执行。 But, whenever I edit the file (in Windows or in bash with vi) then execute gets removed. 但是,每当我编辑文件时(在Windows或带有vi的bash中),执行都将被删除。

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. 您将必须修补git才能使它工作。 The checks in builtin/receive-pack.c are for access(path, X_OK) . Builtin / receive-pack.c中的检查用于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. 在msysgit中,这转移到mingw_access,它丢弃X_OK位,因为Windows上不支持它,这很简单。

On windows, we have no flag to specify a file is executable. 在Windows上,我们没有标志来指定文件是可执行文件。 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. 例如,tcl将在PATHEXT环境变量中寻找任何扩展名,以决定文件是可执行的。 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. 相反,我建议更改访问测试以仅检查文件是否存在,然后在路径上调用execv 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). 此版本的mingw版本(在compat / mingw.c中)查找脚本文件,并将读取shbang行并启动适当的解释器(sh,perl等)。 So modifying builtin/receive-pack.c:run_update_hook should let this work for you. 因此,修改builtin/receive-pack.c:run_update_hook应该可以帮助您解决这个问题。 Currently the hook running uses start_command and I think that should call down to execv for you. 目前,钩子运行使用start_command ,我认为应该为您调用execv。

In short, change the access test and it will probably work. 简而言之,更改访问测试,它可能会起作用。

When using msysgit on the server and pushing via a file share hooks work without problem now. 在服务器上使用msysgit并通过文件共享推送时,钩子现在可以正常工作了。 Maybe this was fixed in mysysgit since the answer was written. 自编写答案以来,也许这已在mysysgit中修复。 I didn't look into it. 我没有调查。

I also noticed that the original question stated git dot aspx and Bonobo were being used which use GitSharp.dll. 我还注意到最初的问题是使用GitSharp.dll的git dot aspx和Bonobo正在使用。 This would mean the application is not shelling out to the git.exe and hooks would not be handled the same way. 这将意味着应用程序不会使用git.exe,并且将无法以相同的方式处理钩子。

For example, the GitSharp.dll used in git dot aspx has it's own hook post-receive hook implementation which could be performed in C#: 例如,在git dot aspx中使用的GitSharp.dll具有它自己的钩子接收后钩子实现,可以在C#中执行:

public void Receive(Stream inputStream, Stream outputStream) 
{
    using (var repository = GetRepository()) 
    {
        var pack = new ReceivePack(repository);
        pack.setBiDirectionalPipe(false);

        //setup post receive hook here
        pack.setPostReceiveHook(new PostRecieveHook());

        pack.receive(inputStream, outputStream, outputStream);
     }
}


public class PostRecieveHook : IPostReceiveHook 
{
    public void OnPostReceive(ReceivePack rp, ICollection<ReceiveCommand> commands) 
    {
        //Do PostRecieve Hook Work Here
    }
}

I hope to help others with confusion between libraries that are implementations of Git and applications that call out to the actual git.exe. 我希望能帮助其他人避免混淆作为Git的实现的库和调用实际git.exe的应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM