如何在 PHP 页面上显示 hg 存储库的当前工作副本版本
我的大多数项目都使用 Mercurial,当我部署网站时,我只需在生产服务器上执行 hg clone
并从那里执行 hg pull -u
即可。我想做的是在我的网站页脚中添加一个小片段,其中显示当前的修订号(十进制和十六进制)以及当前的分支。 Stack Overflow 和 BitBucket 都做了我正在寻找的事情的变体。
我简单地尝试解析 exec('hg Summary') 的输出,但在想知道是否有更好的方法之前遇到了一些权限问题。有更好的方法吗?还是 exec
是我最好的选择?
I use Mercurial for most of my projects and when I deploy a web site, I simply just do an hg clone
on the production server and hg pull -u
from there. What I'd like to do is add a small snippet to my site's footer which displays the current revision number (both decimal and hex) as well as perhaps the current branch. Stack Overflow and BitBucket both do a variation of what I'm looking for.
I briefly tried parsing the output of exec('hg summary')
, but I ran into a couple permissions problems before wondering if there was any better way to do it. Is there a better way, or is exec
my best option?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用更新后挂钩将信息放入文件中。在站点的
.hg/hgrc
中,您可以放置如下内容:然后您可以从 php 内部访问该文件。您仍然需要确保运行
hg pull -u
的用户信任 hgrc 文件,并且 VERSION 文件具有 Web 服务器可以读取它的权限。You could use a post-update hook to put the information in a file. In the site's
.hg/hgrc
you'd put something like this:then you can access that file from inside your php. You'll still need to make sure that the user running the
hg pull -u
trusts the hgrc file and that the VERSION file has permissions such that the webserver can read it.