Git - post-receive hook does not work on a remote Windows server

I am trying to get a git post-receive hook running on windows.

I am using git 1.7.9 (Msysgit) and have a repo locally and a bare repo on a remote server. I can receive, commit, click, etc. I set the hook after the reception, which should check the files in the working folder (part of the deployment process), but it does not work.

That's what I'm doing:

  • Modify the file, complete the step, and execute it.
  • Click on a remote server - successfully
  • Expect to see an echo - don't see an echo
  • Check the working folder on the server - the latest files are missing.
  • Go to the server and run the hook script manually - the latest files exit the working folder.

I changed the hook, so it does nothing but echo the message, and I read that I should see this in my console after clicking. But this is not displayed, so I can only assume that the hook does not start.

I am pushing HTTP using git dot aspx on the server, processing the request and pasting through gui locally. After that I tried Bonobo, and the hook does not work when pressed through gui or bash console.

I assume that this works for someone somewhere, but after two days of searching, all I found are solutions that do not help, or people with the same problem that went unanswered.

(I'm a git newbtw btw).

Greetings.

Update

I'm starting to think that this may be related to permissions - but Unix permissions, not NTFS. When @eis mentioned permissions, I suggested NTFS. But after even more digging, it seems that git on Windows still checks for Unix perms files.

Therefore, I suspect that the problem is that the file after receiving is not executable, as when I do ls -o it -rw-rr-- (in my opinion, 644). If I try to change this via bash and chmod 777 post-receive , then do ls -o , the permissions will be the same.

It is strange that as soon as I edited post-receive (using notepad ++), the execution bit will be deleted. (my test script, which ends with .bat, retains its execution bits, though ...)

BTW, the user I'm registered with is the owner of the files (according to ls -o ), and yet I cannot set permissions.

It starts to really get confused. 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 to the server and checked the permissions and executed it. If I rename the file (to remove the sample) on Windows, then the execution will be deleted. If I do this in bash with mv , the execution will be saved. But, whenever I edit the file (on Windows or in bash with vi), then the execution is deleted.

So now the problem is why does it delete the executable bits when editing the file?

I hope this is the last obstacle and the reason for its non-compliance ...

+2
source share
2 answers

You will need to schedule git to do this work. Checks in builtin / receive-pack.c for access(path, X_OK) . In msysgit, this translates to mingw_access, which discards the X_OK bit, as it is simply not supported on Windows.

On Windows, we do not have a flag to indicate that the file is executable. Systems often do some imitation of this. For example, tcl will look for any extension in the PATHEXT environment variable to determine if the file is executable. We cannot do this here, since the names of the hooks are hardcoded without any extensions.

Instead, I suggest changing the access test to just check the file and then call execv on the way. The mingw version (in compat / mingw.c) searches for script files and will read the shbang line and run the corresponding interpreter (sh, perl, etc.). So changing builtin/receive-pack.c:run_update_hook should let this work for you. Currently, when starting a hook, start_command used, and I think you need to call execv for you.

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

+1
source

When using msysgit on the server and clicking through file sharing without problems, they work without problems. Perhaps this has been fixed in mysysgit since the answer was written. I did not look at her.

I also noticed that in the original question it was pointed out git dot aspx and Bonobo that use GitSharp.dll. This would mean that the application is not fooling git.exe, and interceptors would not be handled the same way.

For example, the GitSharp.dll file used in git dot aspx has its own hook implementation after reception, which can be done in 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 in the turmoil between libraries that are git implementations and applications that access the actual git.exe.

0
source

Source: https://habr.com/ru/post/1444931/


All Articles