##// END OF EJS Templates
Applied $PWD fix (changeset 278f9b13c39a) to tests/test-hook, too.
Thomas Arendsen Hein -
r2164:cbd45822 default
parent child Browse files
Show More
@@ -1,179 +1,179
1 #!/bin/sh
1 #!/bin/sh
2
2
3 # commit hooks can see env vars
3 # commit hooks can see env vars
4 hg init a
4 hg init a
5 cd a
5 cd a
6 echo "[hooks]" > .hg/hgrc
6 echo "[hooks]" > .hg/hgrc
7 echo 'commit = echo commit hook: n=$HG_NODE p1=$HG_PARENT1 p2=$HG_PARENT2' >> .hg/hgrc
7 echo 'commit = echo commit hook: n=$HG_NODE p1=$HG_PARENT1 p2=$HG_PARENT2' >> .hg/hgrc
8 echo 'commit.b = echo commit hook b' >> .hg/hgrc
8 echo 'commit.b = echo commit hook b' >> .hg/hgrc
9 echo 'precommit = echo precommit hook: p1=$HG_PARENT1 p2=$HG_PARENT2' >> .hg/hgrc
9 echo 'precommit = echo precommit hook: p1=$HG_PARENT1 p2=$HG_PARENT2' >> .hg/hgrc
10 echo 'pretxncommit = echo pretxncommit hook: n=$HG_NODE p1=$HG_PARENT1 p2=$HG_PARENT2; hg -q tip' >> .hg/hgrc
10 echo 'pretxncommit = echo pretxncommit hook: n=$HG_NODE p1=$HG_PARENT1 p2=$HG_PARENT2; hg -q tip' >> .hg/hgrc
11 echo a > a
11 echo a > a
12 hg add a
12 hg add a
13 hg commit -m a -d "1000000 0"
13 hg commit -m a -d "1000000 0"
14
14
15 hg clone . ../b
15 hg clone . ../b
16 cd ../b
16 cd ../b
17
17
18 # changegroup hooks can see env vars
18 # changegroup hooks can see env vars
19 echo '[hooks]' > .hg/hgrc
19 echo '[hooks]' > .hg/hgrc
20 echo 'prechangegroup = echo prechangegroup hook' >> .hg/hgrc
20 echo 'prechangegroup = echo prechangegroup hook' >> .hg/hgrc
21 echo 'changegroup = echo changegroup hook: n=$HG_NODE' >> .hg/hgrc
21 echo 'changegroup = echo changegroup hook: n=$HG_NODE' >> .hg/hgrc
22 echo 'incoming = echo incoming hook: n=$HG_NODE' >> .hg/hgrc
22 echo 'incoming = echo incoming hook: n=$HG_NODE' >> .hg/hgrc
23
23
24 # pretxncommit and commit hooks can see both parents of merge
24 # pretxncommit and commit hooks can see both parents of merge
25 cd ../a
25 cd ../a
26 echo b >> a
26 echo b >> a
27 hg commit -m a1 -d "1 0"
27 hg commit -m a1 -d "1 0"
28 hg update -C 0
28 hg update -C 0
29 echo b > b
29 echo b > b
30 hg add b
30 hg add b
31 hg commit -m b -d '1 0'
31 hg commit -m b -d '1 0'
32 hg update -m 1
32 hg update -m 1
33 hg commit -m merge -d '2 0'
33 hg commit -m merge -d '2 0'
34
34
35 cd ../b
35 cd ../b
36 hg pull ../a
36 hg pull ../a
37
37
38 # tag hooks can see env vars
38 # tag hooks can see env vars
39 cd ../a
39 cd ../a
40 echo 'pretag = echo pretag hook: t=$HG_TAG n=$HG_NODE l=$HG_LOCAL' >> .hg/hgrc
40 echo 'pretag = echo pretag hook: t=$HG_TAG n=$HG_NODE l=$HG_LOCAL' >> .hg/hgrc
41 echo 'tag = echo tag hook: t=$HG_TAG n=$HG_NODE l=$HG_LOCAL' >> .hg/hgrc
41 echo 'tag = echo tag hook: t=$HG_TAG n=$HG_NODE l=$HG_LOCAL' >> .hg/hgrc
42 hg tag -d '3 0' a
42 hg tag -d '3 0' a
43 hg tag -l la
43 hg tag -l la
44
44
45 # pretag hook can forbid tagging
45 # pretag hook can forbid tagging
46 echo 'pretag.forbid = echo pretag.forbid hook; exit 1' >> .hg/hgrc
46 echo 'pretag.forbid = echo pretag.forbid hook; exit 1' >> .hg/hgrc
47 hg tag -d '4 0' fa
47 hg tag -d '4 0' fa
48 hg tag -l fla
48 hg tag -l fla
49
49
50 # pretxncommit hook can see changeset, can roll back txn, changeset
50 # pretxncommit hook can see changeset, can roll back txn, changeset
51 # no more there after
51 # no more there after
52 echo 'pretxncommit.forbid = echo pretxncommit.forbid hook: tip=`hg -q tip`; exit 1' >> .hg/hgrc
52 echo 'pretxncommit.forbid = echo pretxncommit.forbid hook: tip=`hg -q tip`; exit 1' >> .hg/hgrc
53 echo z > z
53 echo z > z
54 hg add z
54 hg add z
55 hg -q tip
55 hg -q tip
56 hg commit -m 'fail' -d '4 0'
56 hg commit -m 'fail' -d '4 0'
57 hg -q tip
57 hg -q tip
58
58
59 # precommit hook can prevent commit
59 # precommit hook can prevent commit
60 echo 'precommit.forbid = echo precommit.forbid hook; exit 1' >> .hg/hgrc
60 echo 'precommit.forbid = echo precommit.forbid hook; exit 1' >> .hg/hgrc
61 hg commit -m 'fail' -d '4 0'
61 hg commit -m 'fail' -d '4 0'
62 hg -q tip
62 hg -q tip
63
63
64 # prechangegroup hook can prevent incoming changes
64 # prechangegroup hook can prevent incoming changes
65 cd ../b
65 cd ../b
66 hg -q tip
66 hg -q tip
67 echo '[hooks]' > .hg/hgrc
67 echo '[hooks]' > .hg/hgrc
68 echo 'prechangegroup.forbid = echo prechangegroup.forbid hook; exit 1' >> .hg/hgrc
68 echo 'prechangegroup.forbid = echo prechangegroup.forbid hook; exit 1' >> .hg/hgrc
69 hg pull ../a
69 hg pull ../a
70
70
71 # pretxnchangegroup hook can see incoming changes, can roll back txn,
71 # pretxnchangegroup hook can see incoming changes, can roll back txn,
72 # incoming changes no longer there after
72 # incoming changes no longer there after
73 echo '[hooks]' > .hg/hgrc
73 echo '[hooks]' > .hg/hgrc
74 echo 'pretxnchangegroup.forbid = echo pretxnchangegroup.forbid hook: tip=`hg -q tip`; exit 1' >> .hg/hgrc
74 echo 'pretxnchangegroup.forbid = echo pretxnchangegroup.forbid hook: tip=`hg -q tip`; exit 1' >> .hg/hgrc
75 hg pull ../a
75 hg pull ../a
76 hg -q tip
76 hg -q tip
77
77
78 # outgoing hooks can see env vars
78 # outgoing hooks can see env vars
79 rm .hg/hgrc
79 rm .hg/hgrc
80 echo '[hooks]' > ../a/.hg/hgrc
80 echo '[hooks]' > ../a/.hg/hgrc
81 echo 'preoutgoing = echo preoutgoing hook: s=$HG_SOURCE' >> ../a/.hg/hgrc
81 echo 'preoutgoing = echo preoutgoing hook: s=$HG_SOURCE' >> ../a/.hg/hgrc
82 echo 'outgoing = echo outgoing hook: n=$HG_NODE s=$HG_SOURCE' >> ../a/.hg/hgrc
82 echo 'outgoing = echo outgoing hook: n=$HG_NODE s=$HG_SOURCE' >> ../a/.hg/hgrc
83 hg pull ../a
83 hg pull ../a
84 hg undo
84 hg undo
85
85
86 # preoutgoing hook can prevent outgoing changes
86 # preoutgoing hook can prevent outgoing changes
87 echo 'preoutgoing.forbid = echo preoutgoing.forbid hook; exit 1' >> ../a/.hg/hgrc
87 echo 'preoutgoing.forbid = echo preoutgoing.forbid hook; exit 1' >> ../a/.hg/hgrc
88 hg pull ../a
88 hg pull ../a
89
89
90 cat > hooktests.py <<EOF
90 cat > hooktests.py <<EOF
91 from mercurial import util
91 from mercurial import util
92
92
93 uncallable = 0
93 uncallable = 0
94
94
95 def printargs(args):
95 def printargs(args):
96 args.pop('ui', None)
96 args.pop('ui', None)
97 args.pop('repo', None)
97 args.pop('repo', None)
98 a = list(args.items())
98 a = list(args.items())
99 a.sort()
99 a.sort()
100 print 'hook args:'
100 print 'hook args:'
101 for k, v in a:
101 for k, v in a:
102 print ' ', k, v
102 print ' ', k, v
103 return True
103 return True
104
104
105 def passhook(**args):
105 def passhook(**args):
106 printargs(args)
106 printargs(args)
107 return True
107 return True
108
108
109 def failhook(**args):
109 def failhook(**args):
110 printargs(args)
110 printargs(args)
111
111
112 class LocalException(Exception):
112 class LocalException(Exception):
113 pass
113 pass
114
114
115 def raisehook(**args):
115 def raisehook(**args):
116 raise LocalException('exception from hook')
116 raise LocalException('exception from hook')
117
117
118 def aborthook(**args):
118 def aborthook(**args):
119 raise util.Abort('raise abort from hook')
119 raise util.Abort('raise abort from hook')
120
120
121 def brokenhook(**args):
121 def brokenhook(**args):
122 return 1 + {}
122 return 1 + {}
123
123
124 class container:
124 class container:
125 unreachable = 1
125 unreachable = 1
126 EOF
126 EOF
127
127
128 echo '# test python hooks'
128 echo '# test python hooks'
129 PYTHONPATH="$PWD:$PYTHONPATH"
129 PYTHONPATH="`pwd`:$PYTHONPATH"
130 export PYTHONPATH
130 export PYTHONPATH
131
131
132 echo '[hooks]' > ../a/.hg/hgrc
132 echo '[hooks]' > ../a/.hg/hgrc
133 echo 'preoutgoing.broken = python:hooktests.brokenhook' >> ../a/.hg/hgrc
133 echo 'preoutgoing.broken = python:hooktests.brokenhook' >> ../a/.hg/hgrc
134 hg pull ../a 2>&1 | grep 'raised an exception'
134 hg pull ../a 2>&1 | grep 'raised an exception'
135
135
136 echo '[hooks]' > ../a/.hg/hgrc
136 echo '[hooks]' > ../a/.hg/hgrc
137 echo 'preoutgoing.raise = python:hooktests.raisehook' >> ../a/.hg/hgrc
137 echo 'preoutgoing.raise = python:hooktests.raisehook' >> ../a/.hg/hgrc
138 hg pull ../a 2>&1 | grep 'raised an exception'
138 hg pull ../a 2>&1 | grep 'raised an exception'
139
139
140 echo '[hooks]' > ../a/.hg/hgrc
140 echo '[hooks]' > ../a/.hg/hgrc
141 echo 'preoutgoing.abort = python:hooktests.aborthook' >> ../a/.hg/hgrc
141 echo 'preoutgoing.abort = python:hooktests.aborthook' >> ../a/.hg/hgrc
142 hg pull ../a
142 hg pull ../a
143
143
144 echo '[hooks]' > ../a/.hg/hgrc
144 echo '[hooks]' > ../a/.hg/hgrc
145 echo 'preoutgoing.fail = python:hooktests.failhook' >> ../a/.hg/hgrc
145 echo 'preoutgoing.fail = python:hooktests.failhook' >> ../a/.hg/hgrc
146 hg pull ../a
146 hg pull ../a
147
147
148 echo '[hooks]' > ../a/.hg/hgrc
148 echo '[hooks]' > ../a/.hg/hgrc
149 echo 'preoutgoing.uncallable = python:hooktests.uncallable' >> ../a/.hg/hgrc
149 echo 'preoutgoing.uncallable = python:hooktests.uncallable' >> ../a/.hg/hgrc
150 hg pull ../a
150 hg pull ../a
151
151
152 echo '[hooks]' > ../a/.hg/hgrc
152 echo '[hooks]' > ../a/.hg/hgrc
153 echo 'preoutgoing.nohook = python:hooktests.nohook' >> ../a/.hg/hgrc
153 echo 'preoutgoing.nohook = python:hooktests.nohook' >> ../a/.hg/hgrc
154 hg pull ../a
154 hg pull ../a
155
155
156 echo '[hooks]' > ../a/.hg/hgrc
156 echo '[hooks]' > ../a/.hg/hgrc
157 echo 'preoutgoing.nomodule = python:nomodule' >> ../a/.hg/hgrc
157 echo 'preoutgoing.nomodule = python:nomodule' >> ../a/.hg/hgrc
158 hg pull ../a
158 hg pull ../a
159
159
160 echo '[hooks]' > ../a/.hg/hgrc
160 echo '[hooks]' > ../a/.hg/hgrc
161 echo 'preoutgoing.badmodule = python:nomodule.nowhere' >> ../a/.hg/hgrc
161 echo 'preoutgoing.badmodule = python:nomodule.nowhere' >> ../a/.hg/hgrc
162 hg pull ../a
162 hg pull ../a
163
163
164 echo '[hooks]' > ../a/.hg/hgrc
164 echo '[hooks]' > ../a/.hg/hgrc
165 echo 'preoutgoing.unreachable = python:hooktests.container.unreachable' >> ../a/.hg/hgrc
165 echo 'preoutgoing.unreachable = python:hooktests.container.unreachable' >> ../a/.hg/hgrc
166 hg pull ../a
166 hg pull ../a
167
167
168 echo '[hooks]' > ../a/.hg/hgrc
168 echo '[hooks]' > ../a/.hg/hgrc
169 echo 'preoutgoing.pass = python:hooktests.passhook' >> ../a/.hg/hgrc
169 echo 'preoutgoing.pass = python:hooktests.passhook' >> ../a/.hg/hgrc
170 hg pull ../a
170 hg pull ../a
171
171
172 echo '# make sure --traceback works'
172 echo '# make sure --traceback works'
173 echo '[hooks]' > .hg/hgrc
173 echo '[hooks]' > .hg/hgrc
174 echo 'commit.abort = python:hooktests.aborthook' >> .hg/hgrc
174 echo 'commit.abort = python:hooktests.aborthook' >> .hg/hgrc
175
175
176 echo a >> a
176 echo a >> a
177 hg --traceback commit -A -m a 2>&1 | grep '^Traceback'
177 hg --traceback commit -A -m a 2>&1 | grep '^Traceback'
178
178
179 exit 0
179 exit 0
General Comments 0
You need to be logged in to leave comments. Login now