开发者

Include revision numbers in file after commit?

I'm using TortoiseHg as the version control system for my website. I want to put a label on the website which reports the current revision that is live on the server. Rather than updating this manually, I want it to be automatic.

If I can set TortoiseHg to write the revision number to a file whenever 开发者_Go百科I do a commit, I can set my website to load the version number whenever changes are made, and render this number to the page. Is it possible to get TortoiseHg to do this?


First, I'm contractually obligated to remind you that revision numbers are largely meaningless in distributed systems.

Second, what you probably want is a hook. There are various ways to do this. The simplest is probably something like this on your webserver checkout:

# this gets run after each update, writes the LOCAL revision number to a file
[hooks]
update = hg id --num --rev . > update-number


Since you're using .NET, there are also build tools that do this automatically whenever your solution is compiled:

  • MSBuild Versioning (setup instructions)
  • MSBuild Mercurial Tasks (setup instructions)


There's also the keyword extension, which will expand CVS/SVN style keywords in files. They can include versions, dates, authors, etc...

https://www.mercurial-scm.org/wiki/KeywordExtension

...but it's also worth reading this, for reasons why you wouldn't use it.

https://www.mercurial-scm.org/wiki/KeywordPlan


  1. Read Keyword Plan and Versioning With Make in mercurial wiki
  2. Select best for you workflow policy
  3. Instead of non-templateable command id choose command, which return needed data and is templateable with --template option
  4. Write good template for version-id string, my favourite is smth near

hg tip --template "{rev}:{node|short}-{latesttag}+{latesttagdistance}\n"

where for, f.e. for hgsubversion repo today I get as result

830:d4b3b8370b3c-1.2.1+42

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜