Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mercurial

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.

like image 692
Juan Avatar asked Feb 13 '14 03:02

Juan


People also ask

How do I know my hg version?

hg/hgrc will be created on the remote side. If the source repository has a bookmark called '@' set, that revision will be checked out in the new repository by default. To check out a particular version, use -u/--update, or -U/--noupdate to create a clone with no working directory.

Where is the Mercurial INI file?

Mercurial on Windows has a three-tier configuration system. A site-wide configuration file in C:\Program Files\TortoiseHg\Mercurial. ini This file is read first and thus has the lowest priority. A per-user configuration file in C:\Documents and Settings\username\Mercurial.

Where is Mercurial INI Linux?

%USERPROFILE%\Mercurial. ini (per-user) %HOME%\. hgrc (per-user)


2 Answers

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.

like image 97
Ry4an Brase Avatar answered Sep 27 '22 18:09

Ry4an Brase


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

like image 43
daniel kullmann Avatar answered Sep 27 '22 19:09

daniel kullmann