从STDIN上读取Git pre-commit Hook(使用PHP) [英] Read from STDIN on a Git pre-commit Hook (with PHP)

查看:163
本文介绍了从STDIN上读取Git pre-commit Hook(使用PHP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法让 git-commit 等待标准输入。我在 PHP 中编写了这个代码,因为我的 bash 技能是不存在的,所以我们需要做一个普通的

 <?php 
$ input = trim(fgets(STDIN));
fscanf(STDIN,%d \\\
,$ line);
?>

会诀窍,等到我写东西继续下去,继续执行我的PHP脚本。



这个背后的想法是,在我发布一个版本后,git会推送 HEAD 发送到测试网络服务器,发送一些推文,并让我在CHANGELOG中写入一些关于发布的细节。



虽然我可以实现写入文件(使用 exec('mate -w')),我希望它可以继续,直到我在服务器上做一个快速测试。如果我发现任何错误(懒惰,我知道),这将使我能够回滚。



感谢您的帮助!

解决方案

大多数git钩子都有一些特殊的东西给stdin,或者stdin从终端分离。它们都设计成非交互式运行,所以我不认为钩子适合你想要做的事情。当然,您可以手动与 / dev / tty 进行交谈,但我认为这不是一个好主意。



我也不相信'pre-commit'钩子适合你的任务,当然不是你所做的每个提交都会是某种发布吗?测试webserver机器上的'post-receive'挂钩听起来更合适。

I'm looking for a way to have git-commit wait for standard input. I'm coding this in PHP, as my bash skills are non-existant, so I thougth doing a regular

<?php
$input = trim(fgets(STDIN));
fscanf(STDIN, "%d\n", $line);
?>

would do the trick, and wait until I write stuff in to continue, but it just goes ahead and continues executing my PHP script anyways.

The idea behind this is that after I tag a release, git will push HEAD to the testing webserver, send a couple of tweets, and let me write in some details about the release in the CHANGELOG.

While I can achieve the writing to a file (using exec('mate -w')), I'd like it to hang on until I do a quick test on the server. This would enable me to rollback if I notice any errors (lazy, I know).

Thanks for any help!

解决方案

Most git hooks either have something special fed to there stdin, or have stdin detached from the terminal. They are all designed to be run non-interactively, so I don't believe that a hook is suitable for what you want to do. You can, of course, manually talk to /dev/tty but I don't think that it's a very good idea.

I also don't believe that the 'pre-commit' hook is suitable to your task, surely not every commit that you make will be a release of some sort? A 'post-receive' hook on the testing webserver machine sounds more appropriate.

这篇关于从STDIN上读取Git pre-commit Hook(使用PHP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆