tests/test-hook.t
changeset 36109 361276a36d49
parent 35811 e35320ce8043
child 37415 c2c8962a9465
equal deleted inserted replaced
36108:c4146cf4dd20 36109:361276a36d49
   415   > uncallable = 0
   415   > uncallable = 0
   416   > 
   416   > 
   417   > def printargs(ui, args):
   417   > def printargs(ui, args):
   418   >     a = list(args.items())
   418   >     a = list(args.items())
   419   >     a.sort()
   419   >     a.sort()
   420   >     ui.write('hook args:\n')
   420   >     ui.write(b'hook args:\n')
   421   >     for k, v in a:
   421   >     for k, v in a:
   422   >        ui.write('  %s %s\n' % (k, v))
   422   >        ui.write(b'  %s %s\n' % (k, v))
   423   > 
   423   > 
   424   > def passhook(ui, repo, **args):
   424   > def passhook(ui, repo, **args):
   425   >     printargs(ui, args)
   425   >     printargs(ui, args)
   426   > 
   426   > 
   427   > def failhook(ui, repo, **args):
   427   > def failhook(ui, repo, **args):
   430   > 
   430   > 
   431   > class LocalException(Exception):
   431   > class LocalException(Exception):
   432   >     pass
   432   >     pass
   433   > 
   433   > 
   434   > def raisehook(**args):
   434   > def raisehook(**args):
   435   >     raise LocalException('exception from hook')
   435   >     raise LocalException(b'exception from hook')
   436   > 
   436   > 
   437   > def aborthook(**args):
   437   > def aborthook(**args):
   438   >     raise error.Abort('raise abort from hook')
   438   >     raise error.Abort(b'raise abort from hook')
   439   > 
   439   > 
   440   > def brokenhook(**args):
   440   > def brokenhook(**args):
   441   >     return 1 + {}
   441   >     return 1 + {}
   442   > 
   442   > 
   443   > def verbosehook(ui, **args):
   443   > def verbosehook(ui, **args):
   444   >     ui.note('verbose output from hook\n')
   444   >     ui.note(b'verbose output from hook\n')
   445   > 
   445   > 
   446   > def printtags(ui, repo, **args):
   446   > def printtags(ui, repo, **args):
   447   >     ui.write('%s\n' % sorted(repo.tags()))
   447   >     ui.write(b'%s\n' % sorted(repo.tags()))
   448   > 
   448   > 
   449   > class container:
   449   > class container:
   450   >     unreachable = 1
   450   >     unreachable = 1
   451   > EOF
   451   > EOF
   452 
   452 
   665   $ mkdir hooks
   665   $ mkdir hooks
   666 
   666 
   667   $ cd hooks
   667   $ cd hooks
   668   $ cat > testhooks.py <<EOF
   668   $ cat > testhooks.py <<EOF
   669   > def testhook(ui, **args):
   669   > def testhook(ui, **args):
   670   >     ui.write('hook works\n')
   670   >     ui.write(b'hook works\n')
   671   > EOF
   671   > EOF
   672   $ echo '[hooks]' > ../repo/.hg/hgrc
   672   $ echo '[hooks]' > ../repo/.hg/hgrc
   673   $ echo "pre-commit.test = python:`pwd`/testhooks.py:testhook" >> ../repo/.hg/hgrc
   673   $ echo "pre-commit.test = python:`pwd`/testhooks.py:testhook" >> ../repo/.hg/hgrc
   674 
   674 
   675   $ cd ../repo
   675   $ cd ../repo
   884   $ cat << EOF > $TESTTMP/untrusted.py
   884   $ cat << EOF > $TESTTMP/untrusted.py
   885   > from mercurial import scmutil, util
   885   > from mercurial import scmutil, util
   886   > def uisetup(ui):
   886   > def uisetup(ui):
   887   >     class untrustedui(ui.__class__):
   887   >     class untrustedui(ui.__class__):
   888   >         def _trusted(self, fp, f):
   888   >         def _trusted(self, fp, f):
   889   >             if util.normpath(fp.name).endswith('untrusted/.hg/hgrc'):
   889   >             if util.normpath(fp.name).endswith(b'untrusted/.hg/hgrc'):
   890   >                 return False
   890   >                 return False
   891   >             return super(untrustedui, self)._trusted(fp, f)
   891   >             return super(untrustedui, self)._trusted(fp, f)
   892   >     ui.__class__ = untrustedui
   892   >     ui.__class__ = untrustedui
   893   > EOF
   893   > EOF
   894   $ cat << EOF >> $HGRCPATH
   894   $ cat << EOF >> $HGRCPATH