How to do post-receive capture in msysgit on windows hosted by Apache?

I am creating a Git server on a Windows host. I installed the latest Apache and am working with msysGit. I do not use SSH at all; I can click and pull HTTP.

Now I want to add a post-receive hook to notify my build server, but I cannot figure out how to do this. I see scripts with samples in the repository on the server, but I'm confused about what to do there. Did I put a Windows batch file called post-receive.bat or do something else?

I'm a little unclear in the details that this all does, but Apache does c: \ Program Files \ git \ libexec \ git -core \ git -http-backend.exe when it sees the Git URL. Is git -http-backend.exe to start receiving after receiving?

Update I'm getting closer. Here is my hook, in hooks/post-receive in my repo:

 #!/c/Program Files/Git/bin/sh curl http://mybuildserver:8080/job/Whazzup/build 

I changed shebang from #!/bin/sh , because it wasnโ€™t on Windows. Now in the Apache error log I get the error: cannot spawn hooks/post-receive: No such file or directory message

By the way, Git bash chmod does not seem to work. But I managed to get permission for post-receive to rwxr-xr-x by renaming the sample file.

Update I changed the shebang line to #!/bin/sh , but still getting the same error in the Apache error: cannot spawn hooks/post-receive: No such file or directory log: error: cannot spawn hooks/post-receive: No such file or directory . As a test, I opened the Git bash prompt in the hooks folder and executed the hook using ./post-receive , and it worked.

Update Now I am wondering if I have another problem. Accepting the recommendations of VonC, I tried to run Apache httpd from the command line in my own account, and not as a service in LocalSystem. Another one and the same. Pushing and pulling works fine, but the hook does not work. Then I tried to deduce Apache from the equation. From the Git bash prompt on the same computer as the repo, I made a clone (via the file system), changed, committed, and clicked. But the hook was still not being executed.

Update Ok, I had a stupid problem on my script hook, but now, at least, it runs when I click on the repo from the same computer (via the file system). But not when I push Apache. Apache now runs under a regular account, and the Apache account has full control over the repository. The pusher works fine, but the hook after receiving is not executed.

+4
source share
1 answer

Apache executes c:\Program Files\git\libexec\git-core\git-http-backend.exe when it sees the Git URL. Can git-http-backend.exe launch the hook after receiving?

No, it will pass the command ( clone , push , pull ) to git itself.
post-receive hook will be launched after the completion of the click, and this is a bash (unix shell) script, as shown in " post-receive hook on Windows - GIT_WORK_DIR: there is no such file or directory ".

See also " git windows post pull " to see where you can create a post-receive script (in the .git/hooks your repo): it has nothing to do with your Apache HTTP service in front of the repositories.


Regarding the error message "hooks / post-reception cannot appear: there is no such file or directory", you can refer to " msysgit error with errors:" git: .git / hooks / post-commit cannot appear: there is no such file or catalog and :

  • Sharing should be #!/bin/sh
  • Apache must run as a regular user instead of the local system in order to use the environment variables defined for the regular user.
  • <path_to_git>\bin must be in PATH
+3
source

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


All Articles