##// END OF EJS Templates
Work around problem where 'del os.environ["FOO"]' doesn't update environment....
Thomas Arendsen Hein -
r4368:97962a3e default
parent child Browse files
Show More
@@ -1,213 +1,213 b''
1 #!/bin/sh
1 #!/bin/sh
2
2
3 cp "$TESTDIR"/printenv.py .
3 cp "$TESTDIR"/printenv.py .
4
4
5 # commit hooks can see env vars
5 # commit hooks can see env vars
6 hg init a
6 hg init a
7 cd a
7 cd a
8 echo "[hooks]" > .hg/hgrc
8 echo "[hooks]" > .hg/hgrc
9 echo 'commit = python ../printenv.py commit' >> .hg/hgrc
9 echo 'commit = unset HG_LOCAL HG_TAG; python ../printenv.py commit' >> .hg/hgrc
10 echo 'commit.b = python ../printenv.py commit.b' >> .hg/hgrc
10 echo 'commit.b = unset HG_LOCAL HG_TAG; python ../printenv.py commit.b' >> .hg/hgrc
11 echo 'precommit = python ../printenv.py precommit' >> .hg/hgrc
11 echo 'precommit = unset HG_LOCAL HG_NODE HG_TAG; python ../printenv.py precommit' >> .hg/hgrc
12 echo 'pretxncommit = python ../printenv.py pretxncommit' >> .hg/hgrc
12 echo 'pretxncommit = unset HG_LOCAL HG_TAG; python ../printenv.py pretxncommit' >> .hg/hgrc
13 echo 'pretxncommit.tip = hg -q tip' >> .hg/hgrc
13 echo 'pretxncommit.tip = hg -q tip' >> .hg/hgrc
14 echo a > a
14 echo a > a
15 hg add a
15 hg add a
16 hg commit -m a -d "1000000 0"
16 hg commit -m a -d "1000000 0"
17
17
18 hg clone . ../b
18 hg clone . ../b
19 cd ../b
19 cd ../b
20
20
21 # changegroup hooks can see env vars
21 # changegroup hooks can see env vars
22 echo '[hooks]' > .hg/hgrc
22 echo '[hooks]' > .hg/hgrc
23 echo 'prechangegroup = python ../printenv.py prechangegroup' >> .hg/hgrc
23 echo 'prechangegroup = python ../printenv.py prechangegroup' >> .hg/hgrc
24 echo 'changegroup = python ../printenv.py changegroup' >> .hg/hgrc
24 echo 'changegroup = python ../printenv.py changegroup' >> .hg/hgrc
25 echo 'incoming = python ../printenv.py incoming' >> .hg/hgrc
25 echo 'incoming = python ../printenv.py incoming' >> .hg/hgrc
26
26
27 # pretxncommit and commit hooks can see both parents of merge
27 # pretxncommit and commit hooks can see both parents of merge
28 cd ../a
28 cd ../a
29 echo b >> a
29 echo b >> a
30 hg commit -m a1 -d "1 0"
30 hg commit -m a1 -d "1 0"
31 hg update -C 0
31 hg update -C 0
32 echo b > b
32 echo b > b
33 hg add b
33 hg add b
34 hg commit -m b -d '1 0'
34 hg commit -m b -d '1 0'
35 hg merge 1
35 hg merge 1
36 hg commit -m merge -d '2 0'
36 hg commit -m merge -d '2 0'
37
37
38 cd ../b
38 cd ../b
39 hg pull ../a
39 hg pull ../a
40
40
41 # tag hooks can see env vars
41 # tag hooks can see env vars
42 cd ../a
42 cd ../a
43 echo 'pretag = python ../printenv.py pretag' >> .hg/hgrc
43 echo 'pretag = python ../printenv.py pretag' >> .hg/hgrc
44 echo 'tag = python ../printenv.py tag' >> .hg/hgrc
44 echo 'tag = unset HG_PARENT1 HG_PARENT2; python ../printenv.py tag' >> .hg/hgrc
45 hg tag -d '3 0' a
45 hg tag -d '3 0' a
46 hg tag -l la
46 hg tag -l la
47
47
48 # pretag hook can forbid tagging
48 # pretag hook can forbid tagging
49 echo 'pretag.forbid = python ../printenv.py pretag.forbid 1' >> .hg/hgrc
49 echo 'pretag.forbid = python ../printenv.py pretag.forbid 1' >> .hg/hgrc
50 hg tag -d '4 0' fa
50 hg tag -d '4 0' fa
51 hg tag -l fla
51 hg tag -l fla
52
52
53 # pretxncommit hook can see changeset, can roll back txn, changeset
53 # pretxncommit hook can see changeset, can roll back txn, changeset
54 # no more there after
54 # no more there after
55 echo 'pretxncommit.forbid0 = hg tip -q' >> .hg/hgrc
55 echo 'pretxncommit.forbid0 = hg tip -q' >> .hg/hgrc
56 echo 'pretxncommit.forbid1 = python ../printenv.py pretxncommit.forbid 1' >> .hg/hgrc
56 echo 'pretxncommit.forbid1 = python ../printenv.py pretxncommit.forbid 1' >> .hg/hgrc
57 echo z > z
57 echo z > z
58 hg add z
58 hg add z
59 hg -q tip
59 hg -q tip
60 hg commit -m 'fail' -d '4 0'
60 hg commit -m 'fail' -d '4 0'
61 hg -q tip
61 hg -q tip
62
62
63 # precommit hook can prevent commit
63 # precommit hook can prevent commit
64 echo 'precommit.forbid = python ../printenv.py precommit.forbid 1' >> .hg/hgrc
64 echo 'precommit.forbid = python ../printenv.py precommit.forbid 1' >> .hg/hgrc
65 hg commit -m 'fail' -d '4 0'
65 hg commit -m 'fail' -d '4 0'
66 hg -q tip
66 hg -q tip
67
67
68 # preupdate hook can prevent update
68 # preupdate hook can prevent update
69 echo 'preupdate = python ../printenv.py preupdate' >> .hg/hgrc
69 echo 'preupdate = python ../printenv.py preupdate' >> .hg/hgrc
70 hg update 1
70 hg update 1
71
71
72 # update hook
72 # update hook
73 echo 'update = python ../printenv.py update' >> .hg/hgrc
73 echo 'update = python ../printenv.py update' >> .hg/hgrc
74 hg update
74 hg update
75
75
76 # prechangegroup hook can prevent incoming changes
76 # prechangegroup hook can prevent incoming changes
77 cd ../b
77 cd ../b
78 hg -q tip
78 hg -q tip
79 echo '[hooks]' > .hg/hgrc
79 echo '[hooks]' > .hg/hgrc
80 echo 'prechangegroup.forbid = python ../printenv.py prechangegroup.forbid 1' >> .hg/hgrc
80 echo 'prechangegroup.forbid = python ../printenv.py prechangegroup.forbid 1' >> .hg/hgrc
81 hg pull ../a
81 hg pull ../a
82
82
83 # pretxnchangegroup hook can see incoming changes, can roll back txn,
83 # pretxnchangegroup hook can see incoming changes, can roll back txn,
84 # incoming changes no longer there after
84 # incoming changes no longer there after
85 echo '[hooks]' > .hg/hgrc
85 echo '[hooks]' > .hg/hgrc
86 echo 'pretxnchangegroup.forbid0 = hg tip -q' >> .hg/hgrc
86 echo 'pretxnchangegroup.forbid0 = hg tip -q' >> .hg/hgrc
87 echo 'pretxnchangegroup.forbid1 = python ../printenv.py pretxnchangegroup.forbid 1' >> .hg/hgrc
87 echo 'pretxnchangegroup.forbid1 = python ../printenv.py pretxnchangegroup.forbid 1' >> .hg/hgrc
88 hg pull ../a
88 hg pull ../a
89 hg -q tip
89 hg -q tip
90
90
91 # outgoing hooks can see env vars
91 # outgoing hooks can see env vars
92 rm .hg/hgrc
92 rm .hg/hgrc
93 echo '[hooks]' > ../a/.hg/hgrc
93 echo '[hooks]' > ../a/.hg/hgrc
94 echo 'preoutgoing = python ../printenv.py preoutgoing' >> ../a/.hg/hgrc
94 echo 'preoutgoing = python ../printenv.py preoutgoing' >> ../a/.hg/hgrc
95 echo 'outgoing = python ../printenv.py outgoing' >> ../a/.hg/hgrc
95 echo 'outgoing = python ../printenv.py outgoing' >> ../a/.hg/hgrc
96 hg pull ../a
96 hg pull ../a
97 hg rollback
97 hg rollback
98
98
99 # preoutgoing hook can prevent outgoing changes
99 # preoutgoing hook can prevent outgoing changes
100 echo 'preoutgoing.forbid = python ../printenv.py preoutgoing.forbid 1' >> ../a/.hg/hgrc
100 echo 'preoutgoing.forbid = python ../printenv.py preoutgoing.forbid 1' >> ../a/.hg/hgrc
101 hg pull ../a
101 hg pull ../a
102
102
103 cat > hooktests.py <<EOF
103 cat > hooktests.py <<EOF
104 from mercurial import util
104 from mercurial import util
105
105
106 uncallable = 0
106 uncallable = 0
107
107
108 def printargs(args):
108 def printargs(args):
109 args.pop('ui', None)
109 args.pop('ui', None)
110 args.pop('repo', None)
110 args.pop('repo', None)
111 a = list(args.items())
111 a = list(args.items())
112 a.sort()
112 a.sort()
113 print 'hook args:'
113 print 'hook args:'
114 for k, v in a:
114 for k, v in a:
115 print ' ', k, v
115 print ' ', k, v
116
116
117 def passhook(**args):
117 def passhook(**args):
118 printargs(args)
118 printargs(args)
119
119
120 def failhook(**args):
120 def failhook(**args):
121 printargs(args)
121 printargs(args)
122 return True
122 return True
123
123
124 class LocalException(Exception):
124 class LocalException(Exception):
125 pass
125 pass
126
126
127 def raisehook(**args):
127 def raisehook(**args):
128 raise LocalException('exception from hook')
128 raise LocalException('exception from hook')
129
129
130 def aborthook(**args):
130 def aborthook(**args):
131 raise util.Abort('raise abort from hook')
131 raise util.Abort('raise abort from hook')
132
132
133 def brokenhook(**args):
133 def brokenhook(**args):
134 return 1 + {}
134 return 1 + {}
135
135
136 class container:
136 class container:
137 unreachable = 1
137 unreachable = 1
138 EOF
138 EOF
139
139
140 echo '# test python hooks'
140 echo '# test python hooks'
141 PYTHONPATH="`pwd`:$PYTHONPATH"
141 PYTHONPATH="`pwd`:$PYTHONPATH"
142 export PYTHONPATH
142 export PYTHONPATH
143
143
144 echo '[hooks]' > ../a/.hg/hgrc
144 echo '[hooks]' > ../a/.hg/hgrc
145 echo 'preoutgoing.broken = python:hooktests.brokenhook' >> ../a/.hg/hgrc
145 echo 'preoutgoing.broken = python:hooktests.brokenhook' >> ../a/.hg/hgrc
146 hg pull ../a 2>&1 | grep 'raised an exception'
146 hg pull ../a 2>&1 | grep 'raised an exception'
147
147
148 echo '[hooks]' > ../a/.hg/hgrc
148 echo '[hooks]' > ../a/.hg/hgrc
149 echo 'preoutgoing.raise = python:hooktests.raisehook' >> ../a/.hg/hgrc
149 echo 'preoutgoing.raise = python:hooktests.raisehook' >> ../a/.hg/hgrc
150 hg pull ../a 2>&1 | grep 'raised an exception'
150 hg pull ../a 2>&1 | grep 'raised an exception'
151
151
152 echo '[hooks]' > ../a/.hg/hgrc
152 echo '[hooks]' > ../a/.hg/hgrc
153 echo 'preoutgoing.abort = python:hooktests.aborthook' >> ../a/.hg/hgrc
153 echo 'preoutgoing.abort = python:hooktests.aborthook' >> ../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.fail = python:hooktests.failhook' >> ../a/.hg/hgrc
157 echo 'preoutgoing.fail = python:hooktests.failhook' >> ../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.uncallable = python:hooktests.uncallable' >> ../a/.hg/hgrc
161 echo 'preoutgoing.uncallable = python:hooktests.uncallable' >> ../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.nohook = python:hooktests.nohook' >> ../a/.hg/hgrc
165 echo 'preoutgoing.nohook = python:hooktests.nohook' >> ../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.nomodule = python:nomodule' >> ../a/.hg/hgrc
169 echo 'preoutgoing.nomodule = python:nomodule' >> ../a/.hg/hgrc
170 hg pull ../a
170 hg pull ../a
171
171
172 echo '[hooks]' > ../a/.hg/hgrc
172 echo '[hooks]' > ../a/.hg/hgrc
173 echo 'preoutgoing.badmodule = python:nomodule.nowhere' >> ../a/.hg/hgrc
173 echo 'preoutgoing.badmodule = python:nomodule.nowhere' >> ../a/.hg/hgrc
174 hg pull ../a
174 hg pull ../a
175
175
176 echo '[hooks]' > ../a/.hg/hgrc
176 echo '[hooks]' > ../a/.hg/hgrc
177 echo 'preoutgoing.unreachable = python:hooktests.container.unreachable' >> ../a/.hg/hgrc
177 echo 'preoutgoing.unreachable = python:hooktests.container.unreachable' >> ../a/.hg/hgrc
178 hg pull ../a
178 hg pull ../a
179
179
180 echo '[hooks]' > ../a/.hg/hgrc
180 echo '[hooks]' > ../a/.hg/hgrc
181 echo 'preoutgoing.pass = python:hooktests.passhook' >> ../a/.hg/hgrc
181 echo 'preoutgoing.pass = python:hooktests.passhook' >> ../a/.hg/hgrc
182 hg pull ../a
182 hg pull ../a
183
183
184 echo '# make sure --traceback works'
184 echo '# make sure --traceback works'
185 echo '[hooks]' > .hg/hgrc
185 echo '[hooks]' > .hg/hgrc
186 echo 'commit.abort = python:hooktests.aborthook' >> .hg/hgrc
186 echo 'commit.abort = python:hooktests.aborthook' >> .hg/hgrc
187
187
188 echo a >> a
188 echo a >> a
189 hg --traceback commit -A -m a 2>&1 | grep '^Traceback'
189 hg --traceback commit -A -m a 2>&1 | grep '^Traceback'
190
190
191 cd ..
191 cd ..
192 hg init c
192 hg init c
193 cd c
193 cd c
194
194
195 cat > hookext.py <<EOF
195 cat > hookext.py <<EOF
196 def autohook(**args):
196 def autohook(**args):
197 print "Automatically installed hook"
197 print "Automatically installed hook"
198
198
199 def reposetup(ui, repo):
199 def reposetup(ui, repo):
200 repo.ui.setconfig("hooks", "commit.auto", autohook)
200 repo.ui.setconfig("hooks", "commit.auto", autohook)
201 EOF
201 EOF
202 echo '[extensions]' >> .hg/hgrc
202 echo '[extensions]' >> .hg/hgrc
203 echo 'hookext = hookext.py' >> .hg/hgrc
203 echo 'hookext = hookext.py' >> .hg/hgrc
204
204
205 touch foo
205 touch foo
206 hg add foo
206 hg add foo
207 hg ci -m 'add foo'
207 hg ci -m 'add foo'
208 echo >> foo
208 echo >> foo
209 hg ci --debug -m 'change foo' | sed -e 's/ at .*>/>/'
209 hg ci --debug -m 'change foo' | sed -e 's/ at .*>/>/'
210
210
211 hg showconfig hooks | sed -e 's/ at .*>/>/'
211 hg showconfig hooks | sed -e 's/ at .*>/>/'
212
212
213 exit 0
213 exit 0
General Comments 0
You need to be logged in to leave comments. Login now