Provides a command that runs configured tools on the contents of modified files, writing back any fixes to the working copy or replacing changesets.

Here is an example configuration that causes hg fix to apply automatic formatting fixes to modified lines in C++ code:

clang-format:command=clang-format --assume-filename={rootpath}
clang-format:pattern=set:**.cpp or **.hpp

The :command suboption forms the first part of the shell command that will be used to fix a file. The content of the file is passed on standard input, and the fixed file content is expected on standard output. Any output on standard error will be displayed as a warning. If the exit status is not zero, the file will not be affected. A placeholder warning is displayed if there is a non-zero exit status but no standard error output. Some values may be substituted into the command:

{rootpath}  The path of the file being fixed, relative to the repo root
{basename}  The name of the file being fixed, without the directory path

If the :linerange suboption is set, the tool will only be run if there are changed lines in a file. The value of this suboption is appended to the shell command once for every range of changed lines in the file. Some values may be substituted into the command:

{first}   The 1-based line number of the first line in the modified range
{last}    The 1-based line number of the last line in the modified range

The :pattern suboption determines which files will be passed through each configured tool. See hg help patterns for possible values. If there are file arguments to hg fix, the intersection of these patterns is used.

There is also a configurable limit for the maximum size of file that will be processed by hg fix:

maxfilesize = 2MB

Normally, execution of configured tools will continue after a failure (indicated by a non-zero exit status). It can also be configured to abort after the first such failure, so that no files will be affected if any tool fails. This abort will also cause hg fix to exit with a non-zero status:

failure = abort

When multiple tools are configured to affect a file, they execute in an order defined by the :priority suboption. The priority suboption has a default value of zero for each tool. Tools are executed in order of descending priority. The execution order of tools with equal priority is unspecified. For example, you could use the 'sort' and 'head' utilities to keep only the 10 smallest numbers in a text file by ensuring that 'sort' runs before 'head':

sort:command = sort -n
head:command = head -n 10
sort:pattern = numbers.txt
head:pattern = numbers.txt
sort:priority = 2
head:priority = 1

To account for changes made by each tool, the line numbers used for incremental formatting are recomputed before executing the next tool. So, each tool may see different values for the arguments added by the :linerange suboption.



rewrite file content in changesets or working directory:

hg fix [OPTION]... [FILE]...

Runs any configured tools to fix the content of files. Only affects files with changes, unless file arguments are provided. Only affects changed lines of files, unless the --whole flag is used. Some tools may always affect the whole file regardless of --whole.

If revisions are specified with --rev, those revisions will be checked, and they may be replaced with new revisions that have fixed file content. It is desirable to specify all descendants of each specified revision, so that the fixes propagate to the descendants. If all descendants are fixed at the same time, no merging, rebasing, or evolution will be required.

If --working-dir is used, files with uncommitted changes in the working copy will be fixed. If the checked-out revision is also fixed, the working directory will update to the replacement revision.

When determining what lines of each file to fix at each revision, the whole set of revisions being fixed is considered, so that fixes to earlier revisions are not forgotten in later ones. The --base flag can be used to override this default behavior, though it is not usually desirable to do so.


--all fix all non-public non-obsolete revisions
--base <REV[+]>
 revisions to diff against (overrides automatic selection, and applies to every revision being fixed)
-r, --rev <REV[+]>
 revisions to fix
-w, --working-dir
 fix the working directory
--whole always fix every line of a file

[+] marked option can be specified multiple times