Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
497 views
in Technique[技术] by (71.8m points)

mercurial - How to display current working copy version of an hg repository on a PHP page

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:

[hooks]
post-update = hg id --rev > VERSION ; hg id --id >> VERSION

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...