tests/test-hook
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
Thu, 15 Feb 2007 10:15:08 -0200
changeset 4085 719488a98ebe
parent 4070 961ccb615cf7
child 4286 949516072388
permissions -rwxr-xr-x
Fix hg showconfig traceback with values that aren't strings
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
800
ec85f9e6f3b1 Don't use 'set -x', fix exports, sed and hexdump usage for Solaris.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 749
diff changeset
     1
#!/bin/sh
487
2ad41189bee5 Add initial hook support
mpm@selenic.com
parents:
diff changeset
     2
1734
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
     3
# commit hooks can see env vars
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
     4
hg init a
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
     5
cd a
487
2ad41189bee5 Add initial hook support
mpm@selenic.com
parents:
diff changeset
     6
echo "[hooks]" > .hg/hgrc
1734
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
     7
echo 'commit = echo commit hook: n=$HG_NODE p1=$HG_PARENT1 p2=$HG_PARENT2' >> .hg/hgrc
1481
acd1832ebf31 Change test-hook to test multiple hooks
Matt Mackall <mpm@selenic.com>
parents: 814
diff changeset
     8
echo 'commit.b = echo commit hook b' >> .hg/hgrc
1734
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
     9
echo 'precommit = echo precommit hook: p1=$HG_PARENT1 p2=$HG_PARENT2' >> .hg/hgrc
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    10
echo 'pretxncommit = echo pretxncommit hook: n=$HG_NODE p1=$HG_PARENT1 p2=$HG_PARENT2; hg -q tip' >> .hg/hgrc
487
2ad41189bee5 Add initial hook support
mpm@selenic.com
parents:
diff changeset
    11
echo a > a
2ad41189bee5 Add initial hook support
mpm@selenic.com
parents:
diff changeset
    12
hg add a
1933
7544700fd931 Use 'hg ci -d "1000000 0"' in tests to circumvent problem with leading zero.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 1736
diff changeset
    13
hg commit -m a -d "1000000 0"
1734
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    14
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    15
hg clone . ../b
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    16
cd ../b
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    17
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    18
# changegroup hooks can see env vars
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    19
echo '[hooks]' > .hg/hgrc
2673
109a22f5434a hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2283
diff changeset
    20
echo 'prechangegroup = echo prechangegroup hook: u=`echo $HG_URL | sed s,file:.*,file:,`' >> .hg/hgrc
109a22f5434a hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2283
diff changeset
    21
echo 'changegroup = echo changegroup hook: n=$HG_NODE u=`echo $HG_URL | sed s,file:.*,file:,`' >> .hg/hgrc
109a22f5434a hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2283
diff changeset
    22
echo 'incoming = echo incoming hook: n=$HG_NODE u=`echo $HG_URL | sed s,file:.*,file:,`' >> .hg/hgrc
1734
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    23
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    24
# pretxncommit and commit hooks can see both parents of merge
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    25
cd ../a
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    26
echo b >> a
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    27
hg commit -m a1 -d "1 0"
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    28
hg update -C 0
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    29
echo b > b
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    30
hg add b
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    31
hg commit -m b -d '1 0'
2283
e506c14382fd deprecate 'update -m'. use 'merge' instead.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2266
diff changeset
    32
hg merge 1
1734
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    33
hg commit -m merge -d '2 0'
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    34
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    35
cd ../b
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    36
hg pull ../a
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    37
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    38
# tag hooks can see env vars
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    39
cd ../a
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    40
echo 'pretag = echo pretag hook: t=$HG_TAG n=$HG_NODE l=$HG_LOCAL' >> .hg/hgrc
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    41
echo 'tag = echo tag hook: t=$HG_TAG n=$HG_NODE l=$HG_LOCAL' >> .hg/hgrc
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    42
hg tag -d '3 0' a
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    43
hg tag -l la
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    44
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    45
# pretag hook can forbid tagging
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    46
echo 'pretag.forbid = echo pretag.forbid hook; exit 1' >> .hg/hgrc
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    47
hg tag -d '4 0' fa
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    48
hg tag -l fla
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    49
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    50
# pretxncommit hook can see changeset, can roll back txn, changeset
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    51
# no more there after
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    52
echo 'pretxncommit.forbid = echo pretxncommit.forbid hook: tip=`hg -q tip`; exit 1' >> .hg/hgrc
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    53
echo z > z
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    54
hg add z
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    55
hg -q tip
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    56
hg commit -m 'fail' -d '4 0'
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    57
hg -q tip
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    58
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    59
# precommit hook can prevent commit
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    60
echo 'precommit.forbid = echo precommit.forbid hook; exit 1' >> .hg/hgrc
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    61
hg commit -m 'fail' -d '4 0'
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    62
hg -q tip
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    63
2266
3f7692b0ff13 hooks: add preupdate and update hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2227
diff changeset
    64
# preupdate hook can prevent update
3f7692b0ff13 hooks: add preupdate and update hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2227
diff changeset
    65
echo 'preupdate = echo preupdate hook: p1=$HG_PARENT1 p2=$HG_PARENT2' >> .hg/hgrc
3f7692b0ff13 hooks: add preupdate and update hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2227
diff changeset
    66
hg update 1
3f7692b0ff13 hooks: add preupdate and update hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2227
diff changeset
    67
3f7692b0ff13 hooks: add preupdate and update hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2227
diff changeset
    68
# update hook
3f7692b0ff13 hooks: add preupdate and update hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2227
diff changeset
    69
echo 'update = echo update hook: p1=$HG_PARENT1 p2=$HG_PARENT2 err=$HG_ERROR' >> .hg/hgrc
3f7692b0ff13 hooks: add preupdate and update hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2227
diff changeset
    70
hg update
3f7692b0ff13 hooks: add preupdate and update hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2227
diff changeset
    71
1734
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    72
# prechangegroup hook can prevent incoming changes
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    73
cd ../b
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    74
hg -q tip
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    75
echo '[hooks]' > .hg/hgrc
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    76
echo 'prechangegroup.forbid = echo prechangegroup.forbid hook; exit 1' >> .hg/hgrc
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    77
hg pull ../a
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    78
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    79
# pretxnchangegroup hook can see incoming changes, can roll back txn,
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    80
# incoming changes no longer there after
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    81
echo '[hooks]' > .hg/hgrc
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    82
echo 'pretxnchangegroup.forbid = echo pretxnchangegroup.forbid hook: tip=`hg -q tip`; exit 1' >> .hg/hgrc
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    83
hg pull ../a
9488d53233b5 tests for new hooks. fix things i found when writing tests.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1481
diff changeset
    84
hg -q tip
1736
50de0887bbcd add preoutgoing and outgoing hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1734
diff changeset
    85
50de0887bbcd add preoutgoing and outgoing hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1734
diff changeset
    86
# outgoing hooks can see env vars
50de0887bbcd add preoutgoing and outgoing hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1734
diff changeset
    87
rm .hg/hgrc
50de0887bbcd add preoutgoing and outgoing hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1734
diff changeset
    88
echo '[hooks]' > ../a/.hg/hgrc
50de0887bbcd add preoutgoing and outgoing hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1734
diff changeset
    89
echo 'preoutgoing = echo preoutgoing hook: s=$HG_SOURCE' >> ../a/.hg/hgrc
50de0887bbcd add preoutgoing and outgoing hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1734
diff changeset
    90
echo 'outgoing = echo outgoing hook: n=$HG_NODE s=$HG_SOURCE' >> ../a/.hg/hgrc
50de0887bbcd add preoutgoing and outgoing hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1734
diff changeset
    91
hg pull ../a
2227
4f072bb06e89 deprecate undo command, replace with rollback command.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2221
diff changeset
    92
hg rollback
1736
50de0887bbcd add preoutgoing and outgoing hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1734
diff changeset
    93
50de0887bbcd add preoutgoing and outgoing hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1734
diff changeset
    94
# preoutgoing hook can prevent outgoing changes
50de0887bbcd add preoutgoing and outgoing hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1734
diff changeset
    95
echo 'preoutgoing.forbid = echo preoutgoing.forbid hook; exit 1' >> ../a/.hg/hgrc
50de0887bbcd add preoutgoing and outgoing hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1734
diff changeset
    96
hg pull ../a
50de0887bbcd add preoutgoing and outgoing hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1734
diff changeset
    97
2155
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
    98
cat > hooktests.py <<EOF
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
    99
from mercurial import util
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   100
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   101
uncallable = 0
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   102
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   103
def printargs(args):
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   104
    args.pop('ui', None)
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   105
    args.pop('repo', None)
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   106
    a = list(args.items())
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   107
    a.sort()
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   108
    print 'hook args:'
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   109
    for k, v in a:
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   110
       print ' ', k, v
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   111
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   112
def passhook(**args):
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   113
    printargs(args)
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   114
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   115
def failhook(**args):
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   116
    printargs(args)
2221
05b6c13f43c6 reverse sense of return value from python hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2164
diff changeset
   117
    return True
2155
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   118
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   119
class LocalException(Exception):
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   120
    pass
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   121
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   122
def raisehook(**args):
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   123
    raise LocalException('exception from hook')
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   124
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   125
def aborthook(**args):
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   126
    raise util.Abort('raise abort from hook')
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   127
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   128
def brokenhook(**args):
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   129
    return 1 + {}
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   130
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   131
class container:
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   132
    unreachable = 1
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   133
EOF
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   134
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   135
echo '# test python hooks'
2164
cbd458228a96 Applied $PWD fix (changeset 278f9b13c39a) to tests/test-hook, too.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2155
diff changeset
   136
PYTHONPATH="`pwd`:$PYTHONPATH"
2155
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   137
export PYTHONPATH
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   138
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   139
echo '[hooks]' > ../a/.hg/hgrc
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   140
echo 'preoutgoing.broken = python:hooktests.brokenhook' >> ../a/.hg/hgrc
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   141
hg pull ../a 2>&1 | grep 'raised an exception'
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   142
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   143
echo '[hooks]' > ../a/.hg/hgrc
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   144
echo 'preoutgoing.raise = python:hooktests.raisehook' >> ../a/.hg/hgrc
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   145
hg pull ../a 2>&1 | grep 'raised an exception'
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   146
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   147
echo '[hooks]' > ../a/.hg/hgrc
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   148
echo 'preoutgoing.abort = python:hooktests.aborthook' >> ../a/.hg/hgrc
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   149
hg pull ../a
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   150
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   151
echo '[hooks]' > ../a/.hg/hgrc
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   152
echo 'preoutgoing.fail = python:hooktests.failhook' >> ../a/.hg/hgrc
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   153
hg pull ../a
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   154
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   155
echo '[hooks]' > ../a/.hg/hgrc
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   156
echo 'preoutgoing.uncallable = python:hooktests.uncallable' >> ../a/.hg/hgrc
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   157
hg pull ../a
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   158
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   159
echo '[hooks]' > ../a/.hg/hgrc
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   160
echo 'preoutgoing.nohook = python:hooktests.nohook' >> ../a/.hg/hgrc
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   161
hg pull ../a
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   162
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   163
echo '[hooks]' > ../a/.hg/hgrc
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   164
echo 'preoutgoing.nomodule = python:nomodule' >> ../a/.hg/hgrc
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   165
hg pull ../a
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   166
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   167
echo '[hooks]' > ../a/.hg/hgrc
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   168
echo 'preoutgoing.badmodule = python:nomodule.nowhere' >> ../a/.hg/hgrc
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   169
hg pull ../a
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   170
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   171
echo '[hooks]' > ../a/.hg/hgrc
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   172
echo 'preoutgoing.unreachable = python:hooktests.container.unreachable' >> ../a/.hg/hgrc
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   173
hg pull ../a
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   174
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   175
echo '[hooks]' > ../a/.hg/hgrc
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   176
echo 'preoutgoing.pass = python:hooktests.passhook' >> ../a/.hg/hgrc
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   177
hg pull ../a
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   178
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   179
echo '# make sure --traceback works'
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   180
echo '[hooks]' > .hg/hgrc
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   181
echo 'commit.abort = python:hooktests.aborthook' >> .hg/hgrc
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   182
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   183
echo a >> a
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   184
hg --traceback commit -A -m a 2>&1 | grep '^Traceback'
ff255b41b4aa support hooks written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1933
diff changeset
   185
4070
961ccb615cf7 Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2673
diff changeset
   186
cd ..
961ccb615cf7 Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2673
diff changeset
   187
hg init c
961ccb615cf7 Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2673
diff changeset
   188
cd c
961ccb615cf7 Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2673
diff changeset
   189
961ccb615cf7 Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2673
diff changeset
   190
cat > hookext.py <<EOF
961ccb615cf7 Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2673
diff changeset
   191
def autohook(**args):
961ccb615cf7 Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2673
diff changeset
   192
    print "Automatically installed hook"
961ccb615cf7 Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2673
diff changeset
   193
961ccb615cf7 Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2673
diff changeset
   194
def reposetup(ui, repo):
961ccb615cf7 Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2673
diff changeset
   195
    repo.ui.setconfig("hooks", "commit.auto", autohook)
961ccb615cf7 Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2673
diff changeset
   196
EOF
961ccb615cf7 Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2673
diff changeset
   197
echo '[extensions]' >> .hg/hgrc
961ccb615cf7 Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2673
diff changeset
   198
echo 'hookext = hookext.py' >> .hg/hgrc
961ccb615cf7 Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2673
diff changeset
   199
961ccb615cf7 Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2673
diff changeset
   200
touch foo
961ccb615cf7 Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2673
diff changeset
   201
hg add foo
961ccb615cf7 Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2673
diff changeset
   202
hg ci -m 'add foo'
961ccb615cf7 Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2673
diff changeset
   203
echo >> foo
961ccb615cf7 Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2673
diff changeset
   204
hg ci --debug -m 'change foo' | sed -e 's/ at .*>/>/'
961ccb615cf7 Handle functions as the value of a hooks.<name> config variable
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2673
diff changeset
   205
4085
719488a98ebe Fix hg showconfig traceback with values that aren't strings
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4070
diff changeset
   206
hg showconfig hooks | sed -e 's/ at .*>/>/'
719488a98ebe Fix hg showconfig traceback with values that aren't strings
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4070
diff changeset
   207
1736
50de0887bbcd add preoutgoing and outgoing hooks.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 1734
diff changeset
   208
exit 0