System-Wide Configuration

On Unix-like systems shared by multiple users (such as a server to which people publish changes), it often makes sense to set up some global default behaviors, such as what theme to use in web interfaces.

If a file named /etc/mercurial/hgrc exists, Mercurial will read it at startup time and apply any configuration settings it finds in that file. It will also look for files ending in a .rc extension in a directory named /etc/mercurial/hgrc.d, and apply any configuration settings it finds in each of those files.

Making Mercurial More Trusting

One situation in which a global hgrc can be useful is if users are pulling changes owned by other users. By default, Mercurial will not trust most of the configuration items in a .hg/hgrc file inside a repository that is owned by a different user. If we clone or pull changes from such a repository, Mercurial will print a warning stating that it does not trust their .hg/hgrc.

If everyone in a particular Unix group is on the same team and should trust each other’s configuration settings, or we want to trust particular users, we can override Mercurial’s skeptical defaults by creating a system-wide hgrc file such as the following:

# Save this as e.g. /etc/mercurial/hgrc.d/trust.rc
[trusted]
# Trust all entries in any hgrc file owned by the "editors" or
# "www-data" groups.
groups = editors, www-data

# Trust entries in hgrc files owned by the following users.
users = apache, bobo

Get Mercurial: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.