How to display current working copy version of an hg repository on a PHP page
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.
Jimmy Sawczuk
I am a 2009 graduate of Case Western Reserve University with a degree in computer science. I work primarily in Go, PHP and Javascript (jQuery) (along with HTML/CSS), but have some .NET experience and have dabbled in a few other languages. I also maintain a bunch of smaller projects on the side. When I'm not coding, I enjoy running, reading, writing and watching baseball.
Updated on June 03, 2022Comments
-
Jimmy Sawczuk about 2 years
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 andhg 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 isexec
my best option? -
Tim Henigan about 13 yearsA good description of the revision can obtained with something like
hg log -r . --template "v{latesttag}-{latesttagdistance}-{node|short}\n"
. This returns a string like "v1.0.0-2-5e51254a" (i.e. 2 commits after tag1.0.0
with changeset id5e51254a
. -
Jimmy Sawczuk about 13 yearsGood answer - I like it. Doesn't rely on
exec
, easy enough to implement. Thanks! -
Thomas Keller over 12 years
hg id -r
expects an argument, I guess you meant-n
? -
Ry4an Brase over 12 yearsRight you are @tommyd, though Tim Henigan's form is better yet.