##// END OF EJS Templates
test python hook configured with python:[file]:[hook] syntax...
Henri Wiechers -
r9014:87c05a78 default
parent child Browse files
Show More
@@ -1,233 +1,251 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 9 echo 'commit = unset HG_LOCAL HG_TAG; python ../printenv.py commit' >> .hg/hgrc
10 10 echo 'commit.b = unset HG_LOCAL HG_TAG; python ../printenv.py commit.b' >> .hg/hgrc
11 11 echo 'precommit = unset HG_LOCAL HG_NODE HG_TAG; python ../printenv.py precommit' >> .hg/hgrc
12 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 'pre-identify = python ../printenv.py pre-identify 1' >> .hg/hgrc
15 15 echo 'pre-cat = python ../printenv.py pre-cat' >> .hg/hgrc
16 16 echo 'post-cat = python ../printenv.py post-cat' >> .hg/hgrc
17 17 echo a > a
18 18 hg add a
19 19 hg commit -m a -d "1000000 0"
20 20
21 21 hg clone . ../b
22 22 cd ../b
23 23
24 24 # changegroup hooks can see env vars
25 25 echo '[hooks]' > .hg/hgrc
26 26 echo 'prechangegroup = python ../printenv.py prechangegroup' >> .hg/hgrc
27 27 echo 'changegroup = python ../printenv.py changegroup' >> .hg/hgrc
28 28 echo 'incoming = python ../printenv.py incoming' >> .hg/hgrc
29 29
30 30 # pretxncommit and commit hooks can see both parents of merge
31 31 cd ../a
32 32 echo b >> a
33 33 hg commit -m a1 -d "1 0"
34 34 hg update -C 0
35 35 echo b > b
36 36 hg add b
37 37 hg commit -m b -d '1 0'
38 38 hg merge 1
39 39 hg commit -m merge -d '2 0'
40 40
41 41 # test generic hooks
42 42 hg id
43 43 hg cat b
44 44
45 45 cd ../b
46 46 hg pull ../a
47 47
48 48 # tag hooks can see env vars
49 49 cd ../a
50 50 echo 'pretag = python ../printenv.py pretag' >> .hg/hgrc
51 51 echo 'tag = unset HG_PARENT1 HG_PARENT2; python ../printenv.py tag' >> .hg/hgrc
52 52 hg tag -d '3 0' a
53 53 hg tag -l la
54 54
55 55 # pretag hook can forbid tagging
56 56 echo 'pretag.forbid = python ../printenv.py pretag.forbid 1' >> .hg/hgrc
57 57 hg tag -d '4 0' fa
58 58 hg tag -l fla
59 59
60 60 # pretxncommit hook can see changeset, can roll back txn, changeset
61 61 # no more there after
62 62 echo 'pretxncommit.forbid0 = hg tip -q' >> .hg/hgrc
63 63 echo 'pretxncommit.forbid1 = python ../printenv.py pretxncommit.forbid 1' >> .hg/hgrc
64 64 echo z > z
65 65 hg add z
66 66 hg -q tip
67 67 hg commit -m 'fail' -d '4 0'
68 68 hg -q tip
69 69
70 70 # precommit hook can prevent commit
71 71 echo 'precommit.forbid = python ../printenv.py precommit.forbid 1' >> .hg/hgrc
72 72 hg commit -m 'fail' -d '4 0'
73 73 hg -q tip
74 74
75 75 # preupdate hook can prevent update
76 76 echo 'preupdate = python ../printenv.py preupdate' >> .hg/hgrc
77 77 hg update 1
78 78
79 79 # update hook
80 80 echo 'update = python ../printenv.py update' >> .hg/hgrc
81 81 hg update
82 82
83 83 # prechangegroup hook can prevent incoming changes
84 84 cd ../b
85 85 hg -q tip
86 86 echo '[hooks]' > .hg/hgrc
87 87 echo 'prechangegroup.forbid = python ../printenv.py prechangegroup.forbid 1' >> .hg/hgrc
88 88 hg pull ../a
89 89
90 90 # pretxnchangegroup hook can see incoming changes, can roll back txn,
91 91 # incoming changes no longer there after
92 92 echo '[hooks]' > .hg/hgrc
93 93 echo 'pretxnchangegroup.forbid0 = hg tip -q' >> .hg/hgrc
94 94 echo 'pretxnchangegroup.forbid1 = python ../printenv.py pretxnchangegroup.forbid 1' >> .hg/hgrc
95 95 hg pull ../a
96 96 hg -q tip
97 97
98 98 # outgoing hooks can see env vars
99 99 rm .hg/hgrc
100 100 echo '[hooks]' > ../a/.hg/hgrc
101 101 echo 'preoutgoing = python ../printenv.py preoutgoing' >> ../a/.hg/hgrc
102 102 echo 'outgoing = python ../printenv.py outgoing' >> ../a/.hg/hgrc
103 103 hg pull ../a
104 104 hg rollback
105 105
106 106 # preoutgoing hook can prevent outgoing changes
107 107 echo 'preoutgoing.forbid = python ../printenv.py preoutgoing.forbid 1' >> ../a/.hg/hgrc
108 108 hg pull ../a
109 109
110 110 # outgoing hooks work for local clones
111 111 cd ..
112 112 echo '[hooks]' > a/.hg/hgrc
113 113 echo 'preoutgoing = python ../printenv.py preoutgoing' >> a/.hg/hgrc
114 114 echo 'outgoing = python ../printenv.py outgoing' >> a/.hg/hgrc
115 115 hg clone a c
116 116 rm -rf c
117 117
118 118 # preoutgoing hook can prevent outgoing changes for local clones
119 119 echo 'preoutgoing.forbid = python ../printenv.py preoutgoing.forbid 1' >> a/.hg/hgrc
120 120 hg clone a zzz
121 121 cd b
122 122
123 123 cat > hooktests.py <<EOF
124 124 from mercurial import util
125 125
126 126 uncallable = 0
127 127
128 128 def printargs(args):
129 129 args.pop('ui', None)
130 130 args.pop('repo', None)
131 131 a = list(args.items())
132 132 a.sort()
133 133 print 'hook args:'
134 134 for k, v in a:
135 135 print ' ', k, v
136 136
137 137 def passhook(**args):
138 138 printargs(args)
139 139
140 140 def failhook(**args):
141 141 printargs(args)
142 142 return True
143 143
144 144 class LocalException(Exception):
145 145 pass
146 146
147 147 def raisehook(**args):
148 148 raise LocalException('exception from hook')
149 149
150 150 def aborthook(**args):
151 151 raise util.Abort('raise abort from hook')
152 152
153 153 def brokenhook(**args):
154 154 return 1 + {}
155 155
156 156 class container:
157 157 unreachable = 1
158 158 EOF
159 159
160 160 echo '# test python hooks'
161 161 PYTHONPATH="`pwd`:$PYTHONPATH"
162 162 export PYTHONPATH
163 163
164 164 echo '[hooks]' > ../a/.hg/hgrc
165 165 echo 'preoutgoing.broken = python:hooktests.brokenhook' >> ../a/.hg/hgrc
166 166 hg pull ../a 2>&1 | grep 'raised an exception'
167 167
168 168 echo '[hooks]' > ../a/.hg/hgrc
169 169 echo 'preoutgoing.raise = python:hooktests.raisehook' >> ../a/.hg/hgrc
170 170 hg pull ../a 2>&1 | grep 'raised an exception'
171 171
172 172 echo '[hooks]' > ../a/.hg/hgrc
173 173 echo 'preoutgoing.abort = python:hooktests.aborthook' >> ../a/.hg/hgrc
174 174 hg pull ../a
175 175
176 176 echo '[hooks]' > ../a/.hg/hgrc
177 177 echo 'preoutgoing.fail = python:hooktests.failhook' >> ../a/.hg/hgrc
178 178 hg pull ../a
179 179
180 180 echo '[hooks]' > ../a/.hg/hgrc
181 181 echo 'preoutgoing.uncallable = python:hooktests.uncallable' >> ../a/.hg/hgrc
182 182 hg pull ../a
183 183
184 184 echo '[hooks]' > ../a/.hg/hgrc
185 185 echo 'preoutgoing.nohook = python:hooktests.nohook' >> ../a/.hg/hgrc
186 186 hg pull ../a
187 187
188 188 echo '[hooks]' > ../a/.hg/hgrc
189 189 echo 'preoutgoing.nomodule = python:nomodule' >> ../a/.hg/hgrc
190 190 hg pull ../a
191 191
192 192 echo '[hooks]' > ../a/.hg/hgrc
193 193 echo 'preoutgoing.badmodule = python:nomodule.nowhere' >> ../a/.hg/hgrc
194 194 hg pull ../a
195 195
196 196 echo '[hooks]' > ../a/.hg/hgrc
197 197 echo 'preoutgoing.unreachable = python:hooktests.container.unreachable' >> ../a/.hg/hgrc
198 198 hg pull ../a
199 199
200 200 echo '[hooks]' > ../a/.hg/hgrc
201 201 echo 'preoutgoing.pass = python:hooktests.passhook' >> ../a/.hg/hgrc
202 202 hg pull ../a
203 203
204 204 echo '# make sure --traceback works'
205 205 echo '[hooks]' > .hg/hgrc
206 206 echo 'commit.abort = python:hooktests.aborthook' >> .hg/hgrc
207 207
208 208 echo a >> a
209 209 hg --traceback commit -A -m a 2>&1 | grep '^Traceback'
210 210
211 211 cd ..
212 212 hg init c
213 213 cd c
214 214
215 215 cat > hookext.py <<EOF
216 216 def autohook(**args):
217 217 print "Automatically installed hook"
218 218
219 219 def reposetup(ui, repo):
220 220 repo.ui.setconfig("hooks", "commit.auto", autohook)
221 221 EOF
222 222 echo '[extensions]' >> .hg/hgrc
223 223 echo 'hookext = hookext.py' >> .hg/hgrc
224 224
225 225 touch foo
226 226 hg add foo
227 227 hg ci -m 'add foo'
228 228 echo >> foo
229 229 hg ci --debug -m 'change foo' | sed -e 's/ at .*>/>/'
230 230
231 231 hg showconfig hooks | sed -e 's/ at .*>/>/'
232 232
233 echo '# test python hook configured with python:[file]:[hook] syntax'
234 cd ..
235 mkdir d
236 cd d
237 hg init repo
238 mkdir hooks
239
240 cd hooks
241 cat > testhooks.py <<EOF
242 def testhook(**args):
243 print 'hook works'
244 EOF
245 echo '[hooks]' > ../repo/.hg/hgrc
246 echo "pre-commit.test = python:`pwd`/testhooks.py:testhook" >> ../repo/.hg/hgrc
247
248 cd ../repo
249 hg commit
250
233 251 exit 0
@@ -1,162 +1,165 b''
1 1 precommit hook: HG_PARENT1=0000000000000000000000000000000000000000
2 2 pretxncommit hook: HG_NODE=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b HG_PARENT1=0000000000000000000000000000000000000000 HG_PENDING=true
3 3 0:29b62aeb769f
4 4 commit hook: HG_NODE=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b HG_PARENT1=0000000000000000000000000000000000000000
5 5 commit.b hook: HG_NODE=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b HG_PARENT1=0000000000000000000000000000000000000000
6 6 updating working directory
7 7 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
8 8 precommit hook: HG_PARENT1=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b
9 9 pretxncommit hook: HG_NODE=b702efe9688826e3a91283852b328b84dbf37bc2 HG_PARENT1=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b HG_PENDING=true
10 10 1:b702efe96888
11 11 commit hook: HG_NODE=b702efe9688826e3a91283852b328b84dbf37bc2 HG_PARENT1=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b
12 12 commit.b hook: HG_NODE=b702efe9688826e3a91283852b328b84dbf37bc2 HG_PARENT1=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b
13 13 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
14 14 precommit hook: HG_PARENT1=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b
15 15 pretxncommit hook: HG_NODE=1324a5531bac09b329c3845d35ae6a7526874edb HG_PARENT1=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b HG_PENDING=true
16 16 2:1324a5531bac
17 17 commit hook: HG_NODE=1324a5531bac09b329c3845d35ae6a7526874edb HG_PARENT1=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b
18 18 commit.b hook: HG_NODE=1324a5531bac09b329c3845d35ae6a7526874edb HG_PARENT1=29b62aeb769fdf78d8d9c5f28b017f76d7ef824b
19 19 created new head
20 20 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
21 21 (branch merge, don't forget to commit)
22 22 precommit hook: HG_PARENT1=1324a5531bac09b329c3845d35ae6a7526874edb HG_PARENT2=b702efe9688826e3a91283852b328b84dbf37bc2
23 23 pretxncommit hook: HG_NODE=4c52fb2e402287dd5dc052090682536c8406c321 HG_PARENT1=1324a5531bac09b329c3845d35ae6a7526874edb HG_PARENT2=b702efe9688826e3a91283852b328b84dbf37bc2 HG_PENDING=true
24 24 3:4c52fb2e4022
25 25 commit hook: HG_NODE=4c52fb2e402287dd5dc052090682536c8406c321 HG_PARENT1=1324a5531bac09b329c3845d35ae6a7526874edb HG_PARENT2=b702efe9688826e3a91283852b328b84dbf37bc2
26 26 commit.b hook: HG_NODE=4c52fb2e402287dd5dc052090682536c8406c321 HG_PARENT1=1324a5531bac09b329c3845d35ae6a7526874edb HG_PARENT2=b702efe9688826e3a91283852b328b84dbf37bc2
27 27 pre-identify hook: HG_ARGS=id
28 28 warning: pre-identify hook exited with status 1
29 29 pre-cat hook: HG_ARGS=cat b
30 30 post-cat hook: HG_ARGS=cat b HG_RESULT=0
31 31 b
32 32 prechangegroup hook: HG_SOURCE=pull HG_URL=file:
33 33 changegroup hook: HG_NODE=b702efe9688826e3a91283852b328b84dbf37bc2 HG_SOURCE=pull HG_URL=file:
34 34 incoming hook: HG_NODE=b702efe9688826e3a91283852b328b84dbf37bc2 HG_SOURCE=pull HG_URL=file:
35 35 incoming hook: HG_NODE=1324a5531bac09b329c3845d35ae6a7526874edb HG_SOURCE=pull HG_URL=file:
36 36 incoming hook: HG_NODE=4c52fb2e402287dd5dc052090682536c8406c321 HG_SOURCE=pull HG_URL=file:
37 37 pulling from ../a
38 38 searching for changes
39 39 adding changesets
40 40 adding manifests
41 41 adding file changes
42 42 added 3 changesets with 2 changes to 2 files
43 43 (run 'hg update' to get a working copy)
44 44 pretag hook: HG_LOCAL=0 HG_NODE=4c52fb2e402287dd5dc052090682536c8406c321 HG_TAG=a
45 45 precommit hook: HG_PARENT1=4c52fb2e402287dd5dc052090682536c8406c321
46 46 pretxncommit hook: HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_PARENT1=4c52fb2e402287dd5dc052090682536c8406c321 HG_PENDING=true
47 47 4:8ea2ef7ad3e8
48 48 commit hook: HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_PARENT1=4c52fb2e402287dd5dc052090682536c8406c321
49 49 commit.b hook: HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_PARENT1=4c52fb2e402287dd5dc052090682536c8406c321
50 50 tag hook: HG_LOCAL=0 HG_NODE=4c52fb2e402287dd5dc052090682536c8406c321 HG_TAG=a
51 51 pretag hook: HG_LOCAL=1 HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_TAG=la
52 52 tag hook: HG_LOCAL=1 HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_TAG=la
53 53 pretag hook: HG_LOCAL=0 HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_TAG=fa
54 54 pretag.forbid hook: HG_LOCAL=0 HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_TAG=fa
55 55 abort: pretag.forbid hook exited with status 1
56 56 pretag hook: HG_LOCAL=1 HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_TAG=fla
57 57 pretag.forbid hook: HG_LOCAL=1 HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_TAG=fla
58 58 abort: pretag.forbid hook exited with status 1
59 59 4:8ea2ef7ad3e8
60 60 precommit hook: HG_PARENT1=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198
61 61 pretxncommit hook: HG_NODE=fad284daf8c032148abaffcd745dafeceefceb61 HG_PARENT1=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_PENDING=true
62 62 5:fad284daf8c0
63 63 5:fad284daf8c0
64 64 pretxncommit.forbid hook: HG_NODE=fad284daf8c032148abaffcd745dafeceefceb61 HG_PARENT1=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_PENDING=true
65 65 transaction abort!
66 66 rollback completed
67 67 abort: pretxncommit.forbid1 hook exited with status 1
68 68 4:8ea2ef7ad3e8
69 69 precommit hook: HG_PARENT1=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198
70 70 precommit.forbid hook: HG_PARENT1=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198
71 71 abort: precommit.forbid hook exited with status 1
72 72 4:8ea2ef7ad3e8
73 73 preupdate hook: HG_PARENT1=b702efe96888
74 74 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
75 75 preupdate hook: HG_PARENT1=8ea2ef7ad3e8
76 76 update hook: HG_ERROR=0 HG_PARENT1=8ea2ef7ad3e8
77 77 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
78 78 3:4c52fb2e4022
79 79 prechangegroup.forbid hook: HG_SOURCE=pull HG_URL=file:
80 80 pulling from ../a
81 81 searching for changes
82 82 abort: prechangegroup.forbid hook exited with status 1
83 83 4:8ea2ef7ad3e8
84 84 pretxnchangegroup.forbid hook: HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_PENDING=true 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 1 changesets with 1 changes to 1 files
91 91 transaction abort!
92 92 rollback completed
93 93 abort: pretxnchangegroup.forbid1 hook exited with status 1
94 94 3:4c52fb2e4022
95 95 preoutgoing hook: HG_SOURCE=pull
96 96 outgoing hook: HG_NODE=8ea2ef7ad3e8cac946c72f1e0c79d6aebc301198 HG_SOURCE=pull
97 97 pulling from ../a
98 98 searching for changes
99 99 adding changesets
100 100 adding manifests
101 101 adding file changes
102 102 added 1 changesets with 1 changes to 1 files
103 103 (run 'hg update' to get a working copy)
104 104 rolling back last transaction
105 105 preoutgoing hook: HG_SOURCE=pull
106 106 preoutgoing.forbid hook: HG_SOURCE=pull
107 107 pulling from ../a
108 108 searching for changes
109 109 abort: preoutgoing.forbid hook exited with status 1
110 110 preoutgoing hook: HG_SOURCE=clone
111 111 outgoing hook: HG_NODE=0000000000000000000000000000000000000000 HG_SOURCE=clone
112 112 updating working directory
113 113 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
114 114 preoutgoing hook: HG_SOURCE=clone
115 115 preoutgoing.forbid hook: HG_SOURCE=clone
116 116 abort: preoutgoing.forbid hook exited with status 1
117 117 # test python hooks
118 118 error: preoutgoing.broken hook raised an exception: unsupported operand type(s) for +: 'int' and 'dict'
119 119 error: preoutgoing.raise hook raised an exception: exception from hook
120 120 pulling from ../a
121 121 searching for changes
122 122 error: preoutgoing.abort hook failed: raise abort from hook
123 123 abort: raise abort from hook
124 124 pulling from ../a
125 125 searching for changes
126 126 hook args:
127 127 hooktype preoutgoing
128 128 source pull
129 129 abort: preoutgoing.fail hook failed
130 130 pulling from ../a
131 131 searching for changes
132 132 abort: preoutgoing.uncallable hook is invalid ("hooktests.uncallable" is not callable)
133 133 pulling from ../a
134 134 searching for changes
135 135 abort: preoutgoing.nohook hook is invalid ("hooktests.nohook" is not defined)
136 136 pulling from ../a
137 137 searching for changes
138 138 abort: preoutgoing.nomodule hook is invalid ("nomodule" not in a module)
139 139 pulling from ../a
140 140 searching for changes
141 141 abort: preoutgoing.badmodule hook is invalid (import of "nomodule" failed)
142 142 pulling from ../a
143 143 searching for changes
144 144 abort: preoutgoing.unreachable hook is invalid (import of "hooktests.container" failed)
145 145 pulling from ../a
146 146 searching for changes
147 147 hook args:
148 148 hooktype preoutgoing
149 149 source pull
150 150 adding changesets
151 151 adding manifests
152 152 adding file changes
153 153 added 1 changesets with 1 changes to 1 files
154 154 (run 'hg update' to get a working copy)
155 155 # make sure --traceback works
156 156 Traceback (most recent call last):
157 157 Automatically installed hook
158 158 foo
159 159 calling hook commit.auto: <function autohook>
160 160 Automatically installed hook
161 161 committed changeset 1:52998019f6252a2b893452765fcb0a47351a5708
162 162 hooks.commit.auto=<function autohook>
163 # test python hook configured with python:[file]:[hook] syntax
164 hook works
165 nothing changed
General Comments 0
You need to be logged in to leave comments. Login now