From patchwork Tue Nov 24 18:07:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D9388: errors: raise InputError on bad top-level flags From: phabricator X-Patchwork-Id: 47667 Message-Id: To: Phabricator Cc: mercurial-devel@mercurial-scm.org Date: Tue, 24 Nov 2020 18:07:41 +0000 martinvonz created this revision. Herald added a reviewer: hg-reviewers. Herald added a subscriber: mercurial-patches. REPOSITORY rHG Mercurial BRANCH default REVISION DETAIL https://phab.mercurial-scm.org/D9388 AFFECTED FILES mercurial/dispatch.py tests/test-dispatch.t tests/test-globalopts.t CHANGE DETAILS To: martinvonz, #hg-reviewers Cc: mercurial-patches, mercurial-devel diff --git a/tests/test-globalopts.t b/tests/test-globalopts.t --- a/tests/test-globalopts.t +++ b/tests/test-globalopts.t @@ -135,22 +135,22 @@ $ hg --confi "foo.bar=baz" abort: option --config may not be abbreviated - [255] + [10] $ hg --cw a tip abort: option --cwd may not be abbreviated - [255] + [10] $ hg --rep a tip abort: option -R has to be separated from other options (e.g. not -qR) and --repository may only be abbreviated as --repo - [255] + [10] $ hg --repositor a tip abort: option -R has to be separated from other options (e.g. not -qR) and --repository may only be abbreviated as --repo - [255] + [10] $ hg -qR a tip abort: option -R has to be separated from other options (e.g. not -qR) and --repository may only be abbreviated as --repo - [255] + [10] $ hg -qRa tip abort: option -R has to be separated from other options (e.g. not -qR) and --repository may only be abbreviated as --repo - [255] + [10] Testing --cwd: diff --git a/tests/test-dispatch.t b/tests/test-dispatch.t --- a/tests/test-dispatch.t +++ b/tests/test-dispatch.t @@ -63,20 +63,20 @@ $ hg cat --debugg abort: option --debugger may not be abbreviated - [255] + [10] Parsing failure of early options should be detected before executing the command: $ hg log -b '--config=hooks.pre-log=false' default abort: option --config may not be abbreviated - [255] + [10] $ hg log -b -R. default abort: option -R has to be separated from other options (e.g. not -qR) and --repository may only be abbreviated as --repo - [255] + [10] $ hg log --cwd .. -b --cwd=. default abort: option --cwd may not be abbreviated - [255] + [10] However, we can't prevent it from loading extensions and configs: @@ -86,7 +86,7 @@ $ hg log -b '--config=extensions.bad=bad.py' default *** failed to import extension bad from bad.py: bad abort: option --config may not be abbreviated - [255] + [10] $ mkdir -p badrepo/.hg $ echo 'invalid-syntax' > badrepo/.hg/hgrc @@ -114,7 +114,7 @@ $ hg log -b '--config=defaults.log=--config=hooks.pre-log=false' abort: option --config may not be abbreviated - [255] + [10] Shell aliases bypass any command parsing rules but for the early one: @@ -144,13 +144,13 @@ $ HGPLAIN=+strictflags hg log --config='hooks.pre-log=false' -b default abort: option --config may not be abbreviated - [255] + [10] $ HGPLAIN=+strictflags hg log -q --cwd=.. -b default abort: option --cwd may not be abbreviated - [255] + [10] $ HGPLAIN=+strictflags hg log -q -R . -b default abort: option -R has to be separated from other options (e.g. not -qR) and --repository may only be abbreviated as --repo - [255] + [10] $ HGPLAIN=+strictflags hg --config='hooks.pre-log=false' log -b default abort: pre-log hook exited with status 1 diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -1058,18 +1058,20 @@ req.canonical_command = cmd if options[b"config"] != req.earlyoptions[b"config"]: - raise error.Abort(_(b"option --config may not be abbreviated")) + raise error.InputError(_(b"option --config may not be abbreviated")) if options[b"cwd"] != req.earlyoptions[b"cwd"]: - raise error.Abort(_(b"option --cwd may not be abbreviated")) + raise error.InputError(_(b"option --cwd may not be abbreviated")) if options[b"repository"] != req.earlyoptions[b"repository"]: - raise error.Abort( + raise error.InputError( _( b"option -R has to be separated from other options (e.g. not " b"-qR) and --repository may only be abbreviated as --repo" ) ) if options[b"debugger"] != req.earlyoptions[b"debugger"]: - raise error.Abort(_(b"option --debugger may not be abbreviated")) + raise error.InputError( + _(b"option --debugger may not be abbreviated") + ) # don't validate --profile/--traceback, which can be enabled from now if options[b"encoding"]: