##// END OF EJS Templates
hooks: allow Unix style environment variables on external Windows hooks...
Matt Harbison -
r38503:e9e61fba default
parent child Browse files
Show More
@@ -886,6 +886,12 b' They contain the type of hook which trig'
886 886 of the hook in the config, respectively. In the example above, this will
887 887 be ``$HG_HOOKTYPE=incoming`` and ``$HG_HOOKNAME=incoming.email``.
888 888
889 .. container:: windows
890
891 Some basic Unix syntax is supported for portability, including ``$VAR``
892 and ``${VAR}`` style variables. To use a literal ``$``, it must be
893 escaped with a back slash or inside of a strong quote.
894
889 895 ``changegroup``
890 896 Run after a changegroup has been added via push, pull or unbundle. The ID of
891 897 the first new changeset is in ``$HG_NODE`` and last is in ``$HG_NODE_LAST``.
@@ -120,8 +120,6 b' def pythonhook(ui, repo, htype, hname, f'
120 120 return r, False
121 121
122 122 def _exthook(ui, repo, htype, name, cmd, args, throw):
123 ui.note(_("running hook %s: %s\n") % (name, cmd))
124
125 123 starttime = util.timer()
126 124 env = {}
127 125
@@ -141,6 +139,12 b' def _exthook(ui, repo, htype, name, cmd,'
141 139 v = stringutil.pprint(v)
142 140 env['HG_' + k.upper()] = v
143 141
142 if pycompat.iswindows:
143 environ = procutil.shellenviron(env)
144 cmd = util.platform.shelltocmdexe(cmd, environ)
145
146 ui.note(_("running hook %s: %s\n") % (name, cmd))
147
144 148 if repo:
145 149 cwd = repo.root
146 150 else:
@@ -478,14 +478,7 b' This is an excuse to test hook with hist'
478 478 1:199b6bb90248 b
479 479 0:6c795aa153cb a
480 480
481 Setup the proper environment variable symbol for the platform, to be subbed
482 into the hook command.
483 #if windows
484 $ NODE="%HG_NODE%"
485 #else
486 $ NODE="\$HG_NODE"
487 #endif
488 $ hg histedit 6c795aa153cb --config hooks.commit="echo commit $NODE" --commands - 2>&1 << EOF | fixbundle
481 $ hg histedit 6c795aa153cb --config hooks.commit='echo commit $HG_NODE' --commands - 2>&1 << EOF | fixbundle
489 482 > pick 199b6bb90248 b
490 483 > fold a1a953ffb4b0 c
491 484 > pick 6c795aa153cb a
@@ -496,8 +489,24 b' into the hook command.'
496 489 1:9599899f62c0 a
497 490 0:79b99e9c8e49 b
498 491
492 Test unix -> windows style variable substitution in external hooks.
493
494 $ cat > $TESTTMP/tmp.hgrc <<'EOF'
495 > [hooks]
496 > pre-add = echo no variables
497 > post-add = echo ran $HG_ARGS, literal \$non-var, 'also $non-var', $HG_RESULT
498 > EOF
499
500 TODO: Windows should output double quotes around "also $non-var"
499 501 $ echo "foo" > amended.txt
500 $ hg add amended.txt
502 $ HGRCPATH=$TESTTMP/tmp.hgrc hg add -v amended.txt
503 running hook pre-add: echo no variables
504 no variables
505 adding amended.txt
506 running hook post-add: echo ran %HG_ARGS%, literal $non-var, 'also $non-var', %HG_RESULT% (windows !)
507 running hook post-add: echo ran $HG_ARGS, literal \$non-var, 'also $non-var', $HG_RESULT (no-windows !)
508 ran add -v amended.txt, literal $non-var, 'also $non-var', 0 (windows !)
509 ran add -v amended.txt, literal $non-var, also $non-var, 0 (no-windows !)
501 510 $ hg ci -q --config extensions.largefiles= --amend -I amended.txt
502 511 The fsmonitor extension is incompatible with the largefiles extension and has been disabled. (fsmonitor !)
503 512
@@ -333,12 +333,7 b' Test rebase interrupted by hooks'
333 333
334 334 $ cp -R a3 hook-pretxncommit
335 335 $ cd hook-pretxncommit
336 #if windows
337 $ NODE="%HG_NODE%"
338 #else
339 $ NODE="\$HG_NODE"
340 #endif
341 $ hg rebase --source 2 --dest 5 --tool internal:other --config "hooks.pretxncommit=hg log -r $NODE | grep \"summary: C\""
336 $ hg rebase --source 2 --dest 5 --tool internal:other --config 'hooks.pretxncommit=hg log -r $HG_NODE | grep "summary: C"'
342 337 rebasing 2:965c486023db "C"
343 338 summary: C
344 339 rebasing 6:a0b2430ebfb8 "F" (tip)
General Comments 0
You need to be logged in to leave comments. Login now