comparison tests/test-hook.t @ 30234:34a5f6c66bc5 stable

tests: invoke printenv.py via sh -c for test portability On Windows platform, invoking printenv.py directly via hook is problematic, because: - unless binding between *.py suffix and python runtime, application selector dialog is displayed, and running test is blocked at each printenv.py invocations - it isn't safe to assume binding between *.py suffix and python runtime, because application binding is easily broken For example, installing IDE (VisualStudio with Python Tools, or so) often requires binding between source files and IDE itself. This patch invokes printenv.py via sh -c for test portability. This is a kind of follow up for d19787db6fe0, which eliminated explicit "python" for printenv.py. There are already other 'sh -c "printenv.py"' in *.t files, and this fix should be reasonable. This changes were confirmed in cases below: - without any application binding for *.py suffix - with binding between *.py suffix and VisualStudio This patch also replaces "echo + redirection" style with "heredoc" style, because: - hook command line is parsed by cmd.exe as shell at first, and - single quotation can't quote arguments on cmd.exe, therefore, - "printenv.py foobar" should be quoted by double quotation, but - nested quoting (or tricky escaping) isn't readable
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Sat, 29 Oct 2016 02:44:45 +0900
parents 769aee32fae0
children 59e69ed81776
comparison
equal deleted inserted replaced
30233:3afde791dce1 30234:34a5f6c66bc5
14 > commit = sh -c "HG_LOCAL= HG_TAG= printenv.py commit" 14 > commit = sh -c "HG_LOCAL= HG_TAG= printenv.py commit"
15 > commit.b = sh -c "HG_LOCAL= HG_TAG= printenv.py commit.b" 15 > commit.b = sh -c "HG_LOCAL= HG_TAG= printenv.py commit.b"
16 > precommit = sh -c "HG_LOCAL= HG_NODE= HG_TAG= printenv.py precommit" 16 > precommit = sh -c "HG_LOCAL= HG_NODE= HG_TAG= printenv.py precommit"
17 > pretxncommit = sh -c "HG_LOCAL= HG_TAG= printenv.py pretxncommit" 17 > pretxncommit = sh -c "HG_LOCAL= HG_TAG= printenv.py pretxncommit"
18 > pretxncommit.tip = hg -q tip 18 > pretxncommit.tip = hg -q tip
19 > pre-identify = printenv.py pre-identify 1 19 > pre-identify = sh -c "printenv.py pre-identify 1"
20 > pre-cat = printenv.py pre-cat 20 > pre-cat = sh -c "printenv.py pre-cat"
21 > post-cat = printenv.py post-cat 21 > post-cat = sh -c "printenv.py post-cat"
22 > pretxnopen = sh -c "HG_LOCAL= HG_TAG= printenv.py pretxnopen" 22 > pretxnopen = sh -c "HG_LOCAL= HG_TAG= printenv.py pretxnopen"
23 > pretxnclose = sh -c "HG_LOCAL= HG_TAG= printenv.py pretxnclose" 23 > pretxnclose = sh -c "HG_LOCAL= HG_TAG= printenv.py pretxnclose"
24 > txnclose = sh -c "HG_LOCAL= HG_TAG= printenv.py txnclose" 24 > txnclose = sh -c "HG_LOCAL= HG_TAG= printenv.py txnclose"
25 > txnabort.0 = python:$TESTTMP/txnabort.checkargs.py:showargs 25 > txnabort.0 = python:$TESTTMP/txnabort.checkargs.py:showargs
26 > txnabort.1 = sh -c "HG_LOCAL= HG_TAG= printenv.py txnabort" 26 > txnabort.1 = sh -c "HG_LOCAL= HG_TAG= printenv.py txnabort"
45 45
46 changegroup hooks can see env vars 46 changegroup hooks can see env vars
47 47
48 $ cat > .hg/hgrc <<EOF 48 $ cat > .hg/hgrc <<EOF
49 > [hooks] 49 > [hooks]
50 > prechangegroup = printenv.py prechangegroup 50 > prechangegroup = sh -c "printenv.py prechangegroup"
51 > changegroup = printenv.py changegroup 51 > changegroup = sh -c "printenv.py changegroup"
52 > incoming = printenv.py incoming 52 > incoming = sh -c "printenv.py incoming"
53 > EOF 53 > EOF
54 54
55 pretxncommit and commit hooks can see both parents of merge 55 pretxncommit and commit hooks can see both parents of merge
56 56
57 $ cd ../a 57 $ cd ../a
120 120
121 tag hooks can see env vars 121 tag hooks can see env vars
122 122
123 $ cd ../a 123 $ cd ../a
124 $ cat >> .hg/hgrc <<EOF 124 $ cat >> .hg/hgrc <<EOF
125 > pretag = printenv.py pretag 125 > pretag = sh -c "printenv.py pretag"
126 > tag = sh -c "HG_PARENT1= HG_PARENT2= printenv.py tag" 126 > tag = sh -c "HG_PARENT1= HG_PARENT2= printenv.py tag"
127 > EOF 127 > EOF
128 $ hg tag -d '3 0' a 128 $ hg tag -d '3 0' a
129 pretag hook: HG_LOCAL=0 HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_TAG=a 129 pretag hook: HG_LOCAL=0 HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_TAG=a
130 precommit hook: HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2 130 precommit hook: HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2
140 pretag hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=la 140 pretag hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=la
141 tag hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=la 141 tag hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=la
142 142
143 pretag hook can forbid tagging 143 pretag hook can forbid tagging
144 144
145 $ echo "pretag.forbid = printenv.py pretag.forbid 1" >> .hg/hgrc 145 $ cat >> .hg/hgrc <<EOF
146 > pretag.forbid = sh -c "printenv.py pretag.forbid 1"
147 > EOF
146 $ hg tag -d '4 0' fa 148 $ hg tag -d '4 0' fa
147 pretag hook: HG_LOCAL=0 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fa 149 pretag hook: HG_LOCAL=0 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fa
148 pretag.forbid hook: HG_LOCAL=0 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fa 150 pretag.forbid hook: HG_LOCAL=0 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fa
149 abort: pretag.forbid hook exited with status 1 151 abort: pretag.forbid hook exited with status 1
150 [255] 152 [255]
155 [255] 157 [255]
156 158
157 pretxncommit hook can see changeset, can roll back txn, changeset no 159 pretxncommit hook can see changeset, can roll back txn, changeset no
158 more there after 160 more there after
159 161
160 $ echo "pretxncommit.forbid0 = hg tip -q" >> .hg/hgrc 162 $ cat >> .hg/hgrc <<EOF
161 $ echo "pretxncommit.forbid1 = printenv.py pretxncommit.forbid 1" >> .hg/hgrc 163 > pretxncommit.forbid0 = sh -c "hg tip -q"
164 > pretxncommit.forbid1 = sh -c "printenv.py pretxncommit.forbid 1"
165 > EOF
162 $ echo z > z 166 $ echo z > z
163 $ hg add z 167 $ hg add z
164 $ hg -q tip 168 $ hg -q tip
165 4:539e4b31b6dc 169 4:539e4b31b6dc
166 $ hg commit -m 'fail' -d '4 0' 170 $ hg commit -m 'fail' -d '4 0'
194 undo.phaseroots 198 undo.phaseroots
195 199
196 200
197 precommit hook can prevent commit 201 precommit hook can prevent commit
198 202
199 $ echo "precommit.forbid = printenv.py precommit.forbid 1" >> .hg/hgrc 203 $ cat >> .hg/hgrc <<EOF
204 > precommit.forbid = sh -c "printenv.py precommit.forbid 1"
205 > EOF
200 $ hg commit -m 'fail' -d '4 0' 206 $ hg commit -m 'fail' -d '4 0'
201 precommit hook: HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 207 precommit hook: HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
202 precommit.forbid hook: HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 208 precommit.forbid hook: HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
203 abort: precommit.forbid hook exited with status 1 209 abort: precommit.forbid hook exited with status 1
204 [255] 210 [255]
205 $ hg -q tip 211 $ hg -q tip
206 4:539e4b31b6dc 212 4:539e4b31b6dc
207 213
208 preupdate hook can prevent update 214 preupdate hook can prevent update
209 215
210 $ echo "preupdate = printenv.py preupdate" >> .hg/hgrc 216 $ cat >> .hg/hgrc <<EOF
217 > preupdate = sh -c "printenv.py preupdate"
218 > EOF
211 $ hg update 1 219 $ hg update 1
212 preupdate hook: HG_PARENT1=ab228980c14d 220 preupdate hook: HG_PARENT1=ab228980c14d
213 0 files updated, 0 files merged, 2 files removed, 0 files unresolved 221 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
214 222
215 update hook 223 update hook
216 224
217 $ echo "update = printenv.py update" >> .hg/hgrc 225 $ cat >> .hg/hgrc <<EOF
226 > update = sh -c "printenv.py update"
227 > EOF
218 $ hg update 228 $ hg update
219 preupdate hook: HG_PARENT1=539e4b31b6dc 229 preupdate hook: HG_PARENT1=539e4b31b6dc
220 update hook: HG_ERROR=0 HG_PARENT1=539e4b31b6dc 230 update hook: HG_ERROR=0 HG_PARENT1=539e4b31b6dc
221 2 files updated, 0 files merged, 0 files removed, 0 files unresolved 231 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
222 232
223 pushkey hook 233 pushkey hook
224 234
225 $ echo "pushkey = printenv.py pushkey" >> .hg/hgrc 235 $ cat >> .hg/hgrc <<EOF
236 > pushkey = sh -c "printenv.py pushkey"
237 > EOF
226 $ cd ../b 238 $ cd ../b
227 $ hg bookmark -r null foo 239 $ hg bookmark -r null foo
228 $ hg push -B foo ../a 240 $ hg push -B foo ../a
229 pushing to ../a 241 pushing to ../a
230 searching for changes 242 searching for changes
237 [1] 249 [1]
238 $ cd ../a 250 $ cd ../a
239 251
240 listkeys hook 252 listkeys hook
241 253
242 $ echo "listkeys = printenv.py listkeys" >> .hg/hgrc 254 $ cat >> .hg/hgrc <<EOF
255 > listkeys = sh -c "printenv.py listkeys"
256 > EOF
243 $ hg bookmark -r null bar 257 $ hg bookmark -r null bar
244 pretxnopen hook: HG_TXNID=TXN:* HG_TXNNAME=bookmark (glob) 258 pretxnopen hook: HG_TXNID=TXN:* HG_TXNNAME=bookmark (glob)
245 pretxnclose hook: HG_BOOKMARK_MOVED=1 HG_PENDING=$TESTTMP/a HG_TXNID=TXN:* HG_TXNNAME=bookmark (glob) 259 pretxnclose hook: HG_BOOKMARK_MOVED=1 HG_PENDING=$TESTTMP/a HG_TXNID=TXN:* HG_TXNNAME=bookmark (glob)
246 txnclose hook: HG_BOOKMARK_MOVED=1 HG_TXNID=TXN:* HG_TXNNAME=bookmark (glob) 260 txnclose hook: HG_BOOKMARK_MOVED=1 HG_TXNID=TXN:* HG_TXNNAME=bookmark (glob)
247 $ cd ../b 261 $ cd ../b
253 adding remote bookmark bar 267 adding remote bookmark bar
254 $ cd ../a 268 $ cd ../a
255 269
256 test that prepushkey can prevent incoming keys 270 test that prepushkey can prevent incoming keys
257 271
258 $ echo "prepushkey = printenv.py prepushkey.forbid 1" >> .hg/hgrc 272 $ cat >> .hg/hgrc <<EOF
273 > prepushkey = sh -c "printenv.py prepushkey.forbid 1"
274 > EOF
259 $ cd ../b 275 $ cd ../b
260 $ hg bookmark -r null baz 276 $ hg bookmark -r null baz
261 $ hg push -B baz ../a 277 $ hg push -B baz ../a
262 pushing to ../a 278 pushing to ../a
263 searching for changes 279 searching for changes
271 [255] 287 [255]
272 $ cd ../a 288 $ cd ../a
273 289
274 test that prelistkeys can prevent listing keys 290 test that prelistkeys can prevent listing keys
275 291
276 $ echo "prelistkeys = printenv.py prelistkeys.forbid 1" >> .hg/hgrc 292 $ cat >> .hg/hgrc <<EOF
293 > prelistkeys = sh -c "printenv.py prelistkeys.forbid 1"
294 > EOF
277 $ hg bookmark -r null quux 295 $ hg bookmark -r null quux
278 pretxnopen hook: HG_TXNID=TXN:* HG_TXNNAME=bookmark (glob) 296 pretxnopen hook: HG_TXNID=TXN:* HG_TXNNAME=bookmark (glob)
279 pretxnclose hook: HG_BOOKMARK_MOVED=1 HG_PENDING=$TESTTMP/a HG_TXNID=TXN:* HG_TXNNAME=bookmark (glob) 297 pretxnclose hook: HG_BOOKMARK_MOVED=1 HG_PENDING=$TESTTMP/a HG_TXNID=TXN:* HG_TXNNAME=bookmark (glob)
280 txnclose hook: HG_BOOKMARK_MOVED=1 HG_TXNID=TXN:* HG_TXNNAME=bookmark (glob) 298 txnclose hook: HG_BOOKMARK_MOVED=1 HG_TXNID=TXN:* HG_TXNNAME=bookmark (glob)
281 $ cd ../b 299 $ cd ../b
292 $ cd ../b 310 $ cd ../b
293 $ hg -q tip 311 $ hg -q tip
294 3:07f3376c1e65 312 3:07f3376c1e65
295 $ cat > .hg/hgrc <<EOF 313 $ cat > .hg/hgrc <<EOF
296 > [hooks] 314 > [hooks]
297 > prechangegroup.forbid = printenv.py prechangegroup.forbid 1 315 > prechangegroup.forbid = sh -c "printenv.py prechangegroup.forbid 1"
298 > EOF 316 > EOF
299 $ hg pull ../a 317 $ hg pull ../a
300 pulling from ../a 318 pulling from ../a
301 searching for changes 319 searching for changes
302 prechangegroup.forbid hook: HG_SOURCE=pull HG_TXNID=TXN:* HG_URL=file:$TESTTMP/a (glob) 320 prechangegroup.forbid hook: HG_SOURCE=pull HG_TXNID=TXN:* HG_URL=file:$TESTTMP/a (glob)
307 incoming changes no longer there after 325 incoming changes no longer there after
308 326
309 $ cat > .hg/hgrc <<EOF 327 $ cat > .hg/hgrc <<EOF
310 > [hooks] 328 > [hooks]
311 > pretxnchangegroup.forbid0 = hg tip -q 329 > pretxnchangegroup.forbid0 = hg tip -q
312 > pretxnchangegroup.forbid1 = printenv.py pretxnchangegroup.forbid 1 330 > pretxnchangegroup.forbid1 = sh -c "printenv.py pretxnchangegroup.forbid 1"
313 > EOF 331 > EOF
314 $ hg pull ../a 332 $ hg pull ../a
315 pulling from ../a 333 pulling from ../a
316 searching for changes 334 searching for changes
317 adding changesets 335 adding changesets
330 outgoing hooks can see env vars 348 outgoing hooks can see env vars
331 349
332 $ rm .hg/hgrc 350 $ rm .hg/hgrc
333 $ cat > ../a/.hg/hgrc <<EOF 351 $ cat > ../a/.hg/hgrc <<EOF
334 > [hooks] 352 > [hooks]
335 > preoutgoing = printenv.py preoutgoing 353 > preoutgoing = sh -c "printenv.py preoutgoing"
336 > outgoing = printenv.py outgoing 354 > outgoing = sh -c "printenv.py outgoing"
337 > EOF 355 > EOF
338 $ hg pull ../a 356 $ hg pull ../a
339 pulling from ../a 357 pulling from ../a
340 searching for changes 358 searching for changes
341 preoutgoing hook: HG_SOURCE=pull 359 preoutgoing hook: HG_SOURCE=pull
349 $ hg rollback 367 $ hg rollback
350 repository tip rolled back to revision 3 (undo pull) 368 repository tip rolled back to revision 3 (undo pull)
351 369
352 preoutgoing hook can prevent outgoing changes 370 preoutgoing hook can prevent outgoing changes
353 371
354 $ echo "preoutgoing.forbid = printenv.py preoutgoing.forbid 1" >> ../a/.hg/hgrc 372 $ cat >> ../a/.hg/hgrc <<EOF
373 > preoutgoing.forbid = sh -c "printenv.py preoutgoing.forbid 1"
374 > EOF
355 $ hg pull ../a 375 $ hg pull ../a
356 pulling from ../a 376 pulling from ../a
357 searching for changes 377 searching for changes
358 preoutgoing hook: HG_SOURCE=pull 378 preoutgoing hook: HG_SOURCE=pull
359 preoutgoing.forbid hook: HG_SOURCE=pull 379 preoutgoing.forbid hook: HG_SOURCE=pull
363 outgoing hooks work for local clones 383 outgoing hooks work for local clones
364 384
365 $ cd .. 385 $ cd ..
366 $ cat > a/.hg/hgrc <<EOF 386 $ cat > a/.hg/hgrc <<EOF
367 > [hooks] 387 > [hooks]
368 > preoutgoing = printenv.py preoutgoing 388 > preoutgoing = sh -c "printenv.py preoutgoing"
369 > outgoing = printenv.py outgoing 389 > outgoing = sh -c "printenv.py outgoing"
370 > EOF 390 > EOF
371 $ hg clone a c 391 $ hg clone a c
372 preoutgoing hook: HG_SOURCE=clone 392 preoutgoing hook: HG_SOURCE=clone
373 outgoing hook: HG_NODE=0000000000000000000000000000000000000000 HG_SOURCE=clone 393 outgoing hook: HG_NODE=0000000000000000000000000000000000000000 HG_SOURCE=clone
374 updating to branch default 394 updating to branch default
375 3 files updated, 0 files merged, 0 files removed, 0 files unresolved 395 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
376 $ rm -rf c 396 $ rm -rf c
377 397
378 preoutgoing hook can prevent outgoing changes for local clones 398 preoutgoing hook can prevent outgoing changes for local clones
379 399
380 $ echo "preoutgoing.forbid = printenv.py preoutgoing.forbid 1" >> a/.hg/hgrc 400 $ cat >> a/.hg/hgrc <<EOF
401 > preoutgoing.forbid = sh -c "printenv.py preoutgoing.forbid 1"
402 > EOF
381 $ hg clone a zzz 403 $ hg clone a zzz
382 preoutgoing hook: HG_SOURCE=clone 404 preoutgoing hook: HG_SOURCE=clone
383 preoutgoing.forbid hook: HG_SOURCE=clone 405 preoutgoing.forbid hook: HG_SOURCE=clone
384 abort: preoutgoing.forbid hook exited with status 1 406 abort: preoutgoing.forbid hook exited with status 1
385 [255] 407 [255]
748 This also creates the `to` repo for the next test block. 770 This also creates the `to` repo for the next test block.
749 771
750 $ cd .. 772 $ cd ..
751 $ cat << EOF >> hgrc-with-post-init-hook 773 $ cat << EOF >> hgrc-with-post-init-hook
752 > [hooks] 774 > [hooks]
753 > post-init = printenv.py post-init 775 > post-init = sh -c "printenv.py post-init"
754 > EOF 776 > EOF
755 $ HGRCPATH=hgrc-with-post-init-hook hg init to 777 $ HGRCPATH=hgrc-with-post-init-hook hg init to
756 post-init hook: HG_ARGS=init to HG_OPTS={'insecure': None, 'remotecmd': '', 'ssh': ''} HG_PATS=['to'] HG_RESULT=0 778 post-init hook: HG_ARGS=init to HG_OPTS={'insecure': None, 'remotecmd': '', 'ssh': ''} HG_PATS=['to'] HG_RESULT=0
757 779
758 new commits must be visible in pretxnchangegroup (issue3428) 780 new commits must be visible in pretxnchangegroup (issue3428)