Hgweb Mercurial template customization

%META:TOPICINFO{author="colas" comment="" date="1609274046" format="1.1" reprev="4" version="4"}%

Customizing the style of a HG / mercurial web repository

If you use the hgwebdir.cgi system to provide a web view of your mercurial repository, to customize the style like I did for http://hg.colas.nahaboo.net, a way to do it is (in debian, paths to adapt to your linux distribution):

  • copy /usr/share/mercurial/templates/gitweb somewhere among your hg repositories. make a hg repository out of it
  • clone it to another one, e.g. myhg. This way, when upgrades will change the distributed templates, you will just have to copy the new ones in your gitweb repo, commit, and pull+merge the changes into your myhg repo.
  • edit the files in it: header.tmpl to add css code, etc. Adding links in the page headers will make you edit most of the files
  • install by copying it to /usr/share/mercurial/templates/myhg
  • edit your /etc/mercurial/hgrc to tell hgwebdir.cgi to use your new templates by a line style=myhg . in your [web] section. Here is my file as an exemple:
# system-wide mercurial configuration file
# See hgrc(5) for more information
[trusted]
users=colas
[web]
baseurl=http://hg.colas.nahaboo.net/
contact=colas@nahaboo.net
description=Open source software made by Colas Nahaboo
maxchanges=16
staticurl=http://hg.colas.nahaboo.net/static/
style=colas
  • The above will make these settings global to the site. but you can still override them on a per-repository basis by adding these lines into the hgweb.config of the repositories.
  • Note that you can use HTML code in the description field
  • This hgrc is not cloned by hg. So you must add/edit it directly on the web repository, you cannot prepare it in advance in your work dir and expect it to be pushed on the web site on first creation

-- ColasNahaboo - 2008-04-06