[PATCH 1 of 4] hook: disable the shell to native command translation by default

Matt Harbison mharbison72 at gmail.com
Mon Jul 16 21:31:32 UTC 2018


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1531712769 14400
#      Sun Jul 15 23:46:09 2018 -0400
# Node ID 211dc3185a392d27964fc729c41b7265a98043f6
# Parent  3c569172848d329a81b1420d7cd8a5549b48f25f
hook: disable the shell to native command translation by default

There are other things I want to add like ~ expansion and translating single to
double quotes for cmd.exe.  So off by default is safer.

I'm having second thoughts about the name, but I don't have any better ideas.

diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
--- a/mercurial/help/config.txt
+++ b/mercurial/help/config.txt
@@ -891,16 +891,17 @@ be ``$HG_HOOKTYPE=incoming`` and ``$HG_H
 
 .. container:: windows
 
-  Some basic Unix syntax is supported for portability, including ``$VAR``
+  Some basic Unix syntax can be enabled for portability, including ``$VAR``
   and ``${VAR}`` style variables.  To use a literal ``$``, it must be
-  escaped with a back slash or inside of a strong quote.  This can be
-  disabled by adding a prefix of ``tonative.`` to the hook name on a new
-  line, and setting it to ``False``.  For example::
+  escaped with a back slash or inside of a strong quote.
+
+  This feature is enabled by adding a prefix of ``tonative.`` to the hook
+  name on a new line, and setting it to ``True``.  For example::
 
     [hooks]
     incoming.autobuild = /my/build/hook
-    # disable translation to cmd.exe syntax for autobuild hook
-    tonative.incoming.autobuild = False
+    # enable translation to cmd.exe syntax for autobuild hook
+    tonative.incoming.autobuild = True
 
 ``changegroup``
   Run after a changegroup has been added via push, pull or unbundle.  The ID of
diff --git a/mercurial/hook.py b/mercurial/hook.py
--- a/mercurial/hook.py
+++ b/mercurial/hook.py
@@ -139,7 +139,7 @@ def _exthook(ui, repo, htype, name, cmd,
             v = stringutil.pprint(v)
         env['HG_' + k.upper()] = v
 
-    if ui.configbool('hooks', 'tonative.%s' % name, pycompat.iswindows):
+    if ui.configbool('hooks', 'tonative.%s' % name, False):
         ui.note(_('converting hook "%s" to native\n') % name)
         cmd = procutil.shelltonative(cmd, env)
 
diff --git a/tests/test-bookmarks-pushpull.t b/tests/test-bookmarks-pushpull.t
--- a/tests/test-bookmarks-pushpull.t
+++ b/tests/test-bookmarks-pushpull.t
@@ -194,7 +194,6 @@ delete a remote bookmark
   bundle2-input: part header size: 0
   bundle2-input: end of bundle2 stream
   bundle2-input-bundle: 3 parts total
-  converting hook "txnclose-bookmark.test" to native (windows !)
   running hook txnclose-bookmark.test: sh $TESTTMP/hook.sh
   test-hook-bookmark: W:  0000000000000000000000000000000000000000 -> 
   bundle2-output-bundle: "HG20", 1 parts total
@@ -309,7 +308,6 @@ delete a remote bookmark
   bundle2-input: part header size: 0
   bundle2-input: end of bundle2 stream
   bundle2-input-bundle: 3 parts total
-  converting hook "txnclose-bookmark.test" to native (windows !)
   running hook txnclose-bookmark.test: sh $TESTTMP/hook.sh
   test-hook-bookmark: W:  0000000000000000000000000000000000000000 -> 
   bundle2-output-bundle: "HG20", 0 parts total
diff --git a/tests/test-commit-amend.t b/tests/test-commit-amend.t
--- a/tests/test-commit-amend.t
+++ b/tests/test-commit-amend.t
@@ -205,7 +205,6 @@ at first, test saving last-message.txt
   a
   committing manifest
   committing changelog
-  converting hook "pretxncommit.test-saving-last-message" to native (windows !)
   running hook pretxncommit.test-saving-last-message: false
   transaction abort!
   rollback completed
@@ -231,7 +230,6 @@ at first, test saving last-message.txt
   a
   committing manifest
   committing changelog
-  converting hook "pretxncommit.test-saving-last-message" to native (windows !)
   running hook pretxncommit.test-saving-last-message: false
   transaction abort!
   rollback completed
diff --git a/tests/test-histedit-fold.t b/tests/test-histedit-fold.t
--- a/tests/test-histedit-fold.t
+++ b/tests/test-histedit-fold.t
@@ -478,7 +478,8 @@ This is an excuse to test hook with hist
   1:199b6bb90248 b
   0:6c795aa153cb a
 
-  $ hg histedit 6c795aa153cb --config hooks.commit='echo commit $HG_NODE' --commands - 2>&1 << EOF | fixbundle
+  $ hg histedit 6c795aa153cb --config hooks.commit='echo commit $HG_NODE' --config hooks.tonative.commit=True \
+  >     --commands - 2>&1 << EOF | fixbundle
   > pick 199b6bb90248 b
   > fold a1a953ffb4b0 c
   > pick 6c795aa153cb a
@@ -494,8 +495,8 @@ Test unix -> windows style variable subs
   $ cat > $TESTTMP/tmp.hgrc <<'EOF'
   > [hooks]
   > pre-add = echo no variables
-  > tonative.pre-add = False
   > post-add = echo ran $HG_ARGS, literal \$non-var, 'also $non-var', $HG_RESULT
+  > tonative.post-add = True
   > EOF
 
 TODO: Windows should output double quotes around "also $non-var"
diff --git a/tests/test-keyword.t b/tests/test-keyword.t
--- a/tests/test-keyword.t
+++ b/tests/test-keyword.t
@@ -183,7 +183,6 @@ Commit with several checks
   overwriting a expanding keywords
   updating the branch cache
   committed changeset 1:ef63ca68695bc9495032c6fda1350c71e6d256e9
-  converting hook "commit.test" to native (windows !)
   running hook commit.test: cp a hooktest
   $ hg status
   ? hooktest
diff --git a/tests/test-push-http.t b/tests/test-push-http.t
--- a/tests/test-push-http.t
+++ b/tests/test-push-http.t
@@ -90,13 +90,10 @@ expect success
   remote: adding a revisions
   remote: added 1 changesets with 1 changes to 1 files
   remote: updating the branch cache
-  remote: converting hook "txnclose-phase.test" to native (windows !)
   remote: running hook txnclose-phase.test: sh $TESTTMP/hook.sh
   remote: phase-move: cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b:  draft -> public
-  remote: converting hook "txnclose-phase.test" to native (windows !)
   remote: running hook txnclose-phase.test: sh $TESTTMP/hook.sh
   remote: phase-move: ba677d0156c1196c1a699fa53f390dcfc3ce3872:   -> public
-  remote: converting hook "changegroup" to native (windows !)
   remote: running hook changegroup: sh -c "printenv.py changegroup 0"
   remote: changegroup hook: HG_HOOKNAME=changegroup HG_HOOKTYPE=changegroup HG_NODE=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_NODE_LAST=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_SOURCE=serve HG_TXNID=TXN:$ID$ HG_URL=remote:http:$LOCALIP: (glob)
   % serve errors
@@ -113,13 +110,10 @@ expect success
   remote: adding a revisions
   remote: added 1 changesets with 1 changes to 1 files
   remote: updating the branch cache
-  remote: converting hook "txnclose-phase.test" to native (windows !)
   remote: running hook txnclose-phase.test: sh $TESTTMP/hook.sh
   remote: phase-move: cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b:  draft -> public
-  remote: converting hook "txnclose-phase.test" to native (windows !)
   remote: running hook txnclose-phase.test: sh $TESTTMP/hook.sh
   remote: phase-move: ba677d0156c1196c1a699fa53f390dcfc3ce3872:   -> public
-  remote: converting hook "changegroup" to native (windows !)
   remote: running hook changegroup: sh -c "printenv.py changegroup 0"
   remote: changegroup hook: HG_HOOKNAME=changegroup HG_HOOKTYPE=changegroup HG_NODE=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_NODE_LAST=ba677d0156c1196c1a699fa53f390dcfc3ce3872 HG_SOURCE=serve HG_TXNID=TXN:$ID$ HG_URL=remote:http:$LOCALIP: (glob)
   % serve errors
diff --git a/tests/test-rebase-interruptions.t b/tests/test-rebase-interruptions.t
--- a/tests/test-rebase-interruptions.t
+++ b/tests/test-rebase-interruptions.t
@@ -333,7 +333,8 @@ Test rebase interrupted by hooks
 
   $ cp -R a3 hook-pretxncommit
   $ cd hook-pretxncommit
-  $ hg rebase --source 2 --dest 5 --tool internal:other --config 'hooks.pretxncommit=hg log -r $HG_NODE | grep "summary:     C"'
+  $ hg rebase --source 2 --dest 5 --tool internal:other \
+  >     --config 'hooks.tonative.pretxncommit=True' --config 'hooks.pretxncommit=hg log -r $HG_NODE | grep "summary:     C"'
   rebasing 2:965c486023db "C"
   summary:     C
   rebasing 6:a0b2430ebfb8 "F" (tip)


More information about the Mercurial-devel mailing list