diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -470,14 +470,17 @@ config parsing and commands. besides, use handlecommandexception to handle uncaught exceptions. """ + detailed_exit_code = -1 try: return scmutil.callcatch(ui, func) except error.AmbiguousCommand as inst: + detailed_exit_code = 10 ui.warn( _(b"hg: command '%s' is ambiguous:\n %s\n") % (inst.prefix, b" ".join(inst.matches)) ) except error.CommandError as inst: + detailed_exit_code = 10 if inst.command: ui.pager(b'help') msgbytes = pycompat.bytestr(inst.message) @@ -487,6 +490,7 @@ ui.warn(_(b"hg: %s\n") % inst.message) ui.warn(_(b"(use 'hg help -v' for a list of global options)\n")) except error.UnknownCommand as inst: + detailed_exit_code = 10 nocmdmsg = _(b"hg: unknown command '%s'\n") % inst.command try: # check if the command is in a disabled extension @@ -515,7 +519,10 @@ if not handlecommandexception(ui): raise - return -1 + if ui.configbool(b'ui', b'detailed-exit-code'): + return detailed_exit_code + else: + return -1 def aliasargs(fn, givenargs): diff --git a/tests/test-alias.t b/tests/test-alias.t --- a/tests/test-alias.t +++ b/tests/test-alias.t @@ -468,13 +468,13 @@ $ hg i hg: command 'i' is ambiguous: idalias idaliaslong idaliasshell identify import incoming init - [255] + [10] $ hg id 042423737847 tip $ hg ida hg: command 'ida' is ambiguous: idalias idaliaslong idaliasshell - [255] + [10] $ hg idalias 042423737847 tip $ hg idaliasl @@ -484,7 +484,7 @@ $ hg parentsshell hg: command 'parentsshell' is ambiguous: parentsshell1 parentsshell2 - [255] + [10] $ hg parentsshell1 one $ hg parentsshell2 @@ -533,11 +533,11 @@ $ hg --cwd .. subalias > /dev/null hg: unknown command 'subalias' (did you mean idalias?) - [255] + [10] $ hg -R .. subalias > /dev/null hg: unknown command 'subalias' (did you mean idalias?) - [255] + [10] shell alias defined in other repo @@ -545,7 +545,7 @@ $ hg mainalias > /dev/null hg: unknown command 'mainalias' (did you mean idalias?) - [255] + [10] $ hg -R .. mainalias main $ hg --cwd .. mainalias @@ -555,7 +555,7 @@ $ hg --cwd .. manalias hg: unknown command 'manalias' (did you mean one of idalias, mainalias, manifest?) - [255] + [10] shell aliases with escaped $ chars @@ -593,7 +593,7 @@ $ hg reba hg: command 'reba' is ambiguous: rebase rebate - [255] + [10] $ hg rebat this is rebate $ hg rebat --foo-bar @@ -650,22 +650,22 @@ -T --template TEMPLATE display with template (use 'hg rt -h' to show more help) - [255] + [10] invalid global arguments for normal commands, aliases, and shell aliases $ hg --invalid root hg: option --invalid not recognized (use 'hg help -v' for a list of global options) - [255] + [10] $ hg --invalid mylog hg: option --invalid not recognized (use 'hg help -v' for a list of global options) - [255] + [10] $ hg --invalid blank hg: option --invalid not recognized (use 'hg help -v' for a list of global options) - [255] + [10] environment variable changes in alias commands diff --git a/tests/test-basic.t b/tests/test-basic.t --- a/tests/test-basic.t +++ b/tests/test-basic.t @@ -67,12 +67,12 @@ $ hg unknown -q 1>&- hg: unknown command 'unknown' (did you mean debugknown?) - [255] + [10] $ hg version -q 2>&- Mercurial Distributed SCM * (glob) $ hg unknown -q 2>&- - [255] + [10] $ hg commit -m test diff --git a/tests/test-completion.t b/tests/test-completion.t --- a/tests/test-completion.t +++ b/tests/test-completion.t @@ -242,7 +242,7 @@ $ hg debugcomplete --options s hg: command 's' is ambiguous: serve shelve showconfig status summary - [255] + [10] Show all commands + options $ hg debugcommands diff --git a/tests/test-dispatch.t b/tests/test-dispatch.t --- a/tests/test-dispatch.t +++ b/tests/test-dispatch.t @@ -29,7 +29,7 @@ -T --template TEMPLATE display with template (use 'hg cat -h' to show more help) - [255] + [10] Missing parameter for early option: @@ -110,7 +110,7 @@ hg log: option -b not recognized error in definition for alias 'log': --config may only be given on the command line - [255] + [10] $ hg log -b '--config=defaults.log=--config=hooks.pre-log=false' abort: option --config may not be abbreviated diff --git a/tests/test-extension.t b/tests/test-extension.t --- a/tests/test-extension.t +++ b/tests/test-extension.t @@ -1018,7 +1018,7 @@ multirevs command (use 'hg multirevs -h' to show more help) - [255] + [10] @@ -1848,7 +1848,7 @@ *** (use @command decorator to register 'deprecatedcmd') hg: unknown command 'deprecatedcmd' (use 'hg help' for a list of commands) - [255] + [10] the extension shouldn't be loaded at all so the mq works: @@ -1905,4 +1905,4 @@ *** (use b'' to make it byte string) hg: unknown command 'dummy' (did you mean summary?) - [255] + [10] diff --git a/tests/test-fastannotate.t b/tests/test-fastannotate.t --- a/tests/test-fastannotate.t +++ b/tests/test-fastannotate.t @@ -123,7 +123,7 @@ $ hg fastannotate --config fastannotate.modes=fctx -h -q hg: unknown command 'fastannotate' (did you mean *) (glob) - [255] + [10] rename diff --git a/tests/test-help.t b/tests/test-help.t --- a/tests/test-help.t +++ b/tests/test-help.t @@ -593,7 +593,7 @@ -n --dry-run do not perform actions, just print output (use 'hg add -h' to show more help) - [255] + [10] Test ambiguous command help @@ -763,13 +763,13 @@ $ hg skjdfks hg: unknown command 'skjdfks' (use 'hg help' for a list of commands) - [255] + [10] Typoed command gives suggestion $ hg puls hg: unknown command 'puls' (did you mean one of pull, push?) - [255] + [10] Not enabled extension gets suggested @@ -780,7 +780,7 @@ rebase command to move sets of revisions to a different ancestor (use 'hg help extensions' for information on enabling extensions) - [255] + [10] Disabled extension gets suggested $ hg --config extensions.rebase=! rebase @@ -790,7 +790,7 @@ rebase command to move sets of revisions to a different ancestor (use 'hg help extensions' for information on enabling extensions) - [255] + [10] Checking that help adapts based on the config: @@ -804,16 +804,16 @@ $ hg .log hg: unknown command '.log' (did you mean log?) - [255] + [10] $ hg log. hg: unknown command 'log.' (did you mean log?) - [255] + [10] $ hg pu.lh hg: unknown command 'pu.lh' (did you mean one of pull, push?) - [255] + [10] $ cat > helpext.py < import os diff --git a/tests/test-narrow-trackedcmd.t b/tests/test-narrow-trackedcmd.t --- a/tests/test-narrow-trackedcmd.t +++ b/tests/test-narrow-trackedcmd.t @@ -118,7 +118,7 @@ web.cacerts config) (use 'hg tracked -h' to show more help) - [255] + [10] $ hg tracked --import-rules doesnotexist abort: cannot read narrowspecs from '$TESTTMP/narrow/doesnotexist': $ENOENT$ [50] diff --git a/tests/test-qrecord.t b/tests/test-qrecord.t --- a/tests/test-qrecord.t +++ b/tests/test-qrecord.t @@ -105,7 +105,7 @@ interactively record a new patch (use 'hg qrecord -h' to show more help) - [255] + [10] qrecord patch (mq not present) diff --git a/tests/test-share-safe.t b/tests/test-share-safe.t --- a/tests/test-share-safe.t +++ b/tests/test-share-safe.t @@ -92,7 +92,7 @@ extdiff command to allow external programs to compare revisions (use 'hg help extensions' for information on enabling extensions) - [255] + [10] $ echo "[extensions]" >> ../source/.hg/hgrc $ echo "extdiff=" >> ../source/.hg/hgrc diff --git a/tests/test-status-color.t b/tests/test-status-color.t --- a/tests/test-status-color.t +++ b/tests/test-status-color.t @@ -394,7 +394,7 @@ $ hg unknowncommand > /dev/null hg: unknown command 'unknowncommand' (use 'hg help' for a list of commands) - [255] + [10] color coding of error message without curses @@ -402,6 +402,6 @@ $ PYTHONPATH=`pwd`:$PYTHONPATH hg unknowncommand > /dev/null hg: unknown command 'unknowncommand' (use 'hg help' for a list of commands) - [255] + [10] $ cd .. diff --git a/tests/test-strict.t b/tests/test-strict.t --- a/tests/test-strict.t +++ b/tests/test-strict.t @@ -16,7 +16,7 @@ $ hg an a hg: unknown command 'an' (use 'hg help' for a list of commands) - [255] + [10] $ hg annotate a 0: a diff --git a/tests/test-strip.t b/tests/test-strip.t --- a/tests/test-strip.t +++ b/tests/test-strip.t @@ -782,7 +782,7 @@ --mq operate on patch repository (use 'hg debugstrip -h' to show more help) - [255] + [10] $ cd ..