Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing Git hooks on Windows

I'm having trouble executing Git hooks on Windows. I have a bare repo and in it's "hooks" folder I put the following into both the "update" and "pre-push" files but the PHP script is never being executed:

"c:/Programs/PHP/php.exe" c:/Data/Scripts/git-pre-push.phpcli %1

Any ideas as to why the PHP script isn't executed?

In the Git console window I see the following when I try to push something to the bare repo:

POST git-receive-pack (437 bytes)
remote: error: hook declined to update refs/heads/master
To https://myuser@mydomain/samplerepo
! [remote rejected] master -> master (hook declined)
error: failed to push some refs to 'https://myuser@mydomain/samplerepo'

...so I know that the "update" is somehow being executed. When I remove that file the push works just fine.

like image 683
TheStoryCoder Avatar asked Aug 16 '13 15:08

TheStoryCoder


1 Answers

By default, Git for Windows executes hook scripts using its own Windows port of the bash shell. Certainly, a Unix shell has no idea about %1. Supposedly, Git for Windows has extra hacks in place to detect "common" filename extensions — such as .bat — and take an alternate route in such a case.

I think your fix to your own program is the best, but another approach would be to rewrite your script to read

#!/bin/sh
c:/Programs/PHP/php.exe c:/Data/Scripts/git-pre-push.phpcli "$@"

(the shebang line has no real special sense under Windows other than hinting the next person to edit the script about the meaning of its content).

like image 133
kostix Avatar answered Oct 02 '22 22:10

kostix