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