##// END OF EJS Templates
tests: remove useless sed in test-hook
Nicolas Dumazet -
r11794:80c63b2a default
parent child Browse files
Show More
@@ -1,465 +1,465
1 1 $ cp "$TESTDIR"/printenv.py .
2 2
3 3 # commit hooks can see env vars
4 4
5 5 $ hg init a
6 6 $ cd a
7 7 $ echo "[hooks]" > .hg/hgrc
8 8 $ echo 'commit = unset HG_LOCAL HG_TAG; python ../printenv.py commit' >> .hg/hgrc
9 9 $ echo 'commit.b = unset HG_LOCAL HG_TAG; python ../printenv.py commit.b' >> .hg/hgrc
10 10 $ echo 'precommit = unset HG_LOCAL HG_NODE HG_TAG; python ../printenv.py precommit' >> .hg/hgrc
11 11 $ echo 'pretxncommit = unset HG_LOCAL HG_TAG; python ../printenv.py pretxncommit' >> .hg/hgrc
12 12 $ echo 'pretxncommit.tip = hg -q tip' >> .hg/hgrc
13 13 $ echo 'pre-identify = python ../printenv.py pre-identify 1' >> .hg/hgrc
14 14 $ echo 'pre-cat = python ../printenv.py pre-cat' >> .hg/hgrc
15 15 $ echo 'post-cat = python ../printenv.py post-cat' >> .hg/hgrc
16 16 $ echo a > a
17 17 $ hg add a
18 18 $ hg commit -m a -d "1000000 0"
19 19 precommit hook: HG_PARENT1=0000000000000000000000000000000000000000
20 20 pretxncommit hook: HG_NODE=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b HG_PARENT1=0000000000000000000000000000000000000000 HG_PENDING=$HGTMP/test-hook.t/a
21 21 0:29b62aeb769f
22 22 commit hook: HG_NODE=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b HG_PARENT1=0000000000000000000000000000000000000000
23 23 commit.b hook: HG_NODE=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b HG_PARENT1=0000000000000000000000000000000000000000
24 24
25 25 $ hg clone . ../b
26 26 updating to branch default
27 27 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
28 28 $ cd ../b
29 29
30 30 # changegroup hooks can see env vars
31 31
32 32 $ echo '[hooks]' > .hg/hgrc
33 33 $ echo 'prechangegroup = python ../printenv.py prechangegroup' >> .hg/hgrc
34 34 $ echo 'changegroup = python ../printenv.py changegroup' >> .hg/hgrc
35 35 $ echo 'incoming = python ../printenv.py incoming' >> .hg/hgrc
36 36
37 37 # pretxncommit and commit hooks can see both parents of merge
38 38
39 39 $ cd ../a
40 40 $ echo b >> a
41 41 $ hg commit -m a1 -d "1 0"
42 42 precommit hook: HG_PARENT1=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b
43 43 pretxncommit hook: HG_NODE=b702efe9688826e3a91283852b328b84dbf37bc2 HG_PARENT1=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b HG_PENDING=$HGTMP/test-hook.t/a
44 44 1:b702efe96888
45 45 commit hook: HG_NODE=b702efe9688826e3a91283852b328b84dbf37bc2 HG_PARENT1=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b
46 46 commit.b hook: HG_NODE=b702efe9688826e3a91283852b328b84dbf37bc2 HG_PARENT1=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b
47 47 $ hg update -C 0
48 48 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
49 49 $ echo b > b
50 50 $ hg add b
51 51 $ hg commit -m b -d '1 0'
52 52 precommit hook: HG_PARENT1=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b
53 53 pretxncommit hook: HG_NODE=1324a5531bac09b329c3845d35ae6a7526874edb HG_PARENT1=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b HG_PENDING=$HGTMP/test-hook.t/a
54 54 2:1324a5531bac
55 55 commit hook: HG_NODE=1324a5531bac09b329c3845d35ae6a7526874edb HG_PARENT1=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b
56 56 commit.b hook: HG_NODE=1324a5531bac09b329c3845d35ae6a7526874edb HG_PARENT1=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b
57 57 created new head
58 58 $ hg merge 1
59 59 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
60 60 (branch merge, don't forget to commit)
61 61 $ hg commit -m merge -d '2 0'
62 62 precommit hook: HG_PARENT1=1324a5531bac09b329c3845d35ae6a7526874edb HG_PARENT2=b702efe9688826e3a91283852b328b84dbf37bc2
63 63 pretxncommit hook: HG_NODE=4c52fb2e402287dd5dc052090682536c8406c321 HG_PARENT1=1324a5531bac09b329c3845d35ae6a7526874edb HG_PARENT2=b702efe9688826e3a91283852b328b84dbf37bc2 HG_PENDING=$HGTMP/test-hook.t/a
64 64 3:4c52fb2e4022
65 65 commit hook: HG_NODE=4c52fb2e402287dd5dc052090682536c8406c321 HG_PARENT1=1324a5531bac09b329c3845d35ae6a7526874edb HG_PARENT2=b702efe9688826e3a91283852b328b84dbf37bc2
66 66 commit.b hook: HG_NODE=4c52fb2e402287dd5dc052090682536c8406c321 HG_PARENT1=1324a5531bac09b329c3845d35ae6a7526874edb HG_PARENT2=b702efe9688826e3a91283852b328b84dbf37bc2
67 67
68 68 # test generic hooks
69 69
70 70 $ hg id
71 71 pre-identify hook: HG_ARGS=id HG_OPTS={'tags': None, 'rev': '', 'num': None, 'branch': None, 'id': None} HG_PATS=[]
72 72 warning: pre-identify hook exited with status 1
73 73 $ hg cat b
74 74 pre-cat hook: HG_ARGS=cat b HG_OPTS={'rev': '', 'decode': None, 'exclude': [], 'output': '', 'include': []} HG_PATS=['b']
75 75 post-cat hook: HG_ARGS=cat b HG_OPTS={'rev': '', 'decode': None, 'exclude': [], 'output': '', 'include': []} HG_PATS=['b'] HG_RESULT=0
76 76 b
77 77
78 78 $ cd ../b
79 79 $ hg pull ../a
80 80 prechangegroup hook: HG_SOURCE=pull HG_URL=file:
81 81 changegroup hook: HG_NODE=b702efe9688826e3a91283852b328b84dbf37bc2 HG_SOURCE=pull HG_URL=file:
82 82 incoming hook: HG_NODE=b702efe9688826e3a91283852b328b84dbf37bc2 HG_SOURCE=pull HG_URL=file:
83 83 incoming hook: HG_NODE=1324a5531bac09b329c3845d35ae6a7526874edb HG_SOURCE=pull HG_URL=file:
84 84 incoming hook: HG_NODE=4c52fb2e402287dd5dc052090682536c8406c321 HG_SOURCE=pull HG_URL=file:
85 85 pulling from ../a
86 86 searching for changes
87 87 adding changesets
88 88 adding manifests
89 89 adding file changes
90 90 added 3 changesets with 2 changes to 2 files
91 91 (run 'hg update' to get a working copy)
92 92
93 93 # tag hooks can see env vars
94 94
95 95 $ cd ../a
96 96 $ echo 'pretag = python ../printenv.py pretag' >> .hg/hgrc
97 97 $ echo 'tag = unset HG_PARENT1 HG_PARENT2; python ../printenv.py tag' >> .hg/hgrc
98 98 $ hg tag -d '3 0' a
99 99 pretag hook: HG_LOCAL=0 HG_NODE=4c52fb2e402287dd5dc052090682536c8406c321 HG_TAG=a
100 100 precommit hook: HG_PARENT1=4c52fb2e402287dd5dc052090682536c8406c321
101 101 pretxncommit hook: HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_PARENT1=4c52fb2e402287dd5dc052090682536c8406c321 HG_PENDING=$HGTMP/test-hook.t/a
102 102 4:8ea2ef7ad3e8
103 103 commit hook: HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_PARENT1=4c52fb2e402287dd5dc052090682536c8406c321
104 104 commit.b hook: HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_PARENT1=4c52fb2e402287dd5dc052090682536c8406c321
105 105 tag hook: HG_LOCAL=0 HG_NODE=4c52fb2e402287dd5dc052090682536c8406c321 HG_TAG=a
106 106 $ hg tag -l la
107 107 pretag hook: HG_LOCAL=1 HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_TAG=la
108 108 tag hook: HG_LOCAL=1 HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_TAG=la
109 109
110 110 # pretag hook can forbid tagging
111 111
112 112 $ echo 'pretag.forbid = python ../printenv.py pretag.forbid 1' >> .hg/hgrc
113 113 $ hg tag -d '4 0' fa
114 114 pretag hook: HG_LOCAL=0 HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_TAG=fa
115 115 pretag.forbid hook: HG_LOCAL=0 HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_TAG=fa
116 116 abort: pretag.forbid hook exited with status 1
117 117 $ hg tag -l fla
118 118 pretag hook: HG_LOCAL=1 HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_TAG=fla
119 119 pretag.forbid hook: HG_LOCAL=1 HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_TAG=fla
120 120 abort: pretag.forbid hook exited with status 1
121 121
122 122 # pretxncommit hook can see changeset, can roll back txn, changeset
123 123 # no more there after
124 124
125 125 $ echo 'pretxncommit.forbid0 = hg tip -q' >> .hg/hgrc
126 126 $ echo 'pretxncommit.forbid1 = python ../printenv.py pretxncommit.forbid 1' >> .hg/hgrc
127 127 $ echo z > z
128 128 $ hg add z
129 129 $ hg -q tip
130 130 4:8ea2ef7ad3e8
131 131 $ hg commit -m 'fail' -d '4 0'
132 132 precommit hook: HG_PARENT1=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198
133 133 pretxncommit hook: HG_NODE=fad284daf8c032148abaffcd745dafeceefceb61 HG_PARENT1=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_PENDING=$HGTMP/test-hook.t/a
134 134 5:fad284daf8c0
135 135 5:fad284daf8c0
136 136 pretxncommit.forbid hook: HG_NODE=fad284daf8c032148abaffcd745dafeceefceb61 HG_PARENT1=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_PENDING=$HGTMP/test-hook.t/a
137 137 transaction abort!
138 138 rollback completed
139 139 abort: pretxncommit.forbid1 hook exited with status 1
140 140 $ hg -q tip
141 141 4:8ea2ef7ad3e8
142 142
143 143 # precommit hook can prevent commit
144 144
145 145 $ echo 'precommit.forbid = python ../printenv.py precommit.forbid 1' >> .hg/hgrc
146 146 $ hg commit -m 'fail' -d '4 0'
147 147 precommit hook: HG_PARENT1=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198
148 148 precommit.forbid hook: HG_PARENT1=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198
149 149 abort: precommit.forbid hook exited with status 1
150 150 $ hg -q tip
151 151 4:8ea2ef7ad3e8
152 152
153 153 # preupdate hook can prevent update
154 154
155 155 $ echo 'preupdate = python ../printenv.py preupdate' >> .hg/hgrc
156 156 $ hg update 1
157 157 preupdate hook: HG_PARENT1=b702efe96888
158 158 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
159 159
160 160 # update hook
161 161
162 162 $ echo 'update = python ../printenv.py update' >> .hg/hgrc
163 163 $ hg update
164 164 preupdate hook: HG_PARENT1=8ea2ef7ad3e8
165 165 update hook: HG_ERROR=0 HG_PARENT1=8ea2ef7ad3e8
166 166 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
167 167
168 168 # prechangegroup hook can prevent incoming changes
169 169
170 170 $ cd ../b
171 171 $ hg -q tip
172 172 3:4c52fb2e4022
173 173 $ echo '[hooks]' > .hg/hgrc
174 174 $ echo 'prechangegroup.forbid = python ../printenv.py prechangegroup.forbid 1' >> .hg/hgrc
175 175 $ hg pull ../a
176 176 prechangegroup.forbid hook: HG_SOURCE=pull HG_URL=file:
177 177 pulling from ../a
178 178 searching for changes
179 179 abort: prechangegroup.forbid hook exited with status 1
180 180
181 181 # pretxnchangegroup hook can see incoming changes, can roll back txn,
182 182 # incoming changes no longer there after
183 183
184 184 $ echo '[hooks]' > .hg/hgrc
185 185 $ echo 'pretxnchangegroup.forbid0 = hg tip -q' >> .hg/hgrc
186 186 $ echo 'pretxnchangegroup.forbid1 = python ../printenv.py pretxnchangegroup.forbid 1' >> .hg/hgrc
187 187 $ hg pull ../a
188 188 4:8ea2ef7ad3e8
189 189 pretxnchangegroup.forbid hook: HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_PENDING=$HGTMP/test-hook.t/b HG_SOURCE=pull HG_URL=file:
190 190 pulling from ../a
191 191 searching for changes
192 192 adding changesets
193 193 adding manifests
194 194 adding file changes
195 195 added 1 changesets with 1 changes to 1 files
196 196 transaction abort!
197 197 rollback completed
198 198 abort: pretxnchangegroup.forbid1 hook exited with status 1
199 199 $ hg -q tip
200 200 3:4c52fb2e4022
201 201
202 202 # outgoing hooks can see env vars
203 203
204 204 $ rm .hg/hgrc
205 205 $ echo '[hooks]' > ../a/.hg/hgrc
206 206 $ echo 'preoutgoing = python ../printenv.py preoutgoing' >> ../a/.hg/hgrc
207 207 $ echo 'outgoing = python ../printenv.py outgoing' >> ../a/.hg/hgrc
208 208 $ hg pull ../a
209 209 preoutgoing hook: HG_SOURCE=pull
210 210 outgoing hook: HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_SOURCE=pull
211 211 pulling from ../a
212 212 searching for changes
213 213 adding changesets
214 214 adding manifests
215 215 adding file changes
216 216 added 1 changesets with 1 changes to 1 files
217 217 (run 'hg update' to get a working copy)
218 218 $ hg rollback
219 219 rolling back to revision 3 (undo pull)
220 220
221 221 # preoutgoing hook can prevent outgoing changes
222 222
223 223 $ echo 'preoutgoing.forbid = python ../printenv.py preoutgoing.forbid 1' >> ../a/.hg/hgrc
224 224 $ hg pull ../a
225 225 preoutgoing hook: HG_SOURCE=pull
226 226 preoutgoing.forbid hook: HG_SOURCE=pull
227 227 pulling from ../a
228 228 searching for changes
229 229 abort: preoutgoing.forbid hook exited with status 1
230 230
231 231 # outgoing hooks work for local clones
232 232
233 233 $ cd ..
234 234 $ echo '[hooks]' > a/.hg/hgrc
235 235 $ echo 'preoutgoing = python ../printenv.py preoutgoing' >> a/.hg/hgrc
236 236 $ echo 'outgoing = python ../printenv.py outgoing' >> a/.hg/hgrc
237 237 $ hg clone a c
238 238 preoutgoing hook: HG_SOURCE=clone
239 239 outgoing hook: HG_NODE=0000000000000000000000000000000000000000 HG_SOURCE=clone
240 240 updating to branch default
241 241 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
242 242 $ rm -rf c
243 243
244 244 # preoutgoing hook can prevent outgoing changes for local clones
245 245
246 246 $ echo 'preoutgoing.forbid = python ../printenv.py preoutgoing.forbid 1' >> a/.hg/hgrc
247 247 $ hg clone a zzz
248 248 preoutgoing hook: HG_SOURCE=clone
249 249 preoutgoing.forbid hook: HG_SOURCE=clone
250 250 abort: preoutgoing.forbid hook exited with status 1
251 251 $ cd b
252 252
253 253 $ cat > hooktests.py <<EOF
254 254 > from mercurial import util
255 255 >
256 256 > uncallable = 0
257 257 >
258 258 > def printargs(args):
259 259 > args.pop('ui', None)
260 260 > args.pop('repo', None)
261 261 > a = list(args.items())
262 262 > a.sort()
263 263 > print 'hook args:'
264 264 > for k, v in a:
265 265 > print ' ', k, v
266 266 >
267 267 > def passhook(**args):
268 268 > printargs(args)
269 269 >
270 270 > def failhook(**args):
271 271 > printargs(args)
272 272 > return True
273 273 >
274 274 > class LocalException(Exception):
275 275 > pass
276 276 >
277 277 > def raisehook(**args):
278 278 > raise LocalException('exception from hook')
279 279 >
280 280 > def aborthook(**args):
281 281 > raise util.Abort('raise abort from hook')
282 282 >
283 283 > def brokenhook(**args):
284 284 > return 1 + {}
285 285 >
286 286 > class container:
287 287 > unreachable = 1
288 288 > EOF
289 289
290 290 # test python hooks
291 291
292 292 $ PYTHONPATH="`pwd`:$PYTHONPATH"
293 293 $ export PYTHONPATH
294 294
295 295 $ echo '[hooks]' > ../a/.hg/hgrc
296 296 $ echo 'preoutgoing.broken = python:hooktests.brokenhook' >> ../a/.hg/hgrc
297 297 $ hg pull ../a 2>&1 | grep 'raised an exception'
298 298 error: preoutgoing.broken hook raised an exception: unsupported operand type(s) for +: 'int' and 'dict'
299 299
300 300 $ echo '[hooks]' > ../a/.hg/hgrc
301 301 $ echo 'preoutgoing.raise = python:hooktests.raisehook' >> ../a/.hg/hgrc
302 302 $ hg pull ../a 2>&1 | grep 'raised an exception'
303 303 error: preoutgoing.raise hook raised an exception: exception from hook
304 304
305 305 $ echo '[hooks]' > ../a/.hg/hgrc
306 306 $ echo 'preoutgoing.abort = python:hooktests.aborthook' >> ../a/.hg/hgrc
307 307 $ hg pull ../a
308 308 pulling from ../a
309 309 searching for changes
310 310 error: preoutgoing.abort hook failed: raise abort from hook
311 311 abort: raise abort from hook
312 312
313 313 $ echo '[hooks]' > ../a/.hg/hgrc
314 314 $ echo 'preoutgoing.fail = python:hooktests.failhook' >> ../a/.hg/hgrc
315 315 $ hg pull ../a
316 316 pulling from ../a
317 317 searching for changes
318 318 hook args:
319 319 hooktype preoutgoing
320 320 source pull
321 321 abort: preoutgoing.fail hook failed
322 322
323 323 $ echo '[hooks]' > ../a/.hg/hgrc
324 324 $ echo 'preoutgoing.uncallable = python:hooktests.uncallable' >> ../a/.hg/hgrc
325 325 $ hg pull ../a
326 326 pulling from ../a
327 327 searching for changes
328 328 abort: preoutgoing.uncallable hook is invalid ("hooktests.uncallable" is not callable)
329 329
330 330 $ echo '[hooks]' > ../a/.hg/hgrc
331 331 $ echo 'preoutgoing.nohook = python:hooktests.nohook' >> ../a/.hg/hgrc
332 332 $ hg pull ../a
333 333 pulling from ../a
334 334 searching for changes
335 335 abort: preoutgoing.nohook hook is invalid ("hooktests.nohook" is not defined)
336 336
337 337 $ echo '[hooks]' > ../a/.hg/hgrc
338 338 $ echo 'preoutgoing.nomodule = python:nomodule' >> ../a/.hg/hgrc
339 339 $ hg pull ../a
340 340 pulling from ../a
341 341 searching for changes
342 342 abort: preoutgoing.nomodule hook is invalid ("nomodule" not in a module)
343 343
344 344 $ echo '[hooks]' > ../a/.hg/hgrc
345 345 $ echo 'preoutgoing.badmodule = python:nomodule.nowhere' >> ../a/.hg/hgrc
346 346 $ hg pull ../a
347 347 pulling from ../a
348 348 searching for changes
349 349 abort: preoutgoing.badmodule hook is invalid (import of "nomodule" failed)
350 350
351 351 $ echo '[hooks]' > ../a/.hg/hgrc
352 352 $ echo 'preoutgoing.unreachable = python:hooktests.container.unreachable' >> ../a/.hg/hgrc
353 353 $ hg pull ../a
354 354 pulling from ../a
355 355 searching for changes
356 356 abort: preoutgoing.unreachable hook is invalid (import of "hooktests.container" failed)
357 357
358 358 $ echo '[hooks]' > ../a/.hg/hgrc
359 359 $ echo 'preoutgoing.pass = python:hooktests.passhook' >> ../a/.hg/hgrc
360 360 $ hg pull ../a
361 361 pulling from ../a
362 362 searching for changes
363 363 hook args:
364 364 hooktype preoutgoing
365 365 source pull
366 366 adding changesets
367 367 adding manifests
368 368 adding file changes
369 369 added 1 changesets with 1 changes to 1 files
370 370 (run 'hg update' to get a working copy)
371 371
372 372 # make sure --traceback works
373 373
374 374 $ echo '[hooks]' > .hg/hgrc
375 375 $ echo 'commit.abort = python:hooktests.aborthook' >> .hg/hgrc
376 376
377 377 $ echo aa > a
378 378 $ hg --traceback commit -d '0 0' -ma 2>&1 | grep '^Traceback'
379 379 Traceback (most recent call last):
380 380
381 381 $ cd ..
382 382 $ hg init c
383 383 $ cd c
384 384
385 385 $ cat > hookext.py <<EOF
386 386 > def autohook(**args):
387 387 > print "Automatically installed hook"
388 388 >
389 389 > def reposetup(ui, repo):
390 390 > repo.ui.setconfig("hooks", "commit.auto", autohook)
391 391 > EOF
392 392 $ echo '[extensions]' >> .hg/hgrc
393 393 $ echo 'hookext = hookext.py' >> .hg/hgrc
394 394
395 395 $ touch foo
396 396 $ hg add foo
397 397 $ hg ci -d '0 0' -m 'add foo'
398 398 Automatically installed hook
399 399 $ echo >> foo
400 $ hg ci --debug -d '0 0' -m 'change foo' | sed -e 's/ at .*>/>/'
400 $ hg ci --debug -d '0 0' -m 'change foo'
401 401 foo
402 calling hook commit.auto: <function autohook>
402 calling hook commit.auto: <function autohook at .*>
403 403 Automatically installed hook
404 404 committed changeset 1:52998019f6252a2b893452765fcb0a47351a5708
405 405
406 $ hg showconfig hooks | sed -e 's/ at .*>/>/'
407 hooks.commit.auto=<function autohook>
406 $ hg showconfig hooks
407 hooks.commit.auto=<function autohook at .*>
408 408
409 409 # test python hook configured with python:[file]:[hook] syntax
410 410
411 411 $ cd ..
412 412 $ mkdir d
413 413 $ cd d
414 414 $ hg init repo
415 415 $ mkdir hooks
416 416
417 417 $ cd hooks
418 418 $ cat > testhooks.py <<EOF
419 419 > def testhook(**args):
420 420 > print 'hook works'
421 421 > EOF
422 422 $ echo '[hooks]' > ../repo/.hg/hgrc
423 423 $ echo "pre-commit.test = python:`pwd`/testhooks.py:testhook" >> ../repo/.hg/hgrc
424 424
425 425 $ cd ../repo
426 426 $ hg commit -d '0 0'
427 427 hook works
428 428 nothing changed
429 429
430 430 $ cd ../../b
431 431
432 432 # make sure --traceback works on hook import failure
433 433
434 434 $ cat > importfail.py <<EOF
435 435 > import somebogusmodule
436 436 > # dereference something in the module to force demandimport to load it
437 437 > somebogusmodule.whatever
438 438 > EOF
439 439
440 440 $ echo '[hooks]' > .hg/hgrc
441 441 $ echo 'precommit.importfail = python:importfail.whatever' >> .hg/hgrc
442 442
443 443 $ echo a >> a
444 444 $ hg --traceback commit -d '0 0' -ma 2>&1 | egrep '^(exception|Traceback|ImportError)'
445 445 exception from first failed import attempt:
446 446 Traceback (most recent call last):
447 447 ImportError: No module named somebogusmodule
448 448 exception from second failed import attempt:
449 449 Traceback (most recent call last):
450 450 ImportError: No module named hgext_importfail
451 451 Traceback (most recent call last):
452 452
453 453 # commit and update hooks should run after command completion (issue 1827)
454 454
455 455 $ echo '[hooks]' > .hg/hgrc
456 456 $ echo 'commit = hg id' >> .hg/hgrc
457 457 $ echo 'update = hg id' >> .hg/hgrc
458 458 $ echo bb > a
459 459 $ hg ci -d '0 0' -ma
460 460 8da618c33484 tip
461 461 $ hg up 0
462 462 29b62aeb769f
463 463 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
464 464
465 465 $ exit 0
General Comments 0
You need to be logged in to leave comments. Login now