Mercurial > hg
changeset 46492:7289eac777ec stable
hooks: introduce a `:run-with-plain` option for hooks
This option control if HGPLAIN should be set or not for the hooks. This is the
first step to give user some control of the HGPLAIN setting for they hooks.
Some hooks (eg: consistency checking) deserve to be run with HGPLAIN, some other
(eg: user set visual helper) might need to respect the user config and setting.
So both usage are valid and we need to restore the ability to run -without-
HGPLAIN that got lost in Mercurial 5.7.
This does not offer a way to restore the pre-5.7 behavior yet (respect whatever
HGPLAIN setting from the shell), this will be dealt with in the next changeset.
The option name is a bit verbose because implementing this highlighs the need
for another option: `:run-if-plain`. That would make it possible for some hooks
to be easily disabled if HG PLAIN is set. However such option would be a new
feature, not something introduced to mitigate a behavior change introduced in
5.7, so the `:run-if-plain` option belong to the default branch and is not part
of this series.
Differential Revision: https://phab.mercurial-scm.org/D9981
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 10 Feb 2021 23:21:21 +0100 |
parents | 0760282995cf |
children | b910be772eb9 |
files | mercurial/configitems.py mercurial/helptext/config.txt mercurial/hook.py tests/test-hook.t |
diffstat | 4 files changed, 26 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/configitems.py Wed Feb 10 22:43:16 2021 +0100 +++ b/mercurial/configitems.py Wed Feb 10 23:21:21 2021 +0100 @@ -1315,6 +1315,12 @@ generic=True, ) coreconfigitem( + b'hooks', + b'.*:run-with-plain', + default=True, + generic=True, +) +coreconfigitem( b'hgweb-paths', b'.*', default=list,
--- a/mercurial/helptext/config.txt Wed Feb 10 22:43:16 2021 +0100 +++ b/mercurial/helptext/config.txt Wed Feb 10 23:21:21 2021 +0100 @@ -1027,6 +1027,11 @@ incoming.autobuild = /my/build/hook # force autobuild hook to run before other incoming hooks priority.incoming.autobuild = 1 + ### control HGPLAIN setting when running autobuild hook + # HGPLAIN always set (default from Mercurial 5.7) + incoming.autobuild:run-with-plain = yes + # HGPLAIN never set + incoming.autobuild:run-with-plain = no Most hooks are run with environment variables set that give useful additional information. For each hook below, the environment variables
--- a/mercurial/hook.py Wed Feb 10 22:43:16 2021 +0100 +++ b/mercurial/hook.py Wed Feb 10 23:21:21 2021 +0100 @@ -157,7 +157,12 @@ env[b'HG_PENDING'] = repo.root env[b'HG_HOOKTYPE'] = htype env[b'HG_HOOKNAME'] = name - env[b'HGPLAIN'] = b'1' + + plain = ui.configbool(b'hooks', b'%s:run-with-plain' % name) + if plain: + env[b'HGPLAIN'] = b'1' + else: + env[b'HGPLAIN'] = b'' for k, v in pycompat.iteritems(args): # transaction changes can accumulate MBs of data, so skip it
--- a/tests/test-hook.t Wed Feb 10 22:43:16 2021 +0100 +++ b/tests/test-hook.t Wed Feb 10 23:21:21 2021 +0100 @@ -1407,13 +1407,21 @@ $ cat << EOF >> .hg/hgrc > [hooks] - > pre-version.testing-default=echo '### default ###' plain: \$HGPLAIN + > pre-version.testing-default=echo '### default ###' plain: \${HGPLAIN:-'<unset>'} + > pre-version.testing-yes=echo '### yes #######' plain: \${HGPLAIN:-'<unset>'} + > pre-version.testing-yes:run-with-plain=yes + > pre-version.testing-no=echo '### no ########' plain: \${HGPLAIN:-'<unset>'} + > pre-version.testing-no:run-with-plain=no > EOF $ (unset HGPLAIN; hg version --quiet) ### default ### plain: 1 + ### yes ####### plain: 1 + ### no ######## plain: <unset> Mercurial Distributed SCM (*) (glob) $ HGPLAIN=1 hg version --quiet ### default ### plain: 1 + ### yes ####### plain: 1 + ### no ######## plain: <unset> Mercurial Distributed SCM (*) (glob)