comparison tests/test-hook.t @ 16964:eecaeeca2106

test-hook: adapt for Windows
author Adrian Buehlmann <adrian@cadifra.com>
date Fri, 15 Jun 2012 21:42:47 +0200
parents d947e1da1259
children 9c892c830a72
comparison
equal deleted inserted replaced
16963:c19113e842d3 16964:eecaeeca2106
1 $ "$TESTDIR/hghave" system-sh || exit 80
2
3 commit hooks can see env vars 1 commit hooks can see env vars
4 2
5 $ hg init a 3 $ hg init a
6 $ cd a 4 $ cd a
7 $ echo "[hooks]" > .hg/hgrc 5 $ cat > .hg/hgrc <<EOF
8 $ echo 'commit = unset HG_LOCAL HG_TAG; python "$TESTDIR"/printenv.py commit' >> .hg/hgrc 6 > [hooks]
9 $ echo 'commit.b = unset HG_LOCAL HG_TAG; python "$TESTDIR"/printenv.py commit.b' >> .hg/hgrc 7 > commit = sh -c "HG_LOCAL= HG_TAG= python \"$TESTDIR/printenv.py\" commit"
10 $ echo 'precommit = unset HG_LOCAL HG_NODE HG_TAG; python "$TESTDIR"/printenv.py precommit' >> .hg/hgrc 8 > commit.b = sh -c "HG_LOCAL= HG_TAG= python \"$TESTDIR/printenv.py\" commit.b"
11 $ echo 'pretxncommit = unset HG_LOCAL HG_TAG; python "$TESTDIR"/printenv.py pretxncommit' >> .hg/hgrc 9 > precommit = sh -c "HG_LOCAL= HG_NODE= HG_TAG= python \"$TESTDIR/printenv.py\" precommit"
12 $ echo 'pretxncommit.tip = hg -q tip' >> .hg/hgrc 10 > pretxncommit = sh -c "HG_LOCAL= HG_TAG= python \"$TESTDIR/printenv.py\" pretxncommit"
13 $ echo 'pre-identify = python "$TESTDIR"/printenv.py pre-identify 1' >> .hg/hgrc 11 > pretxncommit.tip = hg -q tip
14 $ echo 'pre-cat = python "$TESTDIR"/printenv.py pre-cat' >> .hg/hgrc 12 > pre-identify = python "$TESTDIR/printenv.py" pre-identify 1
15 $ echo 'post-cat = python "$TESTDIR"/printenv.py post-cat' >> .hg/hgrc 13 > pre-cat = python "$TESTDIR/printenv.py" pre-cat
14 > post-cat = python "$TESTDIR/printenv.py" post-cat
15 > EOF
16 $ echo a > a 16 $ echo a > a
17 $ hg add a 17 $ hg add a
18 $ hg commit -m a 18 $ hg commit -m a
19 precommit hook: HG_PARENT1=0000000000000000000000000000000000000000 19 precommit hook: HG_PARENT1=0000000000000000000000000000000000000000
20 pretxncommit hook: HG_NODE=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b HG_PARENT1=0000000000000000000000000000000000000000 HG_PENDING=$TESTTMP/a 20 pretxncommit hook: HG_NODE=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b HG_PARENT1=0000000000000000000000000000000000000000 HG_PENDING=$TESTTMP/a
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 $ cat > .hg/hgrc <<EOF
33 $ echo 'prechangegroup = python "$TESTDIR"/printenv.py prechangegroup' >> .hg/hgrc 33 > [hooks]
34 $ echo 'changegroup = python "$TESTDIR"/printenv.py changegroup' >> .hg/hgrc 34 > prechangegroup = python "$TESTDIR/printenv.py" prechangegroup
35 $ echo 'incoming = python "$TESTDIR"/printenv.py incoming' >> .hg/hgrc 35 > changegroup = python "$TESTDIR/printenv.py" changegroup
36 > incoming = python "$TESTDIR/printenv.py" incoming
37 > EOF
36 38
37 pretxncommit and commit hooks can see both parents of merge 39 pretxncommit and commit hooks can see both parents of merge
38 40
39 $ cd ../a 41 $ cd ../a
40 $ echo b >> a 42 $ echo b >> a
92 (run 'hg update' to get a working copy) 94 (run 'hg update' to get a working copy)
93 95
94 tag hooks can see env vars 96 tag hooks can see env vars
95 97
96 $ cd ../a 98 $ cd ../a
97 $ echo 'pretag = python "$TESTDIR"/printenv.py pretag' >> .hg/hgrc 99 $ cat >> .hg/hgrc <<EOF
98 $ echo 'tag = unset HG_PARENT1 HG_PARENT2; python "$TESTDIR"/printenv.py tag' >> .hg/hgrc 100 > pretag = python "$TESTDIR/printenv.py" pretag
101 > tag = sh -c "HG_PARENT1= HG_PARENT2= python \"$TESTDIR/printenv.py\" tag"
102 > EOF
99 $ hg tag -d '3 0' a 103 $ hg tag -d '3 0' a
100 pretag hook: HG_LOCAL=0 HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_TAG=a 104 pretag hook: HG_LOCAL=0 HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_TAG=a
101 precommit hook: HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2 105 precommit hook: HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2
102 pretxncommit hook: HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PENDING=$TESTTMP/a 106 pretxncommit hook: HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PENDING=$TESTTMP/a
103 4:539e4b31b6dc 107 4:539e4b31b6dc
108 pretag hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=la 112 pretag hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=la
109 tag hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=la 113 tag hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=la
110 114
111 pretag hook can forbid tagging 115 pretag hook can forbid tagging
112 116
113 $ echo 'pretag.forbid = python "$TESTDIR"/printenv.py pretag.forbid 1' >> .hg/hgrc 117 $ echo "pretag.forbid = python \"$TESTDIR/printenv.py\" pretag.forbid 1" >> .hg/hgrc
114 $ hg tag -d '4 0' fa 118 $ hg tag -d '4 0' fa
115 pretag hook: HG_LOCAL=0 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fa 119 pretag 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.forbid hook: HG_LOCAL=0 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fa
117 abort: pretag.forbid hook exited with status 1 121 abort: pretag.forbid hook exited with status 1
118 [255] 122 [255]
123 [255] 127 [255]
124 128
125 pretxncommit hook can see changeset, can roll back txn, changeset no 129 pretxncommit hook can see changeset, can roll back txn, changeset no
126 more there after 130 more there after
127 131
128 $ echo 'pretxncommit.forbid0 = hg tip -q' >> .hg/hgrc 132 $ echo "pretxncommit.forbid0 = hg tip -q" >> .hg/hgrc
129 $ echo 'pretxncommit.forbid1 = python "$TESTDIR"/printenv.py pretxncommit.forbid 1' >> .hg/hgrc 133 $ echo "pretxncommit.forbid1 = python \"$TESTDIR/printenv.py\" pretxncommit.forbid 1" >> .hg/hgrc
130 $ echo z > z 134 $ echo z > z
131 $ hg add z 135 $ hg add z
132 $ hg -q tip 136 $ hg -q tip
133 4:539e4b31b6dc 137 4:539e4b31b6dc
134 $ hg commit -m 'fail' -d '4 0' 138 $ hg commit -m 'fail' -d '4 0'
144 $ hg -q tip 148 $ hg -q tip
145 4:539e4b31b6dc 149 4:539e4b31b6dc
146 150
147 precommit hook can prevent commit 151 precommit hook can prevent commit
148 152
149 $ echo 'precommit.forbid = python "$TESTDIR"/printenv.py precommit.forbid 1' >> .hg/hgrc 153 $ echo "precommit.forbid = python \"$TESTDIR/printenv.py\" precommit.forbid 1" >> .hg/hgrc
150 $ hg commit -m 'fail' -d '4 0' 154 $ hg commit -m 'fail' -d '4 0'
151 precommit hook: HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 155 precommit hook: HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
152 precommit.forbid hook: HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 156 precommit.forbid hook: HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
153 abort: precommit.forbid hook exited with status 1 157 abort: precommit.forbid hook exited with status 1
154 [255] 158 [255]
155 $ hg -q tip 159 $ hg -q tip
156 4:539e4b31b6dc 160 4:539e4b31b6dc
157 161
158 preupdate hook can prevent update 162 preupdate hook can prevent update
159 163
160 $ echo 'preupdate = python "$TESTDIR"/printenv.py preupdate' >> .hg/hgrc 164 $ echo "preupdate = python \"$TESTDIR/printenv.py\" preupdate" >> .hg/hgrc
161 $ hg update 1 165 $ hg update 1
162 preupdate hook: HG_PARENT1=ab228980c14d 166 preupdate hook: HG_PARENT1=ab228980c14d
163 0 files updated, 0 files merged, 2 files removed, 0 files unresolved 167 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
164 168
165 update hook 169 update hook
166 170
167 $ echo 'update = python "$TESTDIR"/printenv.py update' >> .hg/hgrc 171 $ echo "update = python \"$TESTDIR/printenv.py\" update" >> .hg/hgrc
168 $ hg update 172 $ hg update
169 preupdate hook: HG_PARENT1=539e4b31b6dc 173 preupdate hook: HG_PARENT1=539e4b31b6dc
170 update hook: HG_ERROR=0 HG_PARENT1=539e4b31b6dc 174 update hook: HG_ERROR=0 HG_PARENT1=539e4b31b6dc
171 2 files updated, 0 files merged, 0 files removed, 0 files unresolved 175 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
172 176
173 pushkey hook 177 pushkey hook
174 178
175 $ echo 'pushkey = python "$TESTDIR"/printenv.py pushkey' >> .hg/hgrc 179 $ echo "pushkey = python \"$TESTDIR/printenv.py\" pushkey" >> .hg/hgrc
176 $ cd ../b 180 $ cd ../b
177 $ hg bookmark -r null foo 181 $ hg bookmark -r null foo
178 $ hg push -B foo ../a 182 $ hg push -B foo ../a
179 pushing to ../a 183 pushing to ../a
180 searching for changes 184 searching for changes
184 [1] 188 [1]
185 $ cd ../a 189 $ cd ../a
186 190
187 listkeys hook 191 listkeys hook
188 192
189 $ echo 'listkeys = python "$TESTDIR"/printenv.py listkeys' >> .hg/hgrc 193 $ echo "listkeys = python \"$TESTDIR/printenv.py\" listkeys" >> .hg/hgrc
190 $ hg bookmark -r null bar 194 $ hg bookmark -r null bar
191 $ cd ../b 195 $ cd ../b
192 $ hg pull -B bar ../a 196 $ hg pull -B bar ../a
193 pulling from ../a 197 pulling from ../a
194 listkeys hook: HG_NAMESPACE=bookmarks HG_VALUES={'bar': '0000000000000000000000000000000000000000', 'foo': '0000000000000000000000000000000000000000'} 198 listkeys hook: HG_NAMESPACE=bookmarks HG_VALUES={'bar': '0000000000000000000000000000000000000000', 'foo': '0000000000000000000000000000000000000000'}
199 importing bookmark bar 203 importing bookmark bar
200 $ cd ../a 204 $ cd ../a
201 205
202 test that prepushkey can prevent incoming keys 206 test that prepushkey can prevent incoming keys
203 207
204 $ echo 'prepushkey = python "$TESTDIR"/printenv.py prepushkey.forbid 1' >> .hg/hgrc 208 $ echo "prepushkey = python \"$TESTDIR/printenv.py\" prepushkey.forbid 1" >> .hg/hgrc
205 $ cd ../b 209 $ cd ../b
206 $ hg bookmark -r null baz 210 $ hg bookmark -r null baz
207 $ hg push -B baz ../a 211 $ hg push -B baz ../a
208 pushing to ../a 212 pushing to ../a
209 searching for changes 213 searching for changes
217 [255] 221 [255]
218 $ cd ../a 222 $ cd ../a
219 223
220 test that prelistkeys can prevent listing keys 224 test that prelistkeys can prevent listing keys
221 225
222 $ echo 'prelistkeys = python "$TESTDIR"/printenv.py prelistkeys.forbid 1' >> .hg/hgrc 226 $ echo "prelistkeys = python \"$TESTDIR/printenv.py\" prelistkeys.forbid 1" >> .hg/hgrc
223 $ hg bookmark -r null quux 227 $ hg bookmark -r null quux
224 $ cd ../b 228 $ cd ../b
225 $ hg pull -B quux ../a 229 $ hg pull -B quux ../a
226 pulling from ../a 230 pulling from ../a
227 prelistkeys.forbid hook: HG_NAMESPACE=bookmarks 231 prelistkeys.forbid hook: HG_NAMESPACE=bookmarks
232 prechangegroup hook can prevent incoming changes 236 prechangegroup hook can prevent incoming changes
233 237
234 $ cd ../b 238 $ cd ../b
235 $ hg -q tip 239 $ hg -q tip
236 3:07f3376c1e65 240 3:07f3376c1e65
237 $ echo '[hooks]' > .hg/hgrc 241 $ cat > .hg/hgrc <<EOF
238 $ echo 'prechangegroup.forbid = python "$TESTDIR"/printenv.py prechangegroup.forbid 1' >> .hg/hgrc 242 > [hooks]
243 > prechangegroup.forbid = python "$TESTDIR/printenv.py" prechangegroup.forbid 1
244 > EOF
239 $ hg pull ../a 245 $ hg pull ../a
240 pulling from ../a 246 pulling from ../a
241 searching for changes 247 searching for changes
242 prechangegroup.forbid hook: HG_SOURCE=pull HG_URL=file:$TESTTMP/a 248 prechangegroup.forbid hook: HG_SOURCE=pull HG_URL=file:$TESTTMP/a
243 abort: prechangegroup.forbid hook exited with status 1 249 abort: prechangegroup.forbid hook exited with status 1
244 [255] 250 [255]
245 251
246 pretxnchangegroup hook can see incoming changes, can roll back txn, 252 pretxnchangegroup hook can see incoming changes, can roll back txn,
247 incoming changes no longer there after 253 incoming changes no longer there after
248 254
249 $ echo '[hooks]' > .hg/hgrc 255 $ cat > .hg/hgrc <<EOF
250 $ echo 'pretxnchangegroup.forbid0 = hg tip -q' >> .hg/hgrc 256 > [hooks]
251 $ echo 'pretxnchangegroup.forbid1 = python "$TESTDIR"/printenv.py pretxnchangegroup.forbid 1' >> .hg/hgrc 257 > pretxnchangegroup.forbid0 = hg tip -q
258 > pretxnchangegroup.forbid1 = python "$TESTDIR/printenv.py" pretxnchangegroup.forbid 1
259 > EOF
252 $ hg pull ../a 260 $ hg pull ../a
253 pulling from ../a 261 pulling from ../a
254 searching for changes 262 searching for changes
255 adding changesets 263 adding changesets
256 adding manifests 264 adding manifests
266 3:07f3376c1e65 274 3:07f3376c1e65
267 275
268 outgoing hooks can see env vars 276 outgoing hooks can see env vars
269 277
270 $ rm .hg/hgrc 278 $ rm .hg/hgrc
271 $ echo '[hooks]' > ../a/.hg/hgrc 279 $ cat > ../a/.hg/hgrc <<EOF
272 $ echo 'preoutgoing = python "$TESTDIR"/printenv.py preoutgoing' >> ../a/.hg/hgrc 280 > [hooks]
273 $ echo 'outgoing = python "$TESTDIR"/printenv.py outgoing' >> ../a/.hg/hgrc 281 > preoutgoing = python "$TESTDIR/printenv.py" preoutgoing
282 > outgoing = python "$TESTDIR/printenv.py" outgoing
283 > EOF
274 $ hg pull ../a 284 $ hg pull ../a
275 pulling from ../a 285 pulling from ../a
276 searching for changes 286 searching for changes
277 preoutgoing hook: HG_SOURCE=pull 287 preoutgoing hook: HG_SOURCE=pull
278 adding changesets 288 adding changesets
285 $ hg rollback 295 $ hg rollback
286 repository tip rolled back to revision 3 (undo pull) 296 repository tip rolled back to revision 3 (undo pull)
287 297
288 preoutgoing hook can prevent outgoing changes 298 preoutgoing hook can prevent outgoing changes
289 299
290 $ echo 'preoutgoing.forbid = python "$TESTDIR"/printenv.py preoutgoing.forbid 1' >> ../a/.hg/hgrc 300 $ echo "preoutgoing.forbid = python \"$TESTDIR/printenv.py\" preoutgoing.forbid 1" >> ../a/.hg/hgrc
291 $ hg pull ../a 301 $ hg pull ../a
292 pulling from ../a 302 pulling from ../a
293 searching for changes 303 searching for changes
294 preoutgoing hook: HG_SOURCE=pull 304 preoutgoing hook: HG_SOURCE=pull
295 preoutgoing.forbid hook: HG_SOURCE=pull 305 preoutgoing.forbid hook: HG_SOURCE=pull
297 [255] 307 [255]
298 308
299 outgoing hooks work for local clones 309 outgoing hooks work for local clones
300 310
301 $ cd .. 311 $ cd ..
302 $ echo '[hooks]' > a/.hg/hgrc 312 $ cat > a/.hg/hgrc <<EOF
303 $ echo 'preoutgoing = python "$TESTDIR"/printenv.py preoutgoing' >> a/.hg/hgrc 313 > [hooks]
304 $ echo 'outgoing = python "$TESTDIR"/printenv.py outgoing' >> a/.hg/hgrc 314 > preoutgoing = python "$TESTDIR/printenv.py" preoutgoing
315 > outgoing = python "$TESTDIR/printenv.py" outgoing
316 > EOF
305 $ hg clone a c 317 $ hg clone a c
306 preoutgoing hook: HG_SOURCE=clone 318 preoutgoing hook: HG_SOURCE=clone
307 outgoing hook: HG_NODE=0000000000000000000000000000000000000000 HG_SOURCE=clone 319 outgoing hook: HG_NODE=0000000000000000000000000000000000000000 HG_SOURCE=clone
308 updating to branch default 320 updating to branch default
309 3 files updated, 0 files merged, 0 files removed, 0 files unresolved 321 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
310 $ rm -rf c 322 $ rm -rf c
311 323
312 preoutgoing hook can prevent outgoing changes for local clones 324 preoutgoing hook can prevent outgoing changes for local clones
313 325
314 $ echo 'preoutgoing.forbid = python "$TESTDIR"/printenv.py preoutgoing.forbid 1' >> a/.hg/hgrc 326 $ echo "preoutgoing.forbid = python \"$TESTDIR/printenv.py\" preoutgoing.forbid 1" >> a/.hg/hgrc
315 $ hg clone a zzz 327 $ hg clone a zzz
316 preoutgoing hook: HG_SOURCE=clone 328 preoutgoing hook: HG_SOURCE=clone
317 preoutgoing.forbid hook: HG_SOURCE=clone 329 preoutgoing.forbid hook: HG_SOURCE=clone
318 abort: preoutgoing.forbid hook exited with status 1 330 abort: preoutgoing.forbid hook exited with status 1
319 [255] 331 [255]
320 $ cd b 332
333 $ cd "$TESTTMP/b"
321 334
322 $ cat > hooktests.py <<EOF 335 $ cat > hooktests.py <<EOF
323 > from mercurial import util 336 > from mercurial import util
324 > 337 >
325 > uncallable = 0 338 > uncallable = 0
362 > unreachable = 1 375 > unreachable = 1
363 > EOF 376 > EOF
364 377
365 test python hooks 378 test python hooks
366 379
367 $ PYTHONPATH="`pwd`:$PYTHONPATH" 380 #if windows
381 $ PYTHONPATH="$TESTTMP/b;$PYTHONPATH"
382 #else
383 $ PYTHONPATH="$TESTTMP/b:$PYTHONPATH"
384 #endif
368 $ export PYTHONPATH 385 $ export PYTHONPATH
369 386
370 $ echo '[hooks]' > ../a/.hg/hgrc 387 $ echo '[hooks]' > ../a/.hg/hgrc
371 $ echo 'preoutgoing.broken = python:hooktests.brokenhook' >> ../a/.hg/hgrc 388 $ echo 'preoutgoing.broken = python:hooktests.brokenhook' >> ../a/.hg/hgrc
372 $ hg pull ../a 2>&1 | grep 'raised an exception' 389 $ hg pull ../a 2>&1 | grep 'raised an exception'
595 updating to branch default 612 updating to branch default
596 1 files updated, 0 files merged, 0 files removed, 0 files unresolved 613 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
597 $ echo aa >> from/a 614 $ echo aa >> from/a
598 $ hg --cwd from ci -mb 615 $ hg --cwd from ci -mb
599 $ hg --cwd from push 616 $ hg --cwd from push
600 pushing to $TESTTMP/to 617 pushing to $TESTTMP/to (glob)
601 searching for changes 618 searching for changes
602 adding changesets 619 adding changesets
603 adding manifests 620 adding manifests
604 adding file changes 621 adding file changes
605 added 1 changesets with 1 changes to 1 files 622 added 1 changesets with 1 changes to 1 files