spanky spanky - 1 year ago 134
Git Question

Git post-receive hook not working

My setup is a windows XAMPP server, with cURL enabled, and Git and Hudson installed. Hudson polls Git every minute to look for changes, and if it finds them, it creates a build. I use this build as my testing server. This works fine.

I would like to set up a post-receive hook on my central remote repository that runs the force build function of Hudson.

I've created a post-receive file called "post-receive" in the hooks directory in my central Git repository, the one that is pushed to from the developers' local branches. They each push to their own branch on the central repository. I want to run the post-receive build immediately after every push, instead of having Hudson poll Git every minute.

When I open a shell to the remote server and run "post-receive" in the hooks folder, it runs. It just isn't being called when people push to it from their local repository copies to the central one.

Maybe I'm not explaining this right, but it's how I understand Git.

The post-receive code is two lines:


Again, when I open a shell and run this, it works, but when someone pushes to it, nothing happens, until a minute or less goes by, Hudson realizes that Git was changed, and then it builds.

I am happy to clarify if need be. Any help is greatly appreciated.

EDIT: After playing around with it, I feel like maybe post-receive isn't executing because refs aren't being updated of something? The git documentation says

It executes on the remote repository once after all the refs have been updated.

Does this mean if nothing updates, it won't execute? And if so, I'm pretty sure things are updating anyway so it shouldn't apply.

Here's my process:
Make edits locally.
Commit edits.
Push from my HEAD to the remote branch called 'mybranch' (not the master branch, which is checked out)
This is the point at which I want my hook to execute.

Answer Source

All of these answers are useful, but it turns out I needed the "bin" directory of git in my PATH variable. I had the "cmd" directory only. Added c:\my_path_to_git\git\bin to PATH and it works fine. I found this answer by trial and error and looking at the apache error log. Thank you all for your help!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download