It doesn't happen too often, but every once in a while I'll fumble with my typing and accidentally invoke "hg resolve -m" without a file argument. This then helpfully marks all the conflicts resolved. Is there any way to prevent it from resolving without one or more file arguments?
1 Answers
You can do this with a pre-resolve
hook but you'd have to parse the arguments yourself to ensure that they are valid which could be tricky.
The relevant environment variables that you might need to look at are:
HG_ARGS
- the contents of the whole command line e.g.resolve -m
HG_OPTS
- a dictionary object containing options specified. This would have an an entry calledmark
with a value ofTrue
if-m
had been specifiedHG_PATS
- this is the list of files specified
Depending upon the scripting language you would use, you should be able to test if HG_OPTS
contains a value of True
for mark
and fail if it does and the HG_PATS
array is empty.
It starts to get complicated when you take into account the --include
and --exclude
arguments.
If you specify the files to resolve as part of the --include
option then the files to include would be in HG_OPTS
, not HG_PATS
. Also, I don't know what would happen if you specified hg resolve -m test.txt --exclude test.txt
. I'd hope that it would not resolve anything but you'd need to test that.
Once you've parsed the command arguments, you'd return either 0 to allow the command or 1 to prevent it. You should echo a reason for the failure if you return 1 to avoid confusion later.
If you don't know how to do this then you'd need to specify what OS and shell you are using for anyone to provide more specific help.

- 6,262
- 2
- 23
- 27