# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 1499856010 -19800 # Node ID a6af8560494e30fd6fa4c3fdc0d2355e3e4efe4a # Parent 77c0c36654c8ba7aefc7a70b177f6b3b1075bfb7 commitextras: check the format of the arguments and no internal key is used This patch adds check to make the arguments are passed as KEY=VALUE and no key which is used internally is passed. This patch also adds test for the extension. diff -r 77c0c36654c8 -r a6af8560494e hgext/commitextras.py --- a/hgext/commitextras.py Wed Jul 12 00:23:45 2017 +0530 +++ b/hgext/commitextras.py Wed Jul 12 16:10:10 2017 +0530 @@ -12,6 +12,7 @@ from mercurial.i18n import _ from mercurial import ( commands, + error, extensions, registrar, ) @@ -20,6 +21,19 @@ command = registrar.command(cmdtable) testedwith = 'ships-with-hg-core' +usedinternally = { + 'amend_source', + 'branch', + 'close', + 'histedit_source', + 'topic', + 'rebase_source', + 'intermediate-source', + '__touch-noise__', + 'source', + 'transplant_source', +} + def extsetup(ui): entry = extensions.wrapcommand(commands.table, 'commit', _commit) options = entry[1] @@ -33,7 +47,15 @@ extras = opts.get('extra') if extras: for raw in extras: + if '=' not in raw: + msg = _("unable to parse '%s', should follow " + "KEY=VALUE format") + raise error.Abort(msg % raw) k, v = raw.split('=', 1) + if k in usedinternally: + msg = _("key '%s' is used internally, can't be set " + "manually") + raise error.Abort(msg % k) inneropts['extra'][k] = v return origcommit(*innerpats, **inneropts) diff -r 77c0c36654c8 -r a6af8560494e tests/test-commit.t --- a/tests/test-commit.t Wed Jul 12 00:23:45 2017 +0530 +++ b/tests/test-commit.t Wed Jul 12 16:10:10 2017 +0530 @@ -124,6 +124,24 @@ $ hg tip --template '{date|isodate}\n' | grep '1970' [1] +Using the advanced --extra flag + + $ echo "[extensions]" >> $HGRCPATH + $ echo "commitextras=" >> $HGRCPATH + $ hg status + ? baz + ? quux + $ hg add baz + $ hg commit -m "adding extras" --extra sourcehash=foo --extra oldhash=bar + $ hg log -r . -T '{extras % "{extra}\n"}' + branch=default + oldhash=bar + sourcehash=foo + $ hg add quux + $ hg commit -m "adding internal used extras" --extra amend_source=hash + abort: key 'amend_source' is used internally, can't be set manually + [255] + Make sure we do not obscure unknown requires file entries (issue2649) $ echo foo >> foo