Juan
Juan

Reputation: 1371

Is there a way to check the hg version in ~/.hgrc file?

Can I check the version of mercurial before setting a particular setting in my ~/.hgrc file? For example, I'd like to enable an extension (say the shelve extension), but only if the hg version is a particular version (say 2.8 or later). This is particularly useful when one's home directory is shared (think nfs) over many machines that have various versions of hg installed.

Upvotes: 5

Views: 300

Answers (2)

daniel kullmann
daniel kullmann

Reputation: 14023

You could also have hg read a different hgrc file by checking the version of hg in .bashrc and setting the HGRCPATH Variable accordingly; See Mercurial .hgrc file

Upvotes: 2

Ry4an Brase
Ry4an Brase

Reputation: 78330

That's an interesting one. There are no conditionals in the hgrc format, but there are variable expansions in include lines, so you could put this in your .bash_profile:

HG_VERSION=$(python -c 'from mercurial.__version__ import version; print version')

and then in your ~/.hgrc have something like:

%include ~/.hgrc-$HG_VERSION

which would include a file like, ~/.hgrc-2.6.2

To avoid errors you need a possibly empty file for each version you run, and you could use bash-fu to trim off the minor version for a little flexibility. It still won't get you greater-than functionality, though.

The more normal way to do this is to use the include mechanism to include host or OS specific hgrc files like:

%include ~/.hgrc-$HOST

which lets you add in bits that are run only on certain hosts.

Upvotes: 5

Related Questions