Home

Config extension for mercurial

This extension provides command-line access to hg configuration values stored in hg rc files. You can use this extension to view and change configuration values, show which configuration files are used by hg, and edit any of these files from the command-line.

Three commands are provided by this extension:

  • hg showconfigs
  • hg editconfig
  • hg config

enabling the config extension

To enable this extension download the config.py and save it somewhere on your system. Then edit your config file so that it has something similar to:

     [extensions]
     config = /my/path/to/config.py

hg showconfigs

This command will show you which configuration files are searched for, which are present, and which are writeable:

     prompt> hg showconfigs
      * c:\Program Files\Mercurial\mercurial.ini
      ! C:\cygwin\home\jdoe\mercurial.ini
      ! C:\cygwin\home\jdoe\.hgrc
      * C:\Documents and Settings\jdoe\mercurial.ini
      ! C:\Documents and Settings\jdoe\.hgrc
      * d:\projects\hgconfig\src\.hg\hgrc

another example:

     prompt> hg showconfigs
      ! /usr/etc/mercurial/hgrc
      * /etc/mercurial/hgrc
      * /etc/mercurial/hgrc.d/hgext.rc (ro)
      * /etc/mercurial/hgrc.d/mergetools.rc (ro)
      * /home/jdoe/.hgrc
      * /home/jdoe/projects/hgconfig/.hg/hgrc
  • '!' means the file is searched for but does not exist
  • '*' means the file is searched for and is found
  • (ro) means the file exists but is read-only for the current user

hg editconfig

This command will open up an editor to edit your local or global configuration files. By default, the --local option is implied.

The following command will open your local .hg/hgrc config:

     hg editconfig

To edit (one of) your global config(s), use the --global option. If more than one writeable global configuration is found, you will be prompted for input on which to edit. The 'most local' config file is set as the default:

     prompt> hg editconfig --global
     multiple config files to choose from, please select:
      [0] C:\Documents and Settings\jdoe\mercurial.ini
      [1] c:\Program Files\Mercurial\mercurial.ini
     which file do you want to edit: [0]

To choose between all possible config files, use --global with --local:

     prompt> hg editconfig --global --local
     multiple config files to choose from, please select:
      [0] d:\projects\hgconfig\.hg\hgrc
      [1] C:\Documents and Settings\jdoe\mercurial.ini
      [2] c:\Program Files\Mercurial\mercurial.ini
     which file do you want to edit: [0]

hg config

Depending on the number of paramaters the config command can be used to view or set config values.

viewing configuration

To view a configuration variable, use the config command:

     hg config <section>.<key>

Where <section> is the ini file section (eg. ui) and <key> is the key you want to change (eg.ui). Here is some example output:

     prompt>  hg config ui.username
     jdoe@host
     john

If more than one value is shown that indicates that multiple values have been found in your hg configuration files. The last value is always the one used by hg. You can double-check using the mercurial builtin showconfig command:

     prompt> hg showconfig ui.username
     john

For more information on which file contains which value, use the --verbose flag:

     prompt> hg config --verbose ui.username
     values found for ui.username:
      jdoe@host  C:\Documents and Settings\jdoe\mercurial.ini
      john       d:\projects\hgconfig\src\.hg\hgrc

setting configuration

To set a configuration variable, use the config command:

     hg config <section>.<key> <new_value>

Where <section> is the ini file section (eg. ui), <key> is the key you want to change (eg.ui), and <new_value> is the value you would like to set. For example:

     hg config ui.username john doe <jdoe@host>

By default this command is working on the local config file. Here is an example before and after of the local config file:

     ;======== .hg/hgrc BEFORE =======
     [ui]
     username = john


     ;======== .hg/hgrc AFTER ========
     [ui]
     username = john doe <jdoe@host>
     ;username = john

Replaced values are prepended with a ';' to make them as comments. If you prefer to have those lines removed completely, put this in your hgrc:

     [config]
     delete_on_replace = True

Or if you have already enabled the config extension:

     hg config --global config.delete_on_replace True

Many extensions are enabled by assigning them an 'empty' value. For example, to enable to the bookmarks extension you might do:

     hg config --global extensions.hgext.bookmarks " "

If you require " or ' characters in your values, you can do so with the following:

     hg config foo.bar "\"this string as double quotes around it\""
     hg config foo.baz \'this string has single quotes around it\'

Updated

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.