tests/test-hook.t
changeset 13405 682edefe7dbb
parent 13404 31a256ffe9e5
child 13439 d724a69309e0
equal deleted inserted replaced
13404:31a256ffe9e5 13405:682edefe7dbb
     1   $ cp "$TESTDIR"/printenv.py .
       
     2 
       
     3 commit hooks can see env vars
     1 commit hooks can see env vars
     4 
     2 
     5   $ hg init a
     3   $ hg init a
     6   $ cd a
     4   $ cd a
     7   $ echo "[hooks]" > .hg/hgrc
     5   $ echo "[hooks]" > .hg/hgrc
     8   $ echo 'commit = unset HG_LOCAL HG_TAG; python ../printenv.py commit' >> .hg/hgrc
     6   $ echo 'commit = unset HG_LOCAL HG_TAG; python "$TESTDIR"/printenv.py commit' >> .hg/hgrc
     9   $ echo 'commit.b = unset HG_LOCAL HG_TAG; python ../printenv.py commit.b' >> .hg/hgrc
     7   $ echo 'commit.b = unset HG_LOCAL HG_TAG; python "$TESTDIR"/printenv.py commit.b' >> .hg/hgrc
    10   $ echo 'precommit = unset HG_LOCAL HG_NODE HG_TAG; python ../printenv.py precommit' >> .hg/hgrc
     8   $ echo 'precommit = unset HG_LOCAL HG_NODE HG_TAG; python "$TESTDIR"/printenv.py precommit' >> .hg/hgrc
    11   $ echo 'pretxncommit = unset HG_LOCAL HG_TAG; python ../printenv.py pretxncommit' >> .hg/hgrc
     9   $ echo 'pretxncommit = unset HG_LOCAL HG_TAG; python "$TESTDIR"/printenv.py pretxncommit' >> .hg/hgrc
    12   $ echo 'pretxncommit.tip = hg -q tip' >> .hg/hgrc
    10   $ echo 'pretxncommit.tip = hg -q tip' >> .hg/hgrc
    13   $ echo 'pre-identify = python ../printenv.py pre-identify 1' >> .hg/hgrc
    11   $ echo 'pre-identify = python "$TESTDIR"/printenv.py pre-identify 1' >> .hg/hgrc
    14   $ echo 'pre-cat = python ../printenv.py pre-cat' >> .hg/hgrc
    12   $ echo 'pre-cat = python "$TESTDIR"/printenv.py pre-cat' >> .hg/hgrc
    15   $ echo 'post-cat = python ../printenv.py post-cat' >> .hg/hgrc
    13   $ echo 'post-cat = python "$TESTDIR"/printenv.py post-cat' >> .hg/hgrc
    16   $ echo a > a
    14   $ echo a > a
    17   $ hg add a
    15   $ hg add a
    18   $ hg commit -m a
    16   $ hg commit -m a
    19   precommit hook: HG_PARENT1=0000000000000000000000000000000000000000 
    17   precommit hook: HG_PARENT1=0000000000000000000000000000000000000000 
    20   pretxncommit hook: HG_NODE=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b HG_PARENT1=0000000000000000000000000000000000000000 HG_PENDING=$TESTTMP/a 
    18   pretxncommit hook: HG_NODE=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b HG_PARENT1=0000000000000000000000000000000000000000 HG_PENDING=$TESTTMP/a 
    28   $ cd ../b
    26   $ cd ../b
    29 
    27 
    30 changegroup hooks can see env vars
    28 changegroup hooks can see env vars
    31 
    29 
    32   $ echo '[hooks]' > .hg/hgrc
    30   $ echo '[hooks]' > .hg/hgrc
    33   $ echo 'prechangegroup = python ../printenv.py prechangegroup' >> .hg/hgrc
    31   $ echo 'prechangegroup = python "$TESTDIR"/printenv.py prechangegroup' >> .hg/hgrc
    34   $ echo 'changegroup = python ../printenv.py changegroup' >> .hg/hgrc
    32   $ echo 'changegroup = python "$TESTDIR"/printenv.py changegroup' >> .hg/hgrc
    35   $ echo 'incoming = python ../printenv.py incoming' >> .hg/hgrc
    33   $ echo 'incoming = python "$TESTDIR"/printenv.py incoming' >> .hg/hgrc
    36 
    34 
    37 pretxncommit and commit hooks can see both parents of merge
    35 pretxncommit and commit hooks can see both parents of merge
    38 
    36 
    39   $ cd ../a
    37   $ cd ../a
    40   $ echo b >> a
    38   $ echo b >> a
    92   (run 'hg update' to get a working copy)
    90   (run 'hg update' to get a working copy)
    93 
    91 
    94 tag hooks can see env vars
    92 tag hooks can see env vars
    95 
    93 
    96   $ cd ../a
    94   $ cd ../a
    97   $ echo 'pretag = python ../printenv.py pretag' >> .hg/hgrc
    95   $ echo 'pretag = python "$TESTDIR"/printenv.py pretag' >> .hg/hgrc
    98   $ echo 'tag = unset HG_PARENT1 HG_PARENT2; python ../printenv.py tag' >> .hg/hgrc
    96   $ echo 'tag = unset HG_PARENT1 HG_PARENT2; python "$TESTDIR"/printenv.py tag' >> .hg/hgrc
    99   $ hg tag -d '3 0' a
    97   $ hg tag -d '3 0' a
   100   pretag hook: HG_LOCAL=0 HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_TAG=a 
    98   pretag hook: HG_LOCAL=0 HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_TAG=a 
   101   precommit hook: HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2 
    99   precommit hook: HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2 
   102   pretxncommit hook: HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PENDING=$TESTTMP/a 
   100   pretxncommit hook: HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PENDING=$TESTTMP/a 
   103   4:539e4b31b6dc
   101   4:539e4b31b6dc
   108   pretag hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=la 
   106   pretag hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=la 
   109   tag hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=la 
   107   tag hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=la 
   110 
   108 
   111 pretag hook can forbid tagging
   109 pretag hook can forbid tagging
   112 
   110 
   113   $ echo 'pretag.forbid = python ../printenv.py pretag.forbid 1' >> .hg/hgrc
   111   $ echo 'pretag.forbid = python "$TESTDIR"/printenv.py pretag.forbid 1' >> .hg/hgrc
   114   $ hg tag -d '4 0' fa
   112   $ hg tag -d '4 0' fa
   115   pretag hook: HG_LOCAL=0 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fa 
   113   pretag hook: HG_LOCAL=0 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fa 
   116   pretag.forbid hook: HG_LOCAL=0 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fa 
   114   pretag.forbid hook: HG_LOCAL=0 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fa 
   117   abort: pretag.forbid hook exited with status 1
   115   abort: pretag.forbid hook exited with status 1
   118   [255]
   116   [255]
   124 
   122 
   125 pretxncommit hook can see changeset, can roll back txn, changeset no
   123 pretxncommit hook can see changeset, can roll back txn, changeset no
   126 more there after
   124 more there after
   127 
   125 
   128   $ echo 'pretxncommit.forbid0 = hg tip -q' >> .hg/hgrc
   126   $ echo 'pretxncommit.forbid0 = hg tip -q' >> .hg/hgrc
   129   $ echo 'pretxncommit.forbid1 = python ../printenv.py pretxncommit.forbid 1' >> .hg/hgrc
   127   $ echo 'pretxncommit.forbid1 = python "$TESTDIR"/printenv.py pretxncommit.forbid 1' >> .hg/hgrc
   130   $ echo z > z
   128   $ echo z > z
   131   $ hg add z
   129   $ hg add z
   132   $ hg -q tip
   130   $ hg -q tip
   133   4:539e4b31b6dc
   131   4:539e4b31b6dc
   134   $ hg commit -m 'fail' -d '4 0'
   132   $ hg commit -m 'fail' -d '4 0'
   144   $ hg -q tip
   142   $ hg -q tip
   145   4:539e4b31b6dc
   143   4:539e4b31b6dc
   146 
   144 
   147 precommit hook can prevent commit
   145 precommit hook can prevent commit
   148 
   146 
   149   $ echo 'precommit.forbid = python ../printenv.py precommit.forbid 1' >> .hg/hgrc
   147   $ echo 'precommit.forbid = python "$TESTDIR"/printenv.py precommit.forbid 1' >> .hg/hgrc
   150   $ hg commit -m 'fail' -d '4 0'
   148   $ hg commit -m 'fail' -d '4 0'
   151   precommit hook: HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 
   149   precommit hook: HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 
   152   precommit.forbid hook: HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 
   150   precommit.forbid hook: HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 
   153   abort: precommit.forbid hook exited with status 1
   151   abort: precommit.forbid hook exited with status 1
   154   [255]
   152   [255]
   155   $ hg -q tip
   153   $ hg -q tip
   156   4:539e4b31b6dc
   154   4:539e4b31b6dc
   157 
   155 
   158 preupdate hook can prevent update
   156 preupdate hook can prevent update
   159 
   157 
   160   $ echo 'preupdate = python ../printenv.py preupdate' >> .hg/hgrc
   158   $ echo 'preupdate = python "$TESTDIR"/printenv.py preupdate' >> .hg/hgrc
   161   $ hg update 1
   159   $ hg update 1
   162   preupdate hook: HG_PARENT1=ab228980c14d 
   160   preupdate hook: HG_PARENT1=ab228980c14d 
   163   0 files updated, 0 files merged, 2 files removed, 0 files unresolved
   161   0 files updated, 0 files merged, 2 files removed, 0 files unresolved
   164 
   162 
   165 update hook
   163 update hook
   166 
   164 
   167   $ echo 'update = python ../printenv.py update' >> .hg/hgrc
   165   $ echo 'update = python "$TESTDIR"/printenv.py update' >> .hg/hgrc
   168   $ hg update
   166   $ hg update
   169   preupdate hook: HG_PARENT1=539e4b31b6dc 
   167   preupdate hook: HG_PARENT1=539e4b31b6dc 
   170   update hook: HG_ERROR=0 HG_PARENT1=539e4b31b6dc 
   168   update hook: HG_ERROR=0 HG_PARENT1=539e4b31b6dc 
   171   2 files updated, 0 files merged, 0 files removed, 0 files unresolved
   169   2 files updated, 0 files merged, 0 files removed, 0 files unresolved
   172 
   170 
   174 
   172 
   175   $ cd ../b
   173   $ cd ../b
   176   $ hg -q tip
   174   $ hg -q tip
   177   3:07f3376c1e65
   175   3:07f3376c1e65
   178   $ echo '[hooks]' > .hg/hgrc
   176   $ echo '[hooks]' > .hg/hgrc
   179   $ echo 'prechangegroup.forbid = python ../printenv.py prechangegroup.forbid 1' >> .hg/hgrc
   177   $ echo 'prechangegroup.forbid = python "$TESTDIR"/printenv.py prechangegroup.forbid 1' >> .hg/hgrc
   180   $ hg pull ../a
   178   $ hg pull ../a
   181   prechangegroup.forbid hook: HG_SOURCE=pull HG_URL=file:$TESTTMP/a 
   179   prechangegroup.forbid hook: HG_SOURCE=pull HG_URL=file:$TESTTMP/a 
   182   pulling from ../a
   180   pulling from ../a
   183   searching for changes
   181   searching for changes
   184   abort: prechangegroup.forbid hook exited with status 1
   182   abort: prechangegroup.forbid hook exited with status 1
   187 pretxnchangegroup hook can see incoming changes, can roll back txn,
   185 pretxnchangegroup hook can see incoming changes, can roll back txn,
   188 incoming changes no longer there after
   186 incoming changes no longer there after
   189 
   187 
   190   $ echo '[hooks]' > .hg/hgrc
   188   $ echo '[hooks]' > .hg/hgrc
   191   $ echo 'pretxnchangegroup.forbid0 = hg tip -q' >> .hg/hgrc
   189   $ echo 'pretxnchangegroup.forbid0 = hg tip -q' >> .hg/hgrc
   192   $ echo 'pretxnchangegroup.forbid1 = python ../printenv.py pretxnchangegroup.forbid 1' >> .hg/hgrc
   190   $ echo 'pretxnchangegroup.forbid1 = python "$TESTDIR"/printenv.py pretxnchangegroup.forbid 1' >> .hg/hgrc
   193   $ hg pull ../a
   191   $ hg pull ../a
   194   4:539e4b31b6dc
   192   4:539e4b31b6dc
   195   pretxnchangegroup.forbid hook: HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PENDING=$TESTTMP/b HG_SOURCE=pull HG_URL=file:$TESTTMP/a 
   193   pretxnchangegroup.forbid hook: HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PENDING=$TESTTMP/b HG_SOURCE=pull HG_URL=file:$TESTTMP/a 
   196   pulling from ../a
   194   pulling from ../a
   197   searching for changes
   195   searching for changes
   208 
   206 
   209 outgoing hooks can see env vars
   207 outgoing hooks can see env vars
   210 
   208 
   211   $ rm .hg/hgrc
   209   $ rm .hg/hgrc
   212   $ echo '[hooks]' > ../a/.hg/hgrc
   210   $ echo '[hooks]' > ../a/.hg/hgrc
   213   $ echo 'preoutgoing = python ../printenv.py preoutgoing' >> ../a/.hg/hgrc
   211   $ echo 'preoutgoing = python "$TESTDIR"/printenv.py preoutgoing' >> ../a/.hg/hgrc
   214   $ echo 'outgoing = python ../printenv.py outgoing' >> ../a/.hg/hgrc
   212   $ echo 'outgoing = python "$TESTDIR"/printenv.py outgoing' >> ../a/.hg/hgrc
   215   $ hg pull ../a
   213   $ hg pull ../a
   216   preoutgoing hook: HG_SOURCE=pull 
   214   preoutgoing hook: HG_SOURCE=pull 
   217   outgoing hook: HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_SOURCE=pull 
   215   outgoing hook: HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_SOURCE=pull 
   218   pulling from ../a
   216   pulling from ../a
   219   searching for changes
   217   searching for changes
   225   $ hg rollback
   223   $ hg rollback
   226   rolling back to revision 3 (undo pull)
   224   rolling back to revision 3 (undo pull)
   227 
   225 
   228 preoutgoing hook can prevent outgoing changes
   226 preoutgoing hook can prevent outgoing changes
   229 
   227 
   230   $ echo 'preoutgoing.forbid = python ../printenv.py preoutgoing.forbid 1' >> ../a/.hg/hgrc
   228   $ echo 'preoutgoing.forbid = python "$TESTDIR"/printenv.py preoutgoing.forbid 1' >> ../a/.hg/hgrc
   231   $ hg pull ../a
   229   $ hg pull ../a
   232   preoutgoing hook: HG_SOURCE=pull 
   230   preoutgoing hook: HG_SOURCE=pull 
   233   preoutgoing.forbid hook: HG_SOURCE=pull 
   231   preoutgoing.forbid hook: HG_SOURCE=pull 
   234   pulling from ../a
   232   pulling from ../a
   235   searching for changes
   233   searching for changes
   238 
   236 
   239 outgoing hooks work for local clones
   237 outgoing hooks work for local clones
   240 
   238 
   241   $ cd ..
   239   $ cd ..
   242   $ echo '[hooks]' > a/.hg/hgrc
   240   $ echo '[hooks]' > a/.hg/hgrc
   243   $ echo 'preoutgoing = python ../printenv.py preoutgoing' >> a/.hg/hgrc
   241   $ echo 'preoutgoing = python "$TESTDIR"/printenv.py preoutgoing' >> a/.hg/hgrc
   244   $ echo 'outgoing = python ../printenv.py outgoing' >> a/.hg/hgrc
   242   $ echo 'outgoing = python "$TESTDIR"/printenv.py outgoing' >> a/.hg/hgrc
   245   $ hg clone a c
   243   $ hg clone a c
   246   preoutgoing hook: HG_SOURCE=clone 
   244   preoutgoing hook: HG_SOURCE=clone 
   247   outgoing hook: HG_NODE=0000000000000000000000000000000000000000 HG_SOURCE=clone 
   245   outgoing hook: HG_NODE=0000000000000000000000000000000000000000 HG_SOURCE=clone 
   248   updating to branch default
   246   updating to branch default
   249   3 files updated, 0 files merged, 0 files removed, 0 files unresolved
   247   3 files updated, 0 files merged, 0 files removed, 0 files unresolved
   250   $ rm -rf c
   248   $ rm -rf c
   251 
   249 
   252 preoutgoing hook can prevent outgoing changes for local clones
   250 preoutgoing hook can prevent outgoing changes for local clones
   253 
   251 
   254   $ echo 'preoutgoing.forbid = python ../printenv.py preoutgoing.forbid 1' >> a/.hg/hgrc
   252   $ echo 'preoutgoing.forbid = python "$TESTDIR"/printenv.py preoutgoing.forbid 1' >> a/.hg/hgrc
   255   $ hg clone a zzz
   253   $ hg clone a zzz
   256   preoutgoing hook: HG_SOURCE=clone 
   254   preoutgoing hook: HG_SOURCE=clone 
   257   preoutgoing.forbid hook: HG_SOURCE=clone 
   255   preoutgoing.forbid hook: HG_SOURCE=clone 
   258   abort: preoutgoing.forbid hook exited with status 1
   256   abort: preoutgoing.forbid hook exited with status 1
   259   [255]
   257   [255]