1 #!/bin/sh |
1 #!/bin/sh |
|
2 |
|
3 cp "$TESTDIR"/printenv.py . |
2 |
4 |
3 # commit hooks can see env vars |
5 # commit hooks can see env vars |
4 hg init a |
6 hg init a |
5 cd a |
7 cd a |
6 echo "[hooks]" > .hg/hgrc |
8 echo "[hooks]" > .hg/hgrc |
7 echo 'commit = echo commit hook: n=$HG_NODE p1=$HG_PARENT1 p2=$HG_PARENT2' >> .hg/hgrc |
9 echo 'commit = python ../printenv.py commit' >> .hg/hgrc |
8 echo 'commit.b = echo commit hook b' >> .hg/hgrc |
10 echo 'commit.b = python ../printenv.py commit.b' >> .hg/hgrc |
9 echo 'precommit = echo precommit hook: p1=$HG_PARENT1 p2=$HG_PARENT2' >> .hg/hgrc |
11 echo 'precommit = python ../printenv.py precommit' >> .hg/hgrc |
10 echo 'pretxncommit = echo pretxncommit hook: n=$HG_NODE p1=$HG_PARENT1 p2=$HG_PARENT2; hg -q tip' >> .hg/hgrc |
12 echo 'pretxncommit = python ../printenv.py pretxncommit' >> .hg/hgrc |
|
13 echo 'pretxncommit.tip = hg -q tip' >> .hg/hgrc |
11 echo a > a |
14 echo a > a |
12 hg add a |
15 hg add a |
13 hg commit -m a -d "1000000 0" |
16 hg commit -m a -d "1000000 0" |
14 |
17 |
15 hg clone . ../b |
18 hg clone . ../b |
16 cd ../b |
19 cd ../b |
17 |
20 |
18 # changegroup hooks can see env vars |
21 # changegroup hooks can see env vars |
19 echo '[hooks]' > .hg/hgrc |
22 echo '[hooks]' > .hg/hgrc |
20 echo 'prechangegroup = echo prechangegroup hook: u=`echo $HG_URL | sed s,file:.*,file:,`' >> .hg/hgrc |
23 echo 'prechangegroup = python ../printenv.py prechangegroup' >> .hg/hgrc |
21 echo 'changegroup = echo changegroup hook: n=$HG_NODE u=`echo $HG_URL | sed s,file:.*,file:,`' >> .hg/hgrc |
24 echo 'changegroup = python ../printenv.py changegroup' >> .hg/hgrc |
22 echo 'incoming = echo incoming hook: n=$HG_NODE u=`echo $HG_URL | sed s,file:.*,file:,`' >> .hg/hgrc |
25 echo 'incoming = python ../printenv.py incoming' >> .hg/hgrc |
23 |
26 |
24 # pretxncommit and commit hooks can see both parents of merge |
27 # pretxncommit and commit hooks can see both parents of merge |
25 cd ../a |
28 cd ../a |
26 echo b >> a |
29 echo b >> a |
27 hg commit -m a1 -d "1 0" |
30 hg commit -m a1 -d "1 0" |
35 cd ../b |
38 cd ../b |
36 hg pull ../a |
39 hg pull ../a |
37 |
40 |
38 # tag hooks can see env vars |
41 # tag hooks can see env vars |
39 cd ../a |
42 cd ../a |
40 echo 'pretag = echo pretag hook: t=$HG_TAG n=$HG_NODE l=$HG_LOCAL' >> .hg/hgrc |
43 echo 'pretag = python ../printenv.py pretag' >> .hg/hgrc |
41 echo 'tag = echo tag hook: t=$HG_TAG n=$HG_NODE l=$HG_LOCAL' >> .hg/hgrc |
44 echo 'tag = python ../printenv.py tag' >> .hg/hgrc |
42 hg tag -d '3 0' a |
45 hg tag -d '3 0' a |
43 hg tag -l la |
46 hg tag -l la |
44 |
47 |
45 # pretag hook can forbid tagging |
48 # pretag hook can forbid tagging |
46 echo 'pretag.forbid = echo pretag.forbid hook; exit 1' >> .hg/hgrc |
49 echo 'pretag.forbid = python ../printenv.py pretag.forbid 1' >> .hg/hgrc |
47 hg tag -d '4 0' fa |
50 hg tag -d '4 0' fa |
48 hg tag -l fla |
51 hg tag -l fla |
49 |
52 |
50 # pretxncommit hook can see changeset, can roll back txn, changeset |
53 # pretxncommit hook can see changeset, can roll back txn, changeset |
51 # no more there after |
54 # no more there after |
52 echo 'pretxncommit.forbid = echo pretxncommit.forbid hook: tip=`hg -q tip`; exit 1' >> .hg/hgrc |
55 echo 'pretxncommit.forbid0 = hg tip -q' >> .hg/hgrc |
|
56 echo 'pretxncommit.forbid1 = python ../printenv.py pretxncommit.forbid 1' >> .hg/hgrc |
53 echo z > z |
57 echo z > z |
54 hg add z |
58 hg add z |
55 hg -q tip |
59 hg -q tip |
56 hg commit -m 'fail' -d '4 0' |
60 hg commit -m 'fail' -d '4 0' |
57 hg -q tip |
61 hg -q tip |
58 |
62 |
59 # precommit hook can prevent commit |
63 # precommit hook can prevent commit |
60 echo 'precommit.forbid = echo precommit.forbid hook; exit 1' >> .hg/hgrc |
64 echo 'precommit.forbid = python ../printenv.py precommit.forbid 1' >> .hg/hgrc |
61 hg commit -m 'fail' -d '4 0' |
65 hg commit -m 'fail' -d '4 0' |
62 hg -q tip |
66 hg -q tip |
63 |
67 |
64 # preupdate hook can prevent update |
68 # preupdate hook can prevent update |
65 echo 'preupdate = echo preupdate hook: p1=$HG_PARENT1 p2=$HG_PARENT2' >> .hg/hgrc |
69 echo 'preupdate = python ../printenv.py preupdate' >> .hg/hgrc |
66 hg update 1 |
70 hg update 1 |
67 |
71 |
68 # update hook |
72 # update hook |
69 echo 'update = echo update hook: p1=$HG_PARENT1 p2=$HG_PARENT2 err=$HG_ERROR' >> .hg/hgrc |
73 echo 'update = python ../printenv.py update' >> .hg/hgrc |
70 hg update |
74 hg update |
71 |
75 |
72 # prechangegroup hook can prevent incoming changes |
76 # prechangegroup hook can prevent incoming changes |
73 cd ../b |
77 cd ../b |
74 hg -q tip |
78 hg -q tip |
75 echo '[hooks]' > .hg/hgrc |
79 echo '[hooks]' > .hg/hgrc |
76 echo 'prechangegroup.forbid = echo prechangegroup.forbid hook; exit 1' >> .hg/hgrc |
80 echo 'prechangegroup.forbid = python ../printenv.py prechangegroup.forbid 1' >> .hg/hgrc |
77 hg pull ../a |
81 hg pull ../a |
78 |
82 |
79 # pretxnchangegroup hook can see incoming changes, can roll back txn, |
83 # pretxnchangegroup hook can see incoming changes, can roll back txn, |
80 # incoming changes no longer there after |
84 # incoming changes no longer there after |
81 echo '[hooks]' > .hg/hgrc |
85 echo '[hooks]' > .hg/hgrc |
82 echo 'pretxnchangegroup.forbid = echo pretxnchangegroup.forbid hook: tip=`hg -q tip`; exit 1' >> .hg/hgrc |
86 echo 'pretxnchangegroup.forbid0 = hg tip -q' >> .hg/hgrc |
|
87 echo 'pretxnchangegroup.forbid1 = python ../printenv.py pretxnchangegroup.forbid 1' >> .hg/hgrc |
83 hg pull ../a |
88 hg pull ../a |
84 hg -q tip |
89 hg -q tip |
85 |
90 |
86 # outgoing hooks can see env vars |
91 # outgoing hooks can see env vars |
87 rm .hg/hgrc |
92 rm .hg/hgrc |
88 echo '[hooks]' > ../a/.hg/hgrc |
93 echo '[hooks]' > ../a/.hg/hgrc |
89 echo 'preoutgoing = echo preoutgoing hook: s=$HG_SOURCE' >> ../a/.hg/hgrc |
94 echo 'preoutgoing = python ../printenv.py preoutgoing' >> ../a/.hg/hgrc |
90 echo 'outgoing = echo outgoing hook: n=$HG_NODE s=$HG_SOURCE' >> ../a/.hg/hgrc |
95 echo 'outgoing = python ../printenv.py outgoing' >> ../a/.hg/hgrc |
91 hg pull ../a |
96 hg pull ../a |
92 hg rollback |
97 hg rollback |
93 |
98 |
94 # preoutgoing hook can prevent outgoing changes |
99 # preoutgoing hook can prevent outgoing changes |
95 echo 'preoutgoing.forbid = echo preoutgoing.forbid hook; exit 1' >> ../a/.hg/hgrc |
100 echo 'preoutgoing.forbid = python ../printenv.py preoutgoing.forbid 1' >> ../a/.hg/hgrc |
96 hg pull ../a |
101 hg pull ../a |
97 |
102 |
98 cat > hooktests.py <<EOF |
103 cat > hooktests.py <<EOF |
99 from mercurial import util |
104 from mercurial import util |
100 |
105 |