25 $ hg clone . ../b |
25 $ hg clone . ../b |
26 updating to branch default |
26 updating to branch default |
27 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
27 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
28 $ cd ../b |
28 $ cd ../b |
29 |
29 |
30 # changegroup hooks can see env vars |
30 changegroup hooks can see env vars |
31 |
31 |
32 $ echo '[hooks]' > .hg/hgrc |
32 $ echo '[hooks]' > .hg/hgrc |
33 $ echo 'prechangegroup = python ../printenv.py prechangegroup' >> .hg/hgrc |
33 $ echo 'prechangegroup = python ../printenv.py prechangegroup' >> .hg/hgrc |
34 $ echo 'changegroup = python ../printenv.py changegroup' >> .hg/hgrc |
34 $ echo 'changegroup = python ../printenv.py changegroup' >> .hg/hgrc |
35 $ echo 'incoming = python ../printenv.py incoming' >> .hg/hgrc |
35 $ echo 'incoming = python ../printenv.py incoming' >> .hg/hgrc |
36 |
36 |
37 # pretxncommit and commit hooks can see both parents of merge |
37 pretxncommit and commit hooks can see both parents of merge |
38 |
38 |
39 $ cd ../a |
39 $ cd ../a |
40 $ echo b >> a |
40 $ echo b >> a |
41 $ hg commit -m a1 -d "1 0" |
41 $ hg commit -m a1 -d "1 0" |
42 precommit hook: HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b |
42 precommit hook: HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b |
63 pretxncommit hook: HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PARENT1=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT2=ab228980c14deea8b9555d91c9581127383e40fd HG_PENDING=$HGTMP/test-hook.t/a |
63 pretxncommit hook: HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PARENT1=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT2=ab228980c14deea8b9555d91c9581127383e40fd HG_PENDING=$HGTMP/test-hook.t/a |
64 3:07f3376c1e65 |
64 3:07f3376c1e65 |
65 commit hook: HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PARENT1=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT2=ab228980c14deea8b9555d91c9581127383e40fd |
65 commit hook: HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PARENT1=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT2=ab228980c14deea8b9555d91c9581127383e40fd |
66 commit.b hook: HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PARENT1=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT2=ab228980c14deea8b9555d91c9581127383e40fd |
66 commit.b hook: HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PARENT1=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT2=ab228980c14deea8b9555d91c9581127383e40fd |
67 |
67 |
68 # test generic hooks |
68 test generic hooks |
69 |
69 |
70 $ hg id |
70 $ hg id |
71 pre-identify hook: HG_ARGS=id HG_OPTS={'tags': None, 'rev': '', 'num': None, 'branch': None, 'id': None} HG_PATS=[] |
71 pre-identify hook: HG_ARGS=id HG_OPTS={'tags': None, 'rev': '', 'num': None, 'branch': None, 'id': None} HG_PATS=[] |
72 warning: pre-identify hook exited with status 1 |
72 warning: pre-identify hook exited with status 1 |
73 [1] |
73 [1] |
89 adding manifests |
89 adding manifests |
90 adding file changes |
90 adding file changes |
91 added 3 changesets with 2 changes to 2 files |
91 added 3 changesets with 2 changes to 2 files |
92 (run 'hg update' to get a working copy) |
92 (run 'hg update' to get a working copy) |
93 |
93 |
94 # tag hooks can see env vars |
94 tag hooks can see env vars |
95 |
95 |
96 $ cd ../a |
96 $ cd ../a |
97 $ echo 'pretag = python ../printenv.py pretag' >> .hg/hgrc |
97 $ echo 'pretag = python ../printenv.py pretag' >> .hg/hgrc |
98 $ echo 'tag = unset HG_PARENT1 HG_PARENT2; python ../printenv.py tag' >> .hg/hgrc |
98 $ echo 'tag = unset HG_PARENT1 HG_PARENT2; python ../printenv.py tag' >> .hg/hgrc |
99 $ hg tag -d '3 0' a |
99 $ hg tag -d '3 0' a |
106 tag hook: HG_LOCAL=0 HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_TAG=a |
106 tag hook: HG_LOCAL=0 HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_TAG=a |
107 $ hg tag -l la |
107 $ hg tag -l la |
108 pretag hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=la |
108 pretag hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=la |
109 tag hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=la |
109 tag hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=la |
110 |
110 |
111 # pretag hook can forbid tagging |
111 pretag hook can forbid tagging |
112 |
112 |
113 $ echo 'pretag.forbid = python ../printenv.py pretag.forbid 1' >> .hg/hgrc |
113 $ echo 'pretag.forbid = python ../printenv.py pretag.forbid 1' >> .hg/hgrc |
114 $ hg tag -d '4 0' fa |
114 $ hg tag -d '4 0' fa |
115 pretag hook: HG_LOCAL=0 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fa |
115 pretag hook: HG_LOCAL=0 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fa |
116 pretag.forbid hook: HG_LOCAL=0 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fa |
116 pretag.forbid hook: HG_LOCAL=0 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fa |
120 pretag hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fla |
120 pretag hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fla |
121 pretag.forbid hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fla |
121 pretag.forbid hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fla |
122 abort: pretag.forbid hook exited with status 1 |
122 abort: pretag.forbid hook exited with status 1 |
123 [255] |
123 [255] |
124 |
124 |
125 # pretxncommit hook can see changeset, can roll back txn, changeset |
125 pretxncommit hook can see changeset, can roll back txn, changeset no |
126 # no more there after |
126 more there after |
127 |
127 |
128 $ echo 'pretxncommit.forbid0 = hg tip -q' >> .hg/hgrc |
128 $ echo 'pretxncommit.forbid0 = hg tip -q' >> .hg/hgrc |
129 $ echo 'pretxncommit.forbid1 = python ../printenv.py pretxncommit.forbid 1' >> .hg/hgrc |
129 $ echo 'pretxncommit.forbid1 = python ../printenv.py pretxncommit.forbid 1' >> .hg/hgrc |
130 $ echo z > z |
130 $ echo z > z |
131 $ hg add z |
131 $ hg add z |
142 abort: pretxncommit.forbid1 hook exited with status 1 |
142 abort: pretxncommit.forbid1 hook exited with status 1 |
143 [255] |
143 [255] |
144 $ hg -q tip |
144 $ hg -q tip |
145 4:539e4b31b6dc |
145 4:539e4b31b6dc |
146 |
146 |
147 # precommit hook can prevent commit |
147 precommit hook can prevent commit |
148 |
148 |
149 $ echo 'precommit.forbid = python ../printenv.py precommit.forbid 1' >> .hg/hgrc |
149 $ echo 'precommit.forbid = python ../printenv.py precommit.forbid 1' >> .hg/hgrc |
150 $ hg commit -m 'fail' -d '4 0' |
150 $ hg commit -m 'fail' -d '4 0' |
151 precommit hook: HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 |
151 precommit hook: HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 |
152 precommit.forbid hook: HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 |
152 precommit.forbid hook: HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 |
153 abort: precommit.forbid hook exited with status 1 |
153 abort: precommit.forbid hook exited with status 1 |
154 [255] |
154 [255] |
155 $ hg -q tip |
155 $ hg -q tip |
156 4:539e4b31b6dc |
156 4:539e4b31b6dc |
157 |
157 |
158 # preupdate hook can prevent update |
158 preupdate hook can prevent update |
159 |
159 |
160 $ echo 'preupdate = python ../printenv.py preupdate' >> .hg/hgrc |
160 $ echo 'preupdate = python ../printenv.py preupdate' >> .hg/hgrc |
161 $ hg update 1 |
161 $ hg update 1 |
162 preupdate hook: HG_PARENT1=ab228980c14d |
162 preupdate hook: HG_PARENT1=ab228980c14d |
163 0 files updated, 0 files merged, 2 files removed, 0 files unresolved |
163 0 files updated, 0 files merged, 2 files removed, 0 files unresolved |
164 |
164 |
165 # update hook |
165 update hook |
166 |
166 |
167 $ echo 'update = python ../printenv.py update' >> .hg/hgrc |
167 $ echo 'update = python ../printenv.py update' >> .hg/hgrc |
168 $ hg update |
168 $ hg update |
169 preupdate hook: HG_PARENT1=539e4b31b6dc |
169 preupdate hook: HG_PARENT1=539e4b31b6dc |
170 update hook: HG_ERROR=0 HG_PARENT1=539e4b31b6dc |
170 update hook: HG_ERROR=0 HG_PARENT1=539e4b31b6dc |
171 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
171 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
172 |
172 |
173 # prechangegroup hook can prevent incoming changes |
173 prechangegroup hook can prevent incoming changes |
174 |
174 |
175 $ cd ../b |
175 $ cd ../b |
176 $ hg -q tip |
176 $ hg -q tip |
177 3:07f3376c1e65 |
177 3:07f3376c1e65 |
178 $ echo '[hooks]' > .hg/hgrc |
178 $ echo '[hooks]' > .hg/hgrc |
182 pulling from ../a |
182 pulling from ../a |
183 searching for changes |
183 searching for changes |
184 abort: prechangegroup.forbid hook exited with status 1 |
184 abort: prechangegroup.forbid hook exited with status 1 |
185 [255] |
185 [255] |
186 |
186 |
187 # pretxnchangegroup hook can see incoming changes, can roll back txn, |
187 pretxnchangegroup hook can see incoming changes, can roll back txn, |
188 # incoming changes no longer there after |
188 incoming changes no longer there after |
189 |
189 |
190 $ echo '[hooks]' > .hg/hgrc |
190 $ echo '[hooks]' > .hg/hgrc |
191 $ echo 'pretxnchangegroup.forbid0 = hg tip -q' >> .hg/hgrc |
191 $ echo 'pretxnchangegroup.forbid0 = hg tip -q' >> .hg/hgrc |
192 $ echo 'pretxnchangegroup.forbid1 = python ../printenv.py pretxnchangegroup.forbid 1' >> .hg/hgrc |
192 $ echo 'pretxnchangegroup.forbid1 = python ../printenv.py pretxnchangegroup.forbid 1' >> .hg/hgrc |
193 $ hg pull ../a |
193 $ hg pull ../a |
204 abort: pretxnchangegroup.forbid1 hook exited with status 1 |
204 abort: pretxnchangegroup.forbid1 hook exited with status 1 |
205 [255] |
205 [255] |
206 $ hg -q tip |
206 $ hg -q tip |
207 3:07f3376c1e65 |
207 3:07f3376c1e65 |
208 |
208 |
209 # outgoing hooks can see env vars |
209 outgoing hooks can see env vars |
210 |
210 |
211 $ rm .hg/hgrc |
211 $ rm .hg/hgrc |
212 $ echo '[hooks]' > ../a/.hg/hgrc |
212 $ echo '[hooks]' > ../a/.hg/hgrc |
213 $ echo 'preoutgoing = python ../printenv.py preoutgoing' >> ../a/.hg/hgrc |
213 $ echo 'preoutgoing = python ../printenv.py preoutgoing' >> ../a/.hg/hgrc |
214 $ echo 'outgoing = python ../printenv.py outgoing' >> ../a/.hg/hgrc |
214 $ echo 'outgoing = python ../printenv.py outgoing' >> ../a/.hg/hgrc |
223 added 1 changesets with 1 changes to 1 files |
223 added 1 changesets with 1 changes to 1 files |
224 (run 'hg update' to get a working copy) |
224 (run 'hg update' to get a working copy) |
225 $ hg rollback |
225 $ hg rollback |
226 rolling back to revision 3 (undo pull) |
226 rolling back to revision 3 (undo pull) |
227 |
227 |
228 # preoutgoing hook can prevent outgoing changes |
228 preoutgoing hook can prevent outgoing changes |
229 |
229 |
230 $ echo 'preoutgoing.forbid = python ../printenv.py preoutgoing.forbid 1' >> ../a/.hg/hgrc |
230 $ echo 'preoutgoing.forbid = python ../printenv.py preoutgoing.forbid 1' >> ../a/.hg/hgrc |
231 $ hg pull ../a |
231 $ hg pull ../a |
232 preoutgoing hook: HG_SOURCE=pull |
232 preoutgoing hook: HG_SOURCE=pull |
233 preoutgoing.forbid hook: HG_SOURCE=pull |
233 preoutgoing.forbid hook: HG_SOURCE=pull |
234 pulling from ../a |
234 pulling from ../a |
235 searching for changes |
235 searching for changes |
236 abort: preoutgoing.forbid hook exited with status 1 |
236 abort: preoutgoing.forbid hook exited with status 1 |
237 [255] |
237 [255] |
238 |
238 |
239 # outgoing hooks work for local clones |
239 outgoing hooks work for local clones |
240 |
240 |
241 $ cd .. |
241 $ cd .. |
242 $ echo '[hooks]' > a/.hg/hgrc |
242 $ echo '[hooks]' > a/.hg/hgrc |
243 $ echo 'preoutgoing = python ../printenv.py preoutgoing' >> a/.hg/hgrc |
243 $ echo 'preoutgoing = python ../printenv.py preoutgoing' >> a/.hg/hgrc |
244 $ echo 'outgoing = python ../printenv.py outgoing' >> a/.hg/hgrc |
244 $ echo 'outgoing = python ../printenv.py outgoing' >> a/.hg/hgrc |
247 outgoing hook: HG_NODE=0000000000000000000000000000000000000000 HG_SOURCE=clone |
247 outgoing hook: HG_NODE=0000000000000000000000000000000000000000 HG_SOURCE=clone |
248 updating to branch default |
248 updating to branch default |
249 3 files updated, 0 files merged, 0 files removed, 0 files unresolved |
249 3 files updated, 0 files merged, 0 files removed, 0 files unresolved |
250 $ rm -rf c |
250 $ rm -rf c |
251 |
251 |
252 # preoutgoing hook can prevent outgoing changes for local clones |
252 preoutgoing hook can prevent outgoing changes for local clones |
253 |
253 |
254 $ echo 'preoutgoing.forbid = python ../printenv.py preoutgoing.forbid 1' >> a/.hg/hgrc |
254 $ echo 'preoutgoing.forbid = python ../printenv.py preoutgoing.forbid 1' >> a/.hg/hgrc |
255 $ hg clone a zzz |
255 $ hg clone a zzz |
256 preoutgoing hook: HG_SOURCE=clone |
256 preoutgoing hook: HG_SOURCE=clone |
257 preoutgoing.forbid hook: HG_SOURCE=clone |
257 preoutgoing.forbid hook: HG_SOURCE=clone |
383 adding manifests |
383 adding manifests |
384 adding file changes |
384 adding file changes |
385 added 1 changesets with 1 changes to 1 files |
385 added 1 changesets with 1 changes to 1 files |
386 (run 'hg update' to get a working copy) |
386 (run 'hg update' to get a working copy) |
387 |
387 |
388 # make sure --traceback works |
388 make sure --traceback works |
389 |
389 |
390 $ echo '[hooks]' > .hg/hgrc |
390 $ echo '[hooks]' > .hg/hgrc |
391 $ echo 'commit.abort = python:hooktests.aborthook' >> .hg/hgrc |
391 $ echo 'commit.abort = python:hooktests.aborthook' >> .hg/hgrc |
392 |
392 |
393 $ echo aa > a |
393 $ echo aa > a |
444 nothing changed |
444 nothing changed |
445 [1] |
445 [1] |
446 |
446 |
447 $ cd ../../b |
447 $ cd ../../b |
448 |
448 |
449 # make sure --traceback works on hook import failure |
449 make sure --traceback works on hook import failure |
450 |
450 |
451 $ cat > importfail.py <<EOF |
451 $ cat > importfail.py <<EOF |
452 > import somebogusmodule |
452 > import somebogusmodule |
453 > # dereference something in the module to force demandimport to load it |
453 > # dereference something in the module to force demandimport to load it |
454 > somebogusmodule.whatever |
454 > somebogusmodule.whatever |
465 exception from second failed import attempt: |
465 exception from second failed import attempt: |
466 Traceback (most recent call last): |
466 Traceback (most recent call last): |
467 ImportError: No module named hgext_importfail |
467 ImportError: No module named hgext_importfail |
468 Traceback (most recent call last): |
468 Traceback (most recent call last): |
469 |
469 |
470 # commit and update hooks should run after command completion (issue 1827) |
470 commit and update hooks should run after command completion (issue 1827) |
471 |
471 |
472 $ echo '[hooks]' > .hg/hgrc |
472 $ echo '[hooks]' > .hg/hgrc |
473 $ echo 'commit = hg id' >> .hg/hgrc |
473 $ echo 'commit = hg id' >> .hg/hgrc |
474 $ echo 'update = hg id' >> .hg/hgrc |
474 $ echo 'update = hg id' >> .hg/hgrc |
475 $ echo bb > a |
475 $ echo bb > a |