diff mercurial/hook.py @ 38629:38dfd308fe9d

hook: add support for disabling the shell to native command translation I think having it on by default is the right thing to do, but this is an escape hatch if someone has a command that shouldn't be mangled. The inspiration is the priority prefix. The translation does nothing on non Windows platforms, so the default value is selected to avoid printing a useless note by default.
author Matt Harbison <matt_harbison@yahoo.com>
date Sat, 07 Jul 2018 23:38:06 -0400
parents 539f9708b980
children 2009d84f245a
line wrap: on
line diff
--- a/mercurial/hook.py	Sat Jul 07 23:47:49 2018 -0400
+++ b/mercurial/hook.py	Sat Jul 07 23:38:06 2018 -0400
@@ -139,7 +139,9 @@
             v = stringutil.pprint(v)
         env['HG_' + k.upper()] = v
 
-    cmd = procutil.shelltonative(cmd, env)
+    if ui.configbool('hooks', 'tonative.%s' % name, pycompat.iswindows):
+        ui.note(_('converting hook "%s" to native\n') % name)
+        cmd = procutil.shelltonative(cmd, env)
 
     ui.note(_("running hook %s: %s\n") % (name, cmd))
 
@@ -181,9 +183,11 @@
     """return all hooks items ready to be sorted"""
     hooks = {}
     for name, cmd in ui.configitems('hooks', untrusted=_untrusted):
-        if not name.startswith('priority.'):
-            priority = ui.configint('hooks', 'priority.%s' % name, 0)
-            hooks[name] = (-priority, len(hooks), name, cmd)
+        if name.startswith('priority.') or name.startswith('tonative.'):
+            continue
+
+        priority = ui.configint('hooks', 'priority.%s' % name, 0)
+        hooks[name] = (-priority, len(hooks), name, cmd)
     return hooks
 
 _redirect = False