在Windows上执行Git钩子 [英] Executing Git hooks on Windows
问题描述
在Windows上执行Git挂钩时遇到问题。我有一个简单的repo,并且在它的hooks文件夹中,我将以下内容放入更新和预推送文件中,但PHP脚本永远不会执行:
有关PHP脚本未执行的任何想法?
在Git控制台窗口中,当我尝试将某些内容推送到裸回购时,我会看到以下内容: $ b
POST git-receive-pack(437字节)
remote:错误:hook拒绝更新refs / heads / master
到https:// myuser @ mydomain / samplerepo
! [remote rejected] master - > master(钩子已拒绝)
错误:未能将某些裁判推送到'https:// myuser @ mydomain / samplerepo'
...所以我知道更新以某种方式被执行。
默认情况下,Git for Windows使用自己的Windows端口执行钩子脚本 bash
shell。当然,Unix shell不知道%1
。据推测,Git for Windows有额外的黑客来检测常见文件扩展名—如 .bat
—并在这种情况下采取替代路线。
我认为您对自己的程序的修复是最好的,但另一种方法是将您的脚本重写为
#!/ bin / sh
c:/Programs/PHP/php.exe c:/ Data / Scripts / git- pre-push.phpcli$ @
(在Windows下shebang行没有真正的特殊意义)而不是暗示下一个人编辑有关其内容含义的脚本)。
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.
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).
这篇关于在Windows上执行Git钩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!