tests/test-hook.t
changeset 12316 4134686b83e1
parent 12156 4c94b6d0fb1c
child 12327 92e30e135581
equal deleted inserted replaced
12315:ca58f6475f1d 12316:4134686b83e1
    68 # test generic hooks
    68 # test generic hooks
    69 
    69 
    70   $ hg id
    70   $ hg id
    71   pre-identify hook: HG_ARGS=id HG_OPTS={'tags': None, 'rev': '', 'num': None, 'branch': None, 'id': None} HG_PATS=[] 
    71   pre-identify hook: HG_ARGS=id HG_OPTS={'tags': None, 'rev': '', 'num': None, 'branch': None, 'id': None} HG_PATS=[] 
    72   warning: pre-identify hook exited with status 1
    72   warning: pre-identify hook exited with status 1
       
    73   [1]
    73   $ hg cat b
    74   $ hg cat b
    74   pre-cat hook: HG_ARGS=cat b HG_OPTS={'rev': '', 'decode': None, 'exclude': [], 'output': '', 'include': []} HG_PATS=['b'] 
    75   pre-cat hook: HG_ARGS=cat b HG_OPTS={'rev': '', 'decode': None, 'exclude': [], 'output': '', 'include': []} HG_PATS=['b'] 
    75   post-cat hook: HG_ARGS=cat b HG_OPTS={'rev': '', 'decode': None, 'exclude': [], 'output': '', 'include': []} HG_PATS=['b'] HG_RESULT=0 
    76   post-cat hook: HG_ARGS=cat b HG_OPTS={'rev': '', 'decode': None, 'exclude': [], 'output': '', 'include': []} HG_PATS=['b'] HG_RESULT=0 
    76   b
    77   b
    77 
    78 
   112   $ echo 'pretag.forbid = python ../printenv.py pretag.forbid 1' >> .hg/hgrc
   113   $ echo 'pretag.forbid = python ../printenv.py pretag.forbid 1' >> .hg/hgrc
   113   $ hg tag -d '4 0' fa
   114   $ hg tag -d '4 0' fa
   114   pretag hook: HG_LOCAL=0 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fa 
   115   pretag hook: HG_LOCAL=0 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fa 
   115   pretag.forbid hook: HG_LOCAL=0 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fa 
   116   pretag.forbid hook: HG_LOCAL=0 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fa 
   116   abort: pretag.forbid hook exited with status 1
   117   abort: pretag.forbid hook exited with status 1
       
   118   [255]
   117   $ hg tag -l fla
   119   $ hg tag -l fla
   118   pretag hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fla 
   120   pretag hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fla 
   119   pretag.forbid hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fla 
   121   pretag.forbid hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fla 
   120   abort: pretag.forbid hook exited with status 1
   122   abort: pretag.forbid hook exited with status 1
       
   123   [255]
   121 
   124 
   122 # pretxncommit hook can see changeset, can roll back txn, changeset
   125 # pretxncommit hook can see changeset, can roll back txn, changeset
   123 # no more there after
   126 # no more there after
   124 
   127 
   125   $ echo 'pretxncommit.forbid0 = hg tip -q' >> .hg/hgrc
   128   $ echo 'pretxncommit.forbid0 = hg tip -q' >> .hg/hgrc
   135   5:6f611f8018c1
   138   5:6f611f8018c1
   136   pretxncommit.forbid hook: HG_NODE=6f611f8018c10e827fee6bd2bc807f937e761567 HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PENDING=$HGTMP/test-hook.t/a 
   139   pretxncommit.forbid hook: HG_NODE=6f611f8018c10e827fee6bd2bc807f937e761567 HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PENDING=$HGTMP/test-hook.t/a 
   137   transaction abort!
   140   transaction abort!
   138   rollback completed
   141   rollback completed
   139   abort: pretxncommit.forbid1 hook exited with status 1
   142   abort: pretxncommit.forbid1 hook exited with status 1
       
   143   [255]
   140   $ hg -q tip
   144   $ hg -q tip
   141   4:539e4b31b6dc
   145   4:539e4b31b6dc
   142 
   146 
   143 # precommit hook can prevent commit
   147 # precommit hook can prevent commit
   144 
   148 
   145   $ echo 'precommit.forbid = python ../printenv.py precommit.forbid 1' >> .hg/hgrc
   149   $ echo 'precommit.forbid = python ../printenv.py precommit.forbid 1' >> .hg/hgrc
   146   $ hg commit -m 'fail' -d '4 0'
   150   $ hg commit -m 'fail' -d '4 0'
   147   precommit hook: HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 
   151   precommit hook: HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 
   148   precommit.forbid hook: HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 
   152   precommit.forbid hook: HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 
   149   abort: precommit.forbid hook exited with status 1
   153   abort: precommit.forbid hook exited with status 1
       
   154   [255]
   150   $ hg -q tip
   155   $ hg -q tip
   151   4:539e4b31b6dc
   156   4:539e4b31b6dc
   152 
   157 
   153 # preupdate hook can prevent update
   158 # preupdate hook can prevent update
   154 
   159 
   175   $ hg pull ../a
   180   $ hg pull ../a
   176   prechangegroup.forbid hook: HG_SOURCE=pull HG_URL=file: 
   181   prechangegroup.forbid hook: HG_SOURCE=pull HG_URL=file: 
   177   pulling from ../a
   182   pulling from ../a
   178   searching for changes
   183   searching for changes
   179   abort: prechangegroup.forbid hook exited with status 1
   184   abort: prechangegroup.forbid hook exited with status 1
       
   185   [255]
   180 
   186 
   181 # pretxnchangegroup hook can see incoming changes, can roll back txn,
   187 # pretxnchangegroup hook can see incoming changes, can roll back txn,
   182 # incoming changes no longer there after
   188 # incoming changes no longer there after
   183 
   189 
   184   $ echo '[hooks]' > .hg/hgrc
   190   $ echo '[hooks]' > .hg/hgrc
   194   adding file changes
   200   adding file changes
   195   added 1 changesets with 1 changes to 1 files
   201   added 1 changesets with 1 changes to 1 files
   196   transaction abort!
   202   transaction abort!
   197   rollback completed
   203   rollback completed
   198   abort: pretxnchangegroup.forbid1 hook exited with status 1
   204   abort: pretxnchangegroup.forbid1 hook exited with status 1
       
   205   [255]
   199   $ hg -q tip
   206   $ hg -q tip
   200   3:07f3376c1e65
   207   3:07f3376c1e65
   201 
   208 
   202 # outgoing hooks can see env vars
   209 # outgoing hooks can see env vars
   203 
   210 
   225   preoutgoing hook: HG_SOURCE=pull 
   232   preoutgoing hook: HG_SOURCE=pull 
   226   preoutgoing.forbid hook: HG_SOURCE=pull 
   233   preoutgoing.forbid hook: HG_SOURCE=pull 
   227   pulling from ../a
   234   pulling from ../a
   228   searching for changes
   235   searching for changes
   229   abort: preoutgoing.forbid hook exited with status 1
   236   abort: preoutgoing.forbid hook exited with status 1
       
   237   [255]
   230 
   238 
   231 # outgoing hooks work for local clones
   239 # outgoing hooks work for local clones
   232 
   240 
   233   $ cd ..
   241   $ cd ..
   234   $ echo '[hooks]' > a/.hg/hgrc
   242   $ echo '[hooks]' > a/.hg/hgrc
   246   $ echo 'preoutgoing.forbid = python ../printenv.py preoutgoing.forbid 1' >> a/.hg/hgrc
   254   $ echo 'preoutgoing.forbid = python ../printenv.py preoutgoing.forbid 1' >> a/.hg/hgrc
   247   $ hg clone a zzz
   255   $ hg clone a zzz
   248   preoutgoing hook: HG_SOURCE=clone 
   256   preoutgoing hook: HG_SOURCE=clone 
   249   preoutgoing.forbid hook: HG_SOURCE=clone 
   257   preoutgoing.forbid hook: HG_SOURCE=clone 
   250   abort: preoutgoing.forbid hook exited with status 1
   258   abort: preoutgoing.forbid hook exited with status 1
       
   259   [255]
   251   $ cd b
   260   $ cd b
   252 
   261 
   253   $ cat > hooktests.py <<EOF
   262   $ cat > hooktests.py <<EOF
   254   > from mercurial import util
   263   > from mercurial import util
   255   > 
   264   > 
   307   $ hg pull ../a
   316   $ hg pull ../a
   308   pulling from ../a
   317   pulling from ../a
   309   searching for changes
   318   searching for changes
   310   error: preoutgoing.abort hook failed: raise abort from hook
   319   error: preoutgoing.abort hook failed: raise abort from hook
   311   abort: raise abort from hook
   320   abort: raise abort from hook
       
   321   [255]
   312 
   322 
   313   $ echo '[hooks]' > ../a/.hg/hgrc
   323   $ echo '[hooks]' > ../a/.hg/hgrc
   314   $ echo 'preoutgoing.fail = python:hooktests.failhook' >> ../a/.hg/hgrc
   324   $ echo 'preoutgoing.fail = python:hooktests.failhook' >> ../a/.hg/hgrc
   315   $ hg pull ../a
   325   $ hg pull ../a
   316   pulling from ../a
   326   pulling from ../a
   317   searching for changes
   327   searching for changes
   318   hook args:
   328   hook args:
   319     hooktype preoutgoing
   329     hooktype preoutgoing
   320     source pull
   330     source pull
   321   abort: preoutgoing.fail hook failed
   331   abort: preoutgoing.fail hook failed
       
   332   [255]
   322 
   333 
   323   $ echo '[hooks]' > ../a/.hg/hgrc
   334   $ echo '[hooks]' > ../a/.hg/hgrc
   324   $ echo 'preoutgoing.uncallable = python:hooktests.uncallable' >> ../a/.hg/hgrc
   335   $ echo 'preoutgoing.uncallable = python:hooktests.uncallable' >> ../a/.hg/hgrc
   325   $ hg pull ../a
   336   $ hg pull ../a
   326   pulling from ../a
   337   pulling from ../a
   327   searching for changes
   338   searching for changes
   328   abort: preoutgoing.uncallable hook is invalid ("hooktests.uncallable" is not callable)
   339   abort: preoutgoing.uncallable hook is invalid ("hooktests.uncallable" is not callable)
       
   340   [255]
   329 
   341 
   330   $ echo '[hooks]' > ../a/.hg/hgrc
   342   $ echo '[hooks]' > ../a/.hg/hgrc
   331   $ echo 'preoutgoing.nohook = python:hooktests.nohook' >> ../a/.hg/hgrc
   343   $ echo 'preoutgoing.nohook = python:hooktests.nohook' >> ../a/.hg/hgrc
   332   $ hg pull ../a
   344   $ hg pull ../a
   333   pulling from ../a
   345   pulling from ../a
   334   searching for changes
   346   searching for changes
   335   abort: preoutgoing.nohook hook is invalid ("hooktests.nohook" is not defined)
   347   abort: preoutgoing.nohook hook is invalid ("hooktests.nohook" is not defined)
       
   348   [255]
   336 
   349 
   337   $ echo '[hooks]' > ../a/.hg/hgrc
   350   $ echo '[hooks]' > ../a/.hg/hgrc
   338   $ echo 'preoutgoing.nomodule = python:nomodule' >> ../a/.hg/hgrc
   351   $ echo 'preoutgoing.nomodule = python:nomodule' >> ../a/.hg/hgrc
   339   $ hg pull ../a
   352   $ hg pull ../a
   340   pulling from ../a
   353   pulling from ../a
   341   searching for changes
   354   searching for changes
   342   abort: preoutgoing.nomodule hook is invalid ("nomodule" not in a module)
   355   abort: preoutgoing.nomodule hook is invalid ("nomodule" not in a module)
       
   356   [255]
   343 
   357 
   344   $ echo '[hooks]' > ../a/.hg/hgrc
   358   $ echo '[hooks]' > ../a/.hg/hgrc
   345   $ echo 'preoutgoing.badmodule = python:nomodule.nowhere' >> ../a/.hg/hgrc
   359   $ echo 'preoutgoing.badmodule = python:nomodule.nowhere' >> ../a/.hg/hgrc
   346   $ hg pull ../a
   360   $ hg pull ../a
   347   pulling from ../a
   361   pulling from ../a
   348   searching for changes
   362   searching for changes
   349   abort: preoutgoing.badmodule hook is invalid (import of "nomodule" failed)
   363   abort: preoutgoing.badmodule hook is invalid (import of "nomodule" failed)
       
   364   [255]
   350 
   365 
   351   $ echo '[hooks]' > ../a/.hg/hgrc
   366   $ echo '[hooks]' > ../a/.hg/hgrc
   352   $ echo 'preoutgoing.unreachable = python:hooktests.container.unreachable' >> ../a/.hg/hgrc
   367   $ echo 'preoutgoing.unreachable = python:hooktests.container.unreachable' >> ../a/.hg/hgrc
   353   $ hg pull ../a
   368   $ hg pull ../a
   354   pulling from ../a
   369   pulling from ../a
   355   searching for changes
   370   searching for changes
   356   abort: preoutgoing.unreachable hook is invalid (import of "hooktests.container" failed)
   371   abort: preoutgoing.unreachable hook is invalid (import of "hooktests.container" failed)
       
   372   [255]
   357 
   373 
   358   $ echo '[hooks]' > ../a/.hg/hgrc
   374   $ echo '[hooks]' > ../a/.hg/hgrc
   359   $ echo 'preoutgoing.pass = python:hooktests.passhook' >> ../a/.hg/hgrc
   375   $ echo 'preoutgoing.pass = python:hooktests.passhook' >> ../a/.hg/hgrc
   360   $ hg pull ../a
   376   $ hg pull ../a
   361   pulling from ../a
   377   pulling from ../a
   424 
   440 
   425   $ cd ../repo
   441   $ cd ../repo
   426   $ hg commit -d '0 0'
   442   $ hg commit -d '0 0'
   427   hook works
   443   hook works
   428   nothing changed
   444   nothing changed
       
   445   [1]
   429 
   446 
   430   $ cd ../../b
   447   $ cd ../../b
   431 
   448 
   432 # make sure --traceback works on hook import failure
   449 # make sure --traceback works on hook import failure
   433 
   450