php - 在 Windows 上执行 Git 钩子(Hook)

标签 php windows git hook

我在 Windows 上执行 Git Hook 时遇到问题。我有一个裸仓库,在它的“hooks”文件夹中,我将以下内容放入“更新”和“预推”文件中,但 PHP 脚本永远不会被执行:

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

关于为什么不执行 PHP 脚本的任何想法?

在 Git 控制台窗口中,当我尝试将某些内容推送到裸仓库时,我看到以下内容:

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'

...所以我知道“更新”正在以某种方式执行。当我删除该文件时,推送工作正常。

最佳答案

默认情况下,Windows 版 Git 使用它自己的 bash shell Windows 端口执行 Hook 脚本。当然,Unix shell 不知道 %1。据说,Windows 版 Git 有额外的黑客攻击来检测“常见”文件扩展名——例如 .bat——并在这种情况下采取备用路径。

我认为你对自己程序的修复是最好的,但另一种方法是重写你的脚本以阅读

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

(shebang 行在 Windows 下没有真正的特殊意义,除了提示下一个人编辑脚本内容的含义)。

关于php - 在 Windows 上执行 Git 钩子(Hook),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18277429/

相关文章:

html - 网站在 Windows 和 Mac 上定位元素的方式不同

linux - 我正在处理哪些文件?

git - svn 到 git 迁移后 trunk 与 master 分支的区别

PHP/MYSQL - 仅显示表中的左连接项,但连接列中的右连接值

php - CakePHP 2.1 JsonView

php - SQL:如果在另一个表中找不到给定的 ID,则将值插入一个表中(使用单个查询)

php - window : Add site directory to Apache config

Python:在 Windows 或 Linux 上获取挂载点

windows - 如何获取FILETIME格式的当前时间?

git - 如何欺骗 git-svn 来识别用 svn 进行的 merge ?