Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git hooks not firing

Tags:

git

windows

I have git running on a local Windows PC and everything is working perfectly; I have Jenkins and Phing working to automate my build and test processes, however the final step is to automatically kick off the build once a commit is made in git.

I have tried adding post-commit to my local repo's .git/hooks directory with the following:

curl http://localhost:8198/git/notifyCommit?url=c:\scm\myProject

If I run this command directly from the command line Jenkins kicks off the job fine, however when I push a commit it does not fire.

Additionally I have tried adding the script at https://github.com/MestreLion/git-tools/blob/master/git-restore-mtime to the hooks directory in the main repo named post-checkout so that I can add the commit time as the file modified time when cloned. This is also not firing.

Do I need to do something specifically in git or my repo to allow hooks to fire? If not, is there anywhere in particular I can look to start troubleshooting?

like image 432
Jordan Windebank Avatar asked Jan 28 '26 23:01

Jordan Windebank


1 Answers

Do I need to do something specifically in git or my repo to allow hooks to fire?

Mainly:

  • make sure the hook is executable (chmod 775 .git/hooks/post-commit, which isn't actually needed on Windows)
  • make sure 'curl' is in the %PATH% (which is the case if your <c:\path\to\git>\bin is in said path)
  • make sure your command-line test did use the curl package with Git, and not another curl like the one package with GoW Gnu on Windows (if you have GoW installed)
  • add, if it helps, a #!/bin/sh at the beginning of your post-commit script (since it will be executed by the msys bash)
  • the name must be post-c ommit (case sensitive, no extension like .sh or .bat)

The Op mentions an issue with missing quotes around the curl argument.
This is consistent with the fact that it is called in an msys bash session, and shell quoting rules apply.
I would make sure the '\' character isn't interpreted as well. See "Which quoting method protects which characters?":

Double quotes ("...") protect everything except double quotes, backslashes, dollar signs, and backquotes, until the next double quote.
A backslash can be used to protect ", \, $, or within double quotes.
A backslash-newline pair disappears completely; a backslash that does not precede ", \, $, , or newline is taken literally.

In your case, I would use:

curl "http://localhost:8198/git/notifyCommit?url=c:\\scm\\myProject"
like image 115
VonC Avatar answered Jan 30 '26 14:01

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!