##// END OF EJS Templates
test-hook: make test compatible with chg...
Saurabh Singh -
r34453:26c879bb default
parent child Browse files
Show More
@@ -1,937 +1,935 b''
1 1 commit hooks can see env vars
2 2 (and post-transaction one are run unlocked)
3 3
4 4
5 5 $ cat > $TESTTMP/txnabort.checkargs.py <<EOF
6 6 > def showargs(ui, repo, hooktype, **kwargs):
7 7 > ui.write('%s Python hook: %s\n' % (hooktype, ','.join(sorted(kwargs))))
8 8 > EOF
9 9
10 10 $ hg init a
11 11 $ cd a
12 12 $ cat > .hg/hgrc <<EOF
13 13 > [hooks]
14 14 > commit = sh -c "HG_LOCAL= HG_TAG= printenv.py commit"
15 15 > commit.b = sh -c "HG_LOCAL= HG_TAG= printenv.py commit.b"
16 16 > precommit = sh -c "HG_LOCAL= HG_NODE= HG_TAG= printenv.py precommit"
17 17 > pretxncommit = sh -c "HG_LOCAL= HG_TAG= printenv.py pretxncommit"
18 18 > pretxncommit.tip = hg -q tip
19 19 > pre-identify = sh -c "printenv.py pre-identify 1"
20 20 > pre-cat = sh -c "printenv.py pre-cat"
21 21 > post-cat = sh -c "printenv.py post-cat"
22 22 > pretxnopen = sh -c "HG_LOCAL= HG_TAG= printenv.py pretxnopen"
23 23 > pretxnclose = sh -c "HG_LOCAL= HG_TAG= printenv.py pretxnclose"
24 24 > txnclose = sh -c "HG_LOCAL= HG_TAG= printenv.py txnclose"
25 25 > txnabort.0 = python:$TESTTMP/txnabort.checkargs.py:showargs
26 26 > txnabort.1 = sh -c "HG_LOCAL= HG_TAG= printenv.py txnabort"
27 27 > txnclose.checklock = sh -c "hg debuglock > /dev/null"
28 28 > EOF
29 29 $ echo a > a
30 30 $ hg add a
31 31 $ hg commit -m a
32 32 precommit hook: HG_HOOKNAME=precommit HG_HOOKTYPE=precommit HG_PARENT1=0000000000000000000000000000000000000000
33 33 pretxnopen hook: HG_HOOKNAME=pretxnopen HG_HOOKTYPE=pretxnopen HG_TXNID=TXN:$ID$ HG_TXNNAME=commit
34 34 pretxncommit hook: HG_HOOKNAME=pretxncommit HG_HOOKTYPE=pretxncommit HG_NODE=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b HG_PARENT1=0000000000000000000000000000000000000000 HG_PENDING=$TESTTMP/a
35 35 0:cb9a9f314b8b
36 36 pretxnclose hook: HG_HOOKNAME=pretxnclose HG_HOOKTYPE=pretxnclose HG_PENDING=$TESTTMP/a HG_PHASES_MOVED=1 HG_TXNID=TXN:$ID$ HG_TXNNAME=commit
37 37 txnclose hook: HG_HOOKNAME=txnclose HG_HOOKTYPE=txnclose HG_PHASES_MOVED=1 HG_TXNID=TXN:$ID$ HG_TXNNAME=commit
38 38 commit hook: HG_HOOKNAME=commit HG_HOOKTYPE=commit HG_NODE=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b HG_PARENT1=0000000000000000000000000000000000000000
39 39 commit.b hook: HG_HOOKNAME=commit.b HG_HOOKTYPE=commit HG_NODE=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b HG_PARENT1=0000000000000000000000000000000000000000
40 40
41 41 $ hg clone . ../b
42 42 updating to branch default
43 43 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
44 44 $ cd ../b
45 45
46 46 changegroup hooks can see env vars
47 47
48 48 $ cat > .hg/hgrc <<EOF
49 49 > [hooks]
50 50 > prechangegroup = sh -c "printenv.py prechangegroup"
51 51 > changegroup = sh -c "printenv.py changegroup"
52 52 > incoming = sh -c "printenv.py incoming"
53 53 > EOF
54 54
55 55 pretxncommit and commit hooks can see both parents of merge
56 56
57 57 $ cd ../a
58 58 $ echo b >> a
59 59 $ hg commit -m a1 -d "1 0"
60 60 precommit hook: HG_HOOKNAME=precommit HG_HOOKTYPE=precommit HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
61 61 pretxnopen hook: HG_HOOKNAME=pretxnopen HG_HOOKTYPE=pretxnopen HG_TXNID=TXN:$ID$ HG_TXNNAME=commit
62 62 pretxncommit hook: HG_HOOKNAME=pretxncommit HG_HOOKTYPE=pretxncommit HG_NODE=ab228980c14deea8b9555d91c9581127383e40fd HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b HG_PENDING=$TESTTMP/a
63 63 1:ab228980c14d
64 64 pretxnclose hook: HG_HOOKNAME=pretxnclose HG_HOOKTYPE=pretxnclose HG_PENDING=$TESTTMP/a HG_TXNID=TXN:$ID$ HG_TXNNAME=commit
65 65 txnclose hook: HG_HOOKNAME=txnclose HG_HOOKTYPE=txnclose HG_TXNID=TXN:$ID$ HG_TXNNAME=commit
66 66 commit hook: HG_HOOKNAME=commit HG_HOOKTYPE=commit HG_NODE=ab228980c14deea8b9555d91c9581127383e40fd HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
67 67 commit.b hook: HG_HOOKNAME=commit.b HG_HOOKTYPE=commit HG_NODE=ab228980c14deea8b9555d91c9581127383e40fd HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
68 68 $ hg update -C 0
69 69 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
70 70 $ echo b > b
71 71 $ hg add b
72 72 $ hg commit -m b -d '1 0'
73 73 precommit hook: HG_HOOKNAME=precommit HG_HOOKTYPE=precommit HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
74 74 pretxnopen hook: HG_HOOKNAME=pretxnopen HG_HOOKTYPE=pretxnopen HG_TXNID=TXN:$ID$ HG_TXNNAME=commit
75 75 pretxncommit hook: HG_HOOKNAME=pretxncommit HG_HOOKTYPE=pretxncommit HG_NODE=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b HG_PENDING=$TESTTMP/a
76 76 2:ee9deb46ab31
77 77 pretxnclose hook: HG_HOOKNAME=pretxnclose HG_HOOKTYPE=pretxnclose HG_PENDING=$TESTTMP/a HG_TXNID=TXN:$ID$ HG_TXNNAME=commit
78 78 created new head
79 79 txnclose hook: HG_HOOKNAME=txnclose HG_HOOKTYPE=txnclose HG_TXNID=TXN:$ID$ HG_TXNNAME=commit
80 80 commit hook: HG_HOOKNAME=commit HG_HOOKTYPE=commit HG_NODE=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
81 81 commit.b hook: HG_HOOKNAME=commit.b HG_HOOKTYPE=commit HG_NODE=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
82 82 $ hg merge 1
83 83 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
84 84 (branch merge, don't forget to commit)
85 85 $ hg commit -m merge -d '2 0'
86 86 precommit hook: HG_HOOKNAME=precommit HG_HOOKTYPE=precommit HG_PARENT1=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT2=ab228980c14deea8b9555d91c9581127383e40fd
87 87 pretxnopen hook: HG_HOOKNAME=pretxnopen HG_HOOKTYPE=pretxnopen HG_TXNID=TXN:$ID$ HG_TXNNAME=commit
88 88 pretxncommit hook: HG_HOOKNAME=pretxncommit HG_HOOKTYPE=pretxncommit HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PARENT1=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT2=ab228980c14deea8b9555d91c9581127383e40fd HG_PENDING=$TESTTMP/a
89 89 3:07f3376c1e65
90 90 pretxnclose hook: HG_HOOKNAME=pretxnclose HG_HOOKTYPE=pretxnclose HG_PENDING=$TESTTMP/a HG_TXNID=TXN:$ID$ HG_TXNNAME=commit
91 91 txnclose hook: HG_HOOKNAME=txnclose HG_HOOKTYPE=txnclose HG_TXNID=TXN:$ID$ HG_TXNNAME=commit
92 92 commit hook: HG_HOOKNAME=commit HG_HOOKTYPE=commit HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PARENT1=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT2=ab228980c14deea8b9555d91c9581127383e40fd
93 93 commit.b hook: HG_HOOKNAME=commit.b HG_HOOKTYPE=commit HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PARENT1=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT2=ab228980c14deea8b9555d91c9581127383e40fd
94 94
95 95 test generic hooks
96 96
97 97 $ hg id
98 98 pre-identify hook: HG_ARGS=id HG_HOOKNAME=pre-identify HG_HOOKTYPE=pre-identify HG_OPTS={'bookmarks': None, 'branch': None, 'id': None, 'insecure': None, 'num': None, 'remotecmd': '', 'rev': '', 'ssh': '', 'tags': None, 'template': ''} HG_PATS=[]
99 99 abort: pre-identify hook exited with status 1
100 100 [255]
101 101 $ hg cat b
102 102 pre-cat hook: HG_ARGS=cat b HG_HOOKNAME=pre-cat HG_HOOKTYPE=pre-cat HG_OPTS={'decode': None, 'exclude': [], 'include': [], 'output': '', 'rev': '', 'template': ''} HG_PATS=['b']
103 103 b
104 104 post-cat hook: HG_ARGS=cat b HG_HOOKNAME=post-cat HG_HOOKTYPE=post-cat HG_OPTS={'decode': None, 'exclude': [], 'include': [], 'output': '', 'rev': '', 'template': ''} HG_PATS=['b'] HG_RESULT=0
105 105
106 106 $ cd ../b
107 107 $ hg pull ../a
108 108 pulling from ../a
109 109 searching for changes
110 110 prechangegroup hook: HG_HOOKNAME=prechangegroup HG_HOOKTYPE=prechangegroup HG_SOURCE=pull HG_TXNID=TXN:$ID$ HG_URL=file:$TESTTMP/a
111 111 adding changesets
112 112 adding manifests
113 113 adding file changes
114 114 added 3 changesets with 2 changes to 2 files
115 115 changegroup hook: HG_HOOKNAME=changegroup HG_HOOKTYPE=changegroup HG_NODE=ab228980c14deea8b9555d91c9581127383e40fd HG_NODE_LAST=07f3376c1e655977439df2a814e3cc14b27abac2 HG_SOURCE=pull HG_TXNID=TXN:$ID$ HG_URL=file:$TESTTMP/a
116 116 incoming hook: HG_HOOKNAME=incoming HG_HOOKTYPE=incoming HG_NODE=ab228980c14deea8b9555d91c9581127383e40fd HG_SOURCE=pull HG_TXNID=TXN:$ID$ HG_URL=file:$TESTTMP/a
117 117 incoming hook: HG_HOOKNAME=incoming HG_HOOKTYPE=incoming HG_NODE=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_SOURCE=pull HG_TXNID=TXN:$ID$ HG_URL=file:$TESTTMP/a
118 118 incoming hook: HG_HOOKNAME=incoming HG_HOOKTYPE=incoming HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_SOURCE=pull HG_TXNID=TXN:$ID$ HG_URL=file:$TESTTMP/a
119 119 (run 'hg update' to get a working copy)
120 120
121 121 tag hooks can see env vars
122 122
123 123 $ cd ../a
124 124 $ cat >> .hg/hgrc <<EOF
125 125 > pretag = sh -c "printenv.py pretag"
126 126 > tag = sh -c "HG_PARENT1= HG_PARENT2= printenv.py tag"
127 127 > EOF
128 128 $ hg tag -d '3 0' a
129 129 pretag hook: HG_HOOKNAME=pretag HG_HOOKTYPE=pretag HG_LOCAL=0 HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_TAG=a
130 130 precommit hook: HG_HOOKNAME=precommit HG_HOOKTYPE=precommit HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2
131 131 pretxnopen hook: HG_HOOKNAME=pretxnopen HG_HOOKTYPE=pretxnopen HG_TXNID=TXN:$ID$ HG_TXNNAME=commit
132 132 pretxncommit hook: HG_HOOKNAME=pretxncommit HG_HOOKTYPE=pretxncommit HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PENDING=$TESTTMP/a
133 133 4:539e4b31b6dc
134 134 pretxnclose hook: HG_HOOKNAME=pretxnclose HG_HOOKTYPE=pretxnclose HG_PENDING=$TESTTMP/a HG_TXNID=TXN:$ID$ HG_TXNNAME=commit
135 135 tag hook: HG_HOOKNAME=tag HG_HOOKTYPE=tag HG_LOCAL=0 HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_TAG=a
136 136 txnclose hook: HG_HOOKNAME=txnclose HG_HOOKTYPE=txnclose HG_TXNID=TXN:$ID$ HG_TXNNAME=commit
137 137 commit hook: HG_HOOKNAME=commit HG_HOOKTYPE=commit HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2
138 138 commit.b hook: HG_HOOKNAME=commit.b HG_HOOKTYPE=commit HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2
139 139 $ hg tag -l la
140 140 pretag hook: HG_HOOKNAME=pretag HG_HOOKTYPE=pretag HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=la
141 141 tag hook: HG_HOOKNAME=tag HG_HOOKTYPE=tag HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=la
142 142
143 143 pretag hook can forbid tagging
144 144
145 145 $ cat >> .hg/hgrc <<EOF
146 146 > pretag.forbid = sh -c "printenv.py pretag.forbid 1"
147 147 > EOF
148 148 $ hg tag -d '4 0' fa
149 149 pretag hook: HG_HOOKNAME=pretag HG_HOOKTYPE=pretag HG_LOCAL=0 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fa
150 150 pretag.forbid hook: HG_HOOKNAME=pretag.forbid HG_HOOKTYPE=pretag HG_LOCAL=0 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fa
151 151 abort: pretag.forbid hook exited with status 1
152 152 [255]
153 153 $ hg tag -l fla
154 154 pretag hook: HG_HOOKNAME=pretag HG_HOOKTYPE=pretag HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fla
155 155 pretag.forbid hook: HG_HOOKNAME=pretag.forbid HG_HOOKTYPE=pretag HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fla
156 156 abort: pretag.forbid hook exited with status 1
157 157 [255]
158 158
159 159 pretxncommit hook can see changeset, can roll back txn, changeset no
160 160 more there after
161 161
162 162 $ cat >> .hg/hgrc <<EOF
163 163 > pretxncommit.forbid0 = sh -c "hg tip -q"
164 164 > pretxncommit.forbid1 = sh -c "printenv.py pretxncommit.forbid 1"
165 165 > EOF
166 166 $ echo z > z
167 167 $ hg add z
168 168 $ hg -q tip
169 169 4:539e4b31b6dc
170 170 $ hg commit -m 'fail' -d '4 0'
171 171 precommit hook: HG_HOOKNAME=precommit HG_HOOKTYPE=precommit HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
172 172 pretxnopen hook: HG_HOOKNAME=pretxnopen HG_HOOKTYPE=pretxnopen HG_TXNID=TXN:$ID$ HG_TXNNAME=commit
173 173 pretxncommit hook: HG_HOOKNAME=pretxncommit HG_HOOKTYPE=pretxncommit HG_NODE=6f611f8018c10e827fee6bd2bc807f937e761567 HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PENDING=$TESTTMP/a
174 174 5:6f611f8018c1
175 175 5:6f611f8018c1
176 176 pretxncommit.forbid hook: HG_HOOKNAME=pretxncommit.forbid1 HG_HOOKTYPE=pretxncommit HG_NODE=6f611f8018c10e827fee6bd2bc807f937e761567 HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PENDING=$TESTTMP/a
177 177 transaction abort!
178 178 txnabort Python hook: txnid,txnname
179 179 txnabort hook: HG_HOOKNAME=txnabort.1 HG_HOOKTYPE=txnabort HG_TXNID=TXN:$ID$ HG_TXNNAME=commit
180 180 rollback completed
181 181 abort: pretxncommit.forbid1 hook exited with status 1
182 182 [255]
183 183 $ hg -q tip
184 184 4:539e4b31b6dc
185 185
186 186 (Check that no 'changelog.i.a' file were left behind)
187 187
188 188 $ ls -1 .hg/store/
189 189 00changelog.i
190 190 00manifest.i
191 191 data
192 192 fncache
193 193 journal.phaseroots
194 194 phaseroots
195 195 undo
196 196 undo.backup.fncache
197 197 undo.backupfiles
198 198 undo.phaseroots
199 199
200 200
201 201 precommit hook can prevent commit
202 202
203 203 $ cat >> .hg/hgrc <<EOF
204 204 > precommit.forbid = sh -c "printenv.py precommit.forbid 1"
205 205 > EOF
206 206 $ hg commit -m 'fail' -d '4 0'
207 207 precommit hook: HG_HOOKNAME=precommit HG_HOOKTYPE=precommit HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
208 208 precommit.forbid hook: HG_HOOKNAME=precommit.forbid HG_HOOKTYPE=precommit HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
209 209 abort: precommit.forbid hook exited with status 1
210 210 [255]
211 211 $ hg -q tip
212 212 4:539e4b31b6dc
213 213
214 214 preupdate hook can prevent update
215 215
216 216 $ cat >> .hg/hgrc <<EOF
217 217 > preupdate = sh -c "printenv.py preupdate"
218 218 > EOF
219 219 $ hg update 1
220 220 preupdate hook: HG_HOOKNAME=preupdate HG_HOOKTYPE=preupdate HG_PARENT1=ab228980c14d
221 221 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
222 222
223 223 update hook
224 224
225 225 $ cat >> .hg/hgrc <<EOF
226 226 > update = sh -c "printenv.py update"
227 227 > EOF
228 228 $ hg update
229 229 preupdate hook: HG_HOOKNAME=preupdate HG_HOOKTYPE=preupdate HG_PARENT1=539e4b31b6dc
230 230 update hook: HG_ERROR=0 HG_HOOKNAME=update HG_HOOKTYPE=update HG_PARENT1=539e4b31b6dc
231 231 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
232 232
233 233 pushkey hook
234 234
235 235 $ cat >> .hg/hgrc <<EOF
236 236 > pushkey = sh -c "printenv.py pushkey"
237 237 > EOF
238 238 $ cd ../b
239 239 $ hg bookmark -r null foo
240 240 $ hg push -B foo ../a
241 241 pushing to ../a
242 242 searching for changes
243 243 no changes found
244 244 pretxnopen hook: HG_HOOKNAME=pretxnopen HG_HOOKTYPE=pretxnopen HG_TXNID=TXN:$ID$ HG_TXNNAME=push
245 245 pretxnclose hook: HG_BOOKMARK_MOVED=1 HG_BUNDLE2=1 HG_HOOKNAME=pretxnclose HG_HOOKTYPE=pretxnclose HG_PENDING=$TESTTMP/a HG_SOURCE=push HG_TXNID=TXN:$ID$ HG_TXNNAME=push HG_URL=file:$TESTTMP/a
246 246 pushkey hook: HG_HOOKNAME=pushkey HG_HOOKTYPE=pushkey HG_KEY=foo HG_NAMESPACE=bookmarks HG_NEW=0000000000000000000000000000000000000000 HG_RET=1
247 247 txnclose hook: HG_BOOKMARK_MOVED=1 HG_BUNDLE2=1 HG_HOOKNAME=txnclose HG_HOOKTYPE=txnclose HG_SOURCE=push HG_TXNID=TXN:$ID$ HG_TXNNAME=push HG_URL=file:$TESTTMP/a
248 248 exporting bookmark foo
249 249 [1]
250 250 $ cd ../a
251 251
252 252 listkeys hook
253 253
254 254 $ cat >> .hg/hgrc <<EOF
255 255 > listkeys = sh -c "printenv.py listkeys"
256 256 > EOF
257 257 $ hg bookmark -r null bar
258 258 pretxnopen hook: HG_HOOKNAME=pretxnopen HG_HOOKTYPE=pretxnopen HG_TXNID=TXN:$ID$ HG_TXNNAME=bookmark
259 259 pretxnclose hook: HG_BOOKMARK_MOVED=1 HG_HOOKNAME=pretxnclose HG_HOOKTYPE=pretxnclose HG_PENDING=$TESTTMP/a HG_TXNID=TXN:$ID$ HG_TXNNAME=bookmark
260 260 txnclose hook: HG_BOOKMARK_MOVED=1 HG_HOOKNAME=txnclose HG_HOOKTYPE=txnclose HG_TXNID=TXN:$ID$ HG_TXNNAME=bookmark
261 261 $ cd ../b
262 262 $ hg pull -B bar ../a
263 263 pulling from ../a
264 264 listkeys hook: HG_HOOKNAME=listkeys HG_HOOKTYPE=listkeys HG_NAMESPACE=bookmarks HG_VALUES={'bar': '0000000000000000000000000000000000000000', 'foo': '0000000000000000000000000000000000000000'}
265 265 no changes found
266 266 adding remote bookmark bar
267 267 $ cd ../a
268 268
269 269 test that prepushkey can prevent incoming keys
270 270
271 271 $ cat >> .hg/hgrc <<EOF
272 272 > prepushkey = sh -c "printenv.py prepushkey.forbid 1"
273 273 > EOF
274 274 $ cd ../b
275 275 $ hg bookmark -r null baz
276 276 $ hg push -B baz ../a
277 277 pushing to ../a
278 278 searching for changes
279 279 listkeys hook: HG_HOOKNAME=listkeys HG_HOOKTYPE=listkeys HG_NAMESPACE=phases HG_VALUES={'cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b': '1', 'publishing': 'True'}
280 280 listkeys hook: HG_HOOKNAME=listkeys HG_HOOKTYPE=listkeys HG_NAMESPACE=bookmarks HG_VALUES={'bar': '0000000000000000000000000000000000000000', 'foo': '0000000000000000000000000000000000000000'}
281 281 no changes found
282 282 pretxnopen hook: HG_HOOKNAME=pretxnopen HG_HOOKTYPE=pretxnopen HG_TXNID=TXN:$ID$ HG_TXNNAME=push
283 283 prepushkey.forbid hook: HG_BUNDLE2=1 HG_HOOKNAME=prepushkey HG_HOOKTYPE=prepushkey HG_KEY=baz HG_NAMESPACE=bookmarks HG_NEW=0000000000000000000000000000000000000000 HG_SOURCE=push HG_TXNID=TXN:$ID$ HG_URL=file:$TESTTMP/a
284 284 pushkey-abort: prepushkey hook exited with status 1
285 285 abort: exporting bookmark baz failed!
286 286 [255]
287 287 $ cd ../a
288 288
289 289 test that prelistkeys can prevent listing keys
290 290
291 291 $ cat >> .hg/hgrc <<EOF
292 292 > prelistkeys = sh -c "printenv.py prelistkeys.forbid 1"
293 293 > EOF
294 294 $ hg bookmark -r null quux
295 295 pretxnopen hook: HG_HOOKNAME=pretxnopen HG_HOOKTYPE=pretxnopen HG_TXNID=TXN:$ID$ HG_TXNNAME=bookmark
296 296 pretxnclose hook: HG_BOOKMARK_MOVED=1 HG_HOOKNAME=pretxnclose HG_HOOKTYPE=pretxnclose HG_PENDING=$TESTTMP/a HG_TXNID=TXN:$ID$ HG_TXNNAME=bookmark
297 297 txnclose hook: HG_BOOKMARK_MOVED=1 HG_HOOKNAME=txnclose HG_HOOKTYPE=txnclose HG_TXNID=TXN:$ID$ HG_TXNNAME=bookmark
298 298 $ cd ../b
299 299 $ hg pull -B quux ../a
300 300 pulling from ../a
301 301 prelistkeys.forbid hook: HG_HOOKNAME=prelistkeys HG_HOOKTYPE=prelistkeys HG_NAMESPACE=bookmarks
302 302 abort: prelistkeys hook exited with status 1
303 303 [255]
304 304 $ cd ../a
305 305 $ rm .hg/hgrc
306 306
307 307 prechangegroup hook can prevent incoming changes
308 308
309 309 $ cd ../b
310 310 $ hg -q tip
311 311 3:07f3376c1e65
312 312 $ cat > .hg/hgrc <<EOF
313 313 > [hooks]
314 314 > prechangegroup.forbid = sh -c "printenv.py prechangegroup.forbid 1"
315 315 > EOF
316 316 $ hg pull ../a
317 317 pulling from ../a
318 318 searching for changes
319 319 prechangegroup.forbid hook: HG_HOOKNAME=prechangegroup.forbid HG_HOOKTYPE=prechangegroup HG_SOURCE=pull HG_TXNID=TXN:$ID$ HG_URL=file:$TESTTMP/a
320 320 abort: prechangegroup.forbid hook exited with status 1
321 321 [255]
322 322
323 323 pretxnchangegroup hook can see incoming changes, can roll back txn,
324 324 incoming changes no longer there after
325 325
326 326 $ cat > .hg/hgrc <<EOF
327 327 > [hooks]
328 328 > pretxnchangegroup.forbid0 = hg tip -q
329 329 > pretxnchangegroup.forbid1 = sh -c "printenv.py pretxnchangegroup.forbid 1"
330 330 > EOF
331 331 $ hg pull ../a
332 332 pulling from ../a
333 333 searching for changes
334 334 adding changesets
335 335 adding manifests
336 336 adding file changes
337 337 added 1 changesets with 1 changes to 1 files
338 338 4:539e4b31b6dc
339 339 pretxnchangegroup.forbid hook: HG_HOOKNAME=pretxnchangegroup.forbid1 HG_HOOKTYPE=pretxnchangegroup HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_NODE_LAST=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PENDING=$TESTTMP/b HG_SOURCE=pull HG_TXNID=TXN:$ID$ HG_URL=file:$TESTTMP/a
340 340 transaction abort!
341 341 rollback completed
342 342 abort: pretxnchangegroup.forbid1 hook exited with status 1
343 343 [255]
344 344 $ hg -q tip
345 345 3:07f3376c1e65
346 346
347 347 outgoing hooks can see env vars
348 348
349 349 $ rm .hg/hgrc
350 350 $ cat > ../a/.hg/hgrc <<EOF
351 351 > [hooks]
352 352 > preoutgoing = sh -c "printenv.py preoutgoing"
353 353 > outgoing = sh -c "printenv.py outgoing"
354 354 > EOF
355 355 $ hg pull ../a
356 356 pulling from ../a
357 357 searching for changes
358 358 preoutgoing hook: HG_HOOKNAME=preoutgoing HG_HOOKTYPE=preoutgoing HG_SOURCE=pull
359 359 outgoing hook: HG_HOOKNAME=outgoing HG_HOOKTYPE=outgoing HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_SOURCE=pull
360 360 adding changesets
361 361 adding manifests
362 362 adding file changes
363 363 added 1 changesets with 1 changes to 1 files
364 364 adding remote bookmark quux
365 365 (run 'hg update' to get a working copy)
366 366 $ hg rollback
367 367 repository tip rolled back to revision 3 (undo pull)
368 368
369 369 preoutgoing hook can prevent outgoing changes
370 370
371 371 $ cat >> ../a/.hg/hgrc <<EOF
372 372 > preoutgoing.forbid = sh -c "printenv.py preoutgoing.forbid 1"
373 373 > EOF
374 374 $ hg pull ../a
375 375 pulling from ../a
376 376 searching for changes
377 377 preoutgoing hook: HG_HOOKNAME=preoutgoing HG_HOOKTYPE=preoutgoing HG_SOURCE=pull
378 378 preoutgoing.forbid hook: HG_HOOKNAME=preoutgoing.forbid HG_HOOKTYPE=preoutgoing HG_SOURCE=pull
379 379 abort: preoutgoing.forbid hook exited with status 1
380 380 [255]
381 381
382 382 outgoing hooks work for local clones
383 383
384 384 $ cd ..
385 385 $ cat > a/.hg/hgrc <<EOF
386 386 > [hooks]
387 387 > preoutgoing = sh -c "printenv.py preoutgoing"
388 388 > outgoing = sh -c "printenv.py outgoing"
389 389 > EOF
390 390 $ hg clone a c
391 391 preoutgoing hook: HG_HOOKNAME=preoutgoing HG_HOOKTYPE=preoutgoing HG_SOURCE=clone
392 392 outgoing hook: HG_HOOKNAME=outgoing HG_HOOKTYPE=outgoing HG_NODE=0000000000000000000000000000000000000000 HG_SOURCE=clone
393 393 updating to branch default
394 394 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
395 395 $ rm -rf c
396 396
397 397 preoutgoing hook can prevent outgoing changes for local clones
398 398
399 399 $ cat >> a/.hg/hgrc <<EOF
400 400 > preoutgoing.forbid = sh -c "printenv.py preoutgoing.forbid 1"
401 401 > EOF
402 402 $ hg clone a zzz
403 403 preoutgoing hook: HG_HOOKNAME=preoutgoing HG_HOOKTYPE=preoutgoing HG_SOURCE=clone
404 404 preoutgoing.forbid hook: HG_HOOKNAME=preoutgoing.forbid HG_HOOKTYPE=preoutgoing HG_SOURCE=clone
405 405 abort: preoutgoing.forbid hook exited with status 1
406 406 [255]
407 407
408 408 $ cd "$TESTTMP/b"
409 409
410 410 $ cat > hooktests.py <<EOF
411 411 > from __future__ import print_function
412 412 > from mercurial import error
413 413 >
414 414 > uncallable = 0
415 415 >
416 > def printargs(args):
417 > args.pop('ui', None)
418 > args.pop('repo', None)
416 > def printargs(ui, args):
419 417 > a = list(args.items())
420 418 > a.sort()
421 > print('hook args:')
419 > ui.write('hook args:\n')
422 420 > for k, v in a:
423 > print(' ', k, v)
421 > ui.write(' %s %s\n' % (k, v))
424 422 >
425 > def passhook(**args):
426 > printargs(args)
423 > def passhook(ui, repo, **args):
424 > printargs(ui, args)
427 425 >
428 > def failhook(**args):
429 > printargs(args)
426 > def failhook(ui, repo, **args):
427 > printargs(ui, args)
430 428 > return True
431 429 >
432 430 > class LocalException(Exception):
433 431 > pass
434 432 >
435 433 > def raisehook(**args):
436 434 > raise LocalException('exception from hook')
437 435 >
438 436 > def aborthook(**args):
439 437 > raise error.Abort('raise abort from hook')
440 438 >
441 439 > def brokenhook(**args):
442 440 > return 1 + {}
443 441 >
444 442 > def verbosehook(ui, **args):
445 443 > ui.note('verbose output from hook\n')
446 444 >
447 445 > def printtags(ui, repo, **args):
448 > print(sorted(repo.tags()))
446 > ui.write('%s\n' % sorted(repo.tags()))
449 447 >
450 448 > class container:
451 449 > unreachable = 1
452 450 > EOF
453 451
454 452 $ cat > syntaxerror.py << EOF
455 453 > (foo
456 454 > EOF
457 455
458 456 test python hooks
459 457
460 458 #if windows
461 459 $ PYTHONPATH="$TESTTMP/b;$PYTHONPATH"
462 460 #else
463 461 $ PYTHONPATH="$TESTTMP/b:$PYTHONPATH"
464 462 #endif
465 463 $ export PYTHONPATH
466 464
467 465 $ echo '[hooks]' > ../a/.hg/hgrc
468 466 $ echo 'preoutgoing.broken = python:hooktests.brokenhook' >> ../a/.hg/hgrc
469 467 $ hg pull ../a 2>&1 | grep 'raised an exception'
470 468 error: preoutgoing.broken hook raised an exception: unsupported operand type(s) for +: 'int' and 'dict'
471 469
472 470 $ echo '[hooks]' > ../a/.hg/hgrc
473 471 $ echo 'preoutgoing.raise = python:hooktests.raisehook' >> ../a/.hg/hgrc
474 472 $ hg pull ../a 2>&1 | grep 'raised an exception'
475 473 error: preoutgoing.raise hook raised an exception: exception from hook
476 474
477 475 $ echo '[hooks]' > ../a/.hg/hgrc
478 476 $ echo 'preoutgoing.abort = python:hooktests.aborthook' >> ../a/.hg/hgrc
479 477 $ hg pull ../a
480 478 pulling from ../a
481 479 searching for changes
482 480 error: preoutgoing.abort hook failed: raise abort from hook
483 481 abort: raise abort from hook
484 482 [255]
485 483
486 484 $ echo '[hooks]' > ../a/.hg/hgrc
487 485 $ echo 'preoutgoing.fail = python:hooktests.failhook' >> ../a/.hg/hgrc
488 486 $ hg pull ../a
489 487 pulling from ../a
490 488 searching for changes
491 489 hook args:
492 490 hooktype preoutgoing
493 491 source pull
494 492 abort: preoutgoing.fail hook failed
495 493 [255]
496 494
497 495 $ echo '[hooks]' > ../a/.hg/hgrc
498 496 $ echo 'preoutgoing.uncallable = python:hooktests.uncallable' >> ../a/.hg/hgrc
499 497 $ hg pull ../a
500 498 pulling from ../a
501 499 searching for changes
502 500 abort: preoutgoing.uncallable hook is invalid: "hooktests.uncallable" is not callable
503 501 [255]
504 502
505 503 $ echo '[hooks]' > ../a/.hg/hgrc
506 504 $ echo 'preoutgoing.nohook = python:hooktests.nohook' >> ../a/.hg/hgrc
507 505 $ hg pull ../a
508 506 pulling from ../a
509 507 searching for changes
510 508 abort: preoutgoing.nohook hook is invalid: "hooktests.nohook" is not defined
511 509 [255]
512 510
513 511 $ echo '[hooks]' > ../a/.hg/hgrc
514 512 $ echo 'preoutgoing.nomodule = python:nomodule' >> ../a/.hg/hgrc
515 513 $ hg pull ../a
516 514 pulling from ../a
517 515 searching for changes
518 516 abort: preoutgoing.nomodule hook is invalid: "nomodule" not in a module
519 517 [255]
520 518
521 519 $ echo '[hooks]' > ../a/.hg/hgrc
522 520 $ echo 'preoutgoing.badmodule = python:nomodule.nowhere' >> ../a/.hg/hgrc
523 521 $ hg pull ../a
524 522 pulling from ../a
525 523 searching for changes
526 524 abort: preoutgoing.badmodule hook is invalid: import of "nomodule" failed
527 525 (run with --traceback for stack trace)
528 526 [255]
529 527
530 528 $ echo '[hooks]' > ../a/.hg/hgrc
531 529 $ echo 'preoutgoing.unreachable = python:hooktests.container.unreachable' >> ../a/.hg/hgrc
532 530 $ hg pull ../a
533 531 pulling from ../a
534 532 searching for changes
535 533 abort: preoutgoing.unreachable hook is invalid: import of "hooktests.container" failed
536 534 (run with --traceback for stack trace)
537 535 [255]
538 536
539 537 $ echo '[hooks]' > ../a/.hg/hgrc
540 538 $ echo 'preoutgoing.syntaxerror = python:syntaxerror.syntaxerror' >> ../a/.hg/hgrc
541 539 $ hg pull ../a
542 540 pulling from ../a
543 541 searching for changes
544 542 abort: preoutgoing.syntaxerror hook is invalid: import of "syntaxerror" failed
545 543 (run with --traceback for stack trace)
546 544 [255]
547 545
548 546 The second egrep is to filter out lines like ' ^', which are slightly
549 547 different between Python 2.6 and Python 2.7.
550 548 $ hg pull ../a --traceback 2>&1 | egrep -v '^( +File| [_a-zA-Z*(])' | egrep -v '^( )+(\^)?$'
551 549 pulling from ../a
552 550 searching for changes
553 551 exception from first failed import attempt:
554 552 Traceback (most recent call last):
555 553 SyntaxError: * (glob)
556 554 exception from second failed import attempt:
557 555 Traceback (most recent call last):
558 556 ImportError: No module named hgext_syntaxerror
559 557 Traceback (most recent call last):
560 558 HookLoadError: preoutgoing.syntaxerror hook is invalid: import of "syntaxerror" failed
561 559 abort: preoutgoing.syntaxerror hook is invalid: import of "syntaxerror" failed
562 560
563 561 $ echo '[hooks]' > ../a/.hg/hgrc
564 562 $ echo 'preoutgoing.pass = python:hooktests.passhook' >> ../a/.hg/hgrc
565 563 $ hg pull ../a
566 564 pulling from ../a
567 565 searching for changes
568 566 hook args:
569 567 hooktype preoutgoing
570 568 source pull
571 569 adding changesets
572 570 adding manifests
573 571 adding file changes
574 572 added 1 changesets with 1 changes to 1 files
575 573 adding remote bookmark quux
576 574 (run 'hg update' to get a working copy)
577 575
578 576 post- python hooks that fail to *run* don't cause an abort
579 577 $ rm ../a/.hg/hgrc
580 578 $ echo '[hooks]' > .hg/hgrc
581 579 $ echo 'post-pull.broken = python:hooktests.brokenhook' >> .hg/hgrc
582 580 $ hg pull ../a
583 581 pulling from ../a
584 582 searching for changes
585 583 no changes found
586 584 error: post-pull.broken hook raised an exception: unsupported operand type(s) for +: 'int' and 'dict'
587 585 (run with --traceback for stack trace)
588 586
589 587 but post- python hooks that fail to *load* do
590 588 $ echo '[hooks]' > .hg/hgrc
591 589 $ echo 'post-pull.nomodule = python:nomodule' >> .hg/hgrc
592 590 $ hg pull ../a
593 591 pulling from ../a
594 592 searching for changes
595 593 no changes found
596 594 abort: post-pull.nomodule hook is invalid: "nomodule" not in a module
597 595 [255]
598 596
599 597 $ echo '[hooks]' > .hg/hgrc
600 598 $ echo 'post-pull.badmodule = python:nomodule.nowhere' >> .hg/hgrc
601 599 $ hg pull ../a
602 600 pulling from ../a
603 601 searching for changes
604 602 no changes found
605 603 abort: post-pull.badmodule hook is invalid: import of "nomodule" failed
606 604 (run with --traceback for stack trace)
607 605 [255]
608 606
609 607 $ echo '[hooks]' > .hg/hgrc
610 608 $ echo 'post-pull.nohook = python:hooktests.nohook' >> .hg/hgrc
611 609 $ hg pull ../a
612 610 pulling from ../a
613 611 searching for changes
614 612 no changes found
615 613 abort: post-pull.nohook hook is invalid: "hooktests.nohook" is not defined
616 614 [255]
617 615
618 616 make sure --traceback works
619 617
620 618 $ echo '[hooks]' > .hg/hgrc
621 619 $ echo 'commit.abort = python:hooktests.aborthook' >> .hg/hgrc
622 620
623 621 $ echo aa > a
624 622 $ hg --traceback commit -d '0 0' -ma 2>&1 | grep '^Traceback'
625 623 Traceback (most recent call last):
626 624
627 625 $ cd ..
628 626 $ hg init c
629 627 $ cd c
630 628
631 629 $ cat > hookext.py <<EOF
632 > def autohook(**args):
633 > print("Automatically installed hook")
630 > def autohook(ui, **args):
631 > ui.write('Automatically installed hook\n')
634 632 >
635 633 > def reposetup(ui, repo):
636 634 > repo.ui.setconfig("hooks", "commit.auto", autohook)
637 635 > EOF
638 636 $ echo '[extensions]' >> .hg/hgrc
639 637 $ echo 'hookext = hookext.py' >> .hg/hgrc
640 638
641 639 $ touch foo
642 640 $ hg add foo
643 641 $ hg ci -d '0 0' -m 'add foo'
644 642 Automatically installed hook
645 643 $ echo >> foo
646 644 $ hg ci --debug -d '0 0' -m 'change foo'
647 645 committing files:
648 646 foo
649 647 committing manifest
650 648 committing changelog
651 649 updating the branch cache
652 650 committed changeset 1:52998019f6252a2b893452765fcb0a47351a5708
653 651 calling hook commit.auto: hgext_hookext.autohook
654 652 Automatically installed hook
655 653
656 654 $ hg showconfig hooks
657 655 hooks.commit.auto=<function autohook at *> (glob)
658 656
659 657 test python hook configured with python:[file]:[hook] syntax
660 658
661 659 $ cd ..
662 660 $ mkdir d
663 661 $ cd d
664 662 $ hg init repo
665 663 $ mkdir hooks
666 664
667 665 $ cd hooks
668 666 $ cat > testhooks.py <<EOF
669 > def testhook(**args):
670 > print('hook works')
667 > def testhook(ui, **args):
668 > ui.write('hook works\n')
671 669 > EOF
672 670 $ echo '[hooks]' > ../repo/.hg/hgrc
673 671 $ echo "pre-commit.test = python:`pwd`/testhooks.py:testhook" >> ../repo/.hg/hgrc
674 672
675 673 $ cd ../repo
676 674 $ hg commit -d '0 0'
677 675 hook works
678 676 nothing changed
679 677 [1]
680 678
681 679 $ echo '[hooks]' > .hg/hgrc
682 680 $ echo "update.ne = python:`pwd`/nonexistent.py:testhook" >> .hg/hgrc
683 681 $ echo "pre-identify.npmd = python:`pwd`/:no_python_module_dir" >> .hg/hgrc
684 682
685 683 $ hg up null
686 684 loading update.ne hook failed:
687 685 abort: No such file or directory: $TESTTMP/d/repo/nonexistent.py
688 686 [255]
689 687
690 688 $ hg id
691 689 loading pre-identify.npmd hook failed:
692 690 abort: No module named repo!
693 691 [255]
694 692
695 693 $ cd ../../b
696 694
697 695 make sure --traceback works on hook import failure
698 696
699 697 $ cat > importfail.py <<EOF
700 698 > import somebogusmodule
701 699 > # dereference something in the module to force demandimport to load it
702 700 > somebogusmodule.whatever
703 701 > EOF
704 702
705 703 $ echo '[hooks]' > .hg/hgrc
706 704 $ echo 'precommit.importfail = python:importfail.whatever' >> .hg/hgrc
707 705
708 706 $ echo a >> a
709 707 $ hg --traceback commit -ma 2>&1 | egrep -v '^( +File| [a-zA-Z(])'
710 708 exception from first failed import attempt:
711 709 Traceback (most recent call last):
712 710 ImportError: No module named somebogusmodule
713 711 exception from second failed import attempt:
714 712 Traceback (most recent call last):
715 713 ImportError: No module named hgext_importfail
716 714 Traceback (most recent call last):
717 715 HookLoadError: precommit.importfail hook is invalid: import of "importfail" failed
718 716 abort: precommit.importfail hook is invalid: import of "importfail" failed
719 717
720 718 Issue1827: Hooks Update & Commit not completely post operation
721 719
722 720 commit and update hooks should run after command completion. The largefiles
723 721 use demonstrates a recursive wlock, showing the hook doesn't run until the
724 722 final release (and dirstate flush).
725 723
726 724 $ echo '[hooks]' > .hg/hgrc
727 725 $ echo 'commit = hg id' >> .hg/hgrc
728 726 $ echo 'update = hg id' >> .hg/hgrc
729 727 $ echo bb > a
730 728 $ hg ci -ma
731 729 223eafe2750c tip
732 730 $ hg up 0 --config extensions.largefiles=
733 731 The fsmonitor extension is incompatible with the largefiles extension and has been disabled. (fsmonitor !)
734 732 cb9a9f314b8b
735 733 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
736 734
737 735 make sure --verbose (and --quiet/--debug etc.) are propagated to the local ui
738 736 that is passed to pre/post hooks
739 737
740 738 $ echo '[hooks]' > .hg/hgrc
741 739 $ echo 'pre-identify = python:hooktests.verbosehook' >> .hg/hgrc
742 740 $ hg id
743 741 cb9a9f314b8b
744 742 $ hg id --verbose
745 743 calling hook pre-identify: hooktests.verbosehook
746 744 verbose output from hook
747 745 cb9a9f314b8b
748 746
749 747 Ensure hooks can be prioritized
750 748
751 749 $ echo '[hooks]' > .hg/hgrc
752 750 $ echo 'pre-identify.a = python:hooktests.verbosehook' >> .hg/hgrc
753 751 $ echo 'pre-identify.b = python:hooktests.verbosehook' >> .hg/hgrc
754 752 $ echo 'priority.pre-identify.b = 1' >> .hg/hgrc
755 753 $ echo 'pre-identify.c = python:hooktests.verbosehook' >> .hg/hgrc
756 754 $ hg id --verbose
757 755 calling hook pre-identify.b: hooktests.verbosehook
758 756 verbose output from hook
759 757 calling hook pre-identify.a: hooktests.verbosehook
760 758 verbose output from hook
761 759 calling hook pre-identify.c: hooktests.verbosehook
762 760 verbose output from hook
763 761 cb9a9f314b8b
764 762
765 763 new tags must be visible in pretxncommit (issue3210)
766 764
767 765 $ echo 'pretxncommit.printtags = python:hooktests.printtags' >> .hg/hgrc
768 766 $ hg tag -f foo
769 767 ['a', 'foo', 'tip']
770 768
771 769 post-init hooks must not crash (issue4983)
772 770 This also creates the `to` repo for the next test block.
773 771
774 772 $ cd ..
775 773 $ cat << EOF >> hgrc-with-post-init-hook
776 774 > [hooks]
777 775 > post-init = sh -c "printenv.py post-init"
778 776 > EOF
779 777 $ HGRCPATH=hgrc-with-post-init-hook hg init to
780 778 post-init hook: HG_ARGS=init to HG_HOOKNAME=post-init HG_HOOKTYPE=post-init HG_OPTS={'insecure': None, 'remotecmd': '', 'ssh': ''} HG_PATS=['to'] HG_RESULT=0
781 779
782 780 new commits must be visible in pretxnchangegroup (issue3428)
783 781
784 782 $ echo '[hooks]' >> to/.hg/hgrc
785 783 $ echo 'prechangegroup = hg --traceback tip' >> to/.hg/hgrc
786 784 $ echo 'pretxnchangegroup = hg --traceback tip' >> to/.hg/hgrc
787 785 $ echo a >> to/a
788 786 $ hg --cwd to ci -Ama
789 787 adding a
790 788 $ hg clone to from
791 789 updating to branch default
792 790 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
793 791 $ echo aa >> from/a
794 792 $ hg --cwd from ci -mb
795 793 $ hg --cwd from push
796 794 pushing to $TESTTMP/to (glob)
797 795 searching for changes
798 796 changeset: 0:cb9a9f314b8b
799 797 tag: tip
800 798 user: test
801 799 date: Thu Jan 01 00:00:00 1970 +0000
802 800 summary: a
803 801
804 802 adding changesets
805 803 adding manifests
806 804 adding file changes
807 805 added 1 changesets with 1 changes to 1 files
808 806 changeset: 1:9836a07b9b9d
809 807 tag: tip
810 808 user: test
811 809 date: Thu Jan 01 00:00:00 1970 +0000
812 810 summary: b
813 811
814 812
815 813 pretxnclose hook failure should abort the transaction
816 814
817 815 $ hg init txnfailure
818 816 $ cd txnfailure
819 817 $ touch a && hg commit -Aqm a
820 818 $ cat >> .hg/hgrc <<EOF
821 819 > [hooks]
822 820 > pretxnclose.error = exit 1
823 821 > EOF
824 822 $ hg strip -r 0 --config extensions.strip=
825 823 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
826 824 saved backup bundle to * (glob)
827 825 transaction abort!
828 826 rollback completed
829 827 strip failed, backup bundle stored in * (glob)
830 828 abort: pretxnclose.error hook exited with status 1
831 829 [255]
832 830 $ hg recover
833 831 no interrupted transaction available
834 832 [1]
835 833 $ cd ..
836 834
837 835 check whether HG_PENDING makes pending changes only in related
838 836 repositories visible to an external hook.
839 837
840 838 (emulate a transaction running concurrently by copied
841 839 .hg/store/00changelog.i.a in subsequent test)
842 840
843 841 $ cat > $TESTTMP/savepending.sh <<EOF
844 842 > cp .hg/store/00changelog.i.a .hg/store/00changelog.i.a.saved
845 843 > exit 1 # to avoid adding new revision for subsequent tests
846 844 > EOF
847 845 $ cd a
848 846 $ hg tip -q
849 847 4:539e4b31b6dc
850 848 $ hg --config hooks.pretxnclose="sh $TESTTMP/savepending.sh" commit -m "invisible"
851 849 transaction abort!
852 850 rollback completed
853 851 abort: pretxnclose hook exited with status 1
854 852 [255]
855 853 $ cp .hg/store/00changelog.i.a.saved .hg/store/00changelog.i.a
856 854
857 855 (check (in)visibility of new changeset while transaction running in
858 856 repo)
859 857
860 858 $ cat > $TESTTMP/checkpending.sh <<EOF
861 859 > echo '@a'
862 860 > hg -R "$TESTTMP/a" tip -q
863 861 > echo '@a/nested'
864 862 > hg -R "$TESTTMP/a/nested" tip -q
865 863 > exit 1 # to avoid adding new revision for subsequent tests
866 864 > EOF
867 865 $ hg init nested
868 866 $ cd nested
869 867 $ echo a > a
870 868 $ hg add a
871 869 $ hg --config hooks.pretxnclose="sh $TESTTMP/checkpending.sh" commit -m '#0'
872 870 @a
873 871 4:539e4b31b6dc
874 872 @a/nested
875 873 0:bf5e395ced2c
876 874 transaction abort!
877 875 rollback completed
878 876 abort: pretxnclose hook exited with status 1
879 877 [255]
880 878
881 879 Hook from untrusted hgrc are reported as failure
882 880 ================================================
883 881
884 882 $ cat << EOF > $TESTTMP/untrusted.py
885 883 > from mercurial import scmutil, util
886 884 > def uisetup(ui):
887 885 > class untrustedui(ui.__class__):
888 886 > def _trusted(self, fp, f):
889 887 > if util.normpath(fp.name).endswith('untrusted/.hg/hgrc'):
890 888 > return False
891 889 > return super(untrustedui, self)._trusted(fp, f)
892 890 > ui.__class__ = untrustedui
893 891 > EOF
894 892 $ cat << EOF >> $HGRCPATH
895 893 > [extensions]
896 894 > untrusted=$TESTTMP/untrusted.py
897 895 > EOF
898 896 $ hg init untrusted
899 897 $ cd untrusted
900 898
901 899 Non-blocking hook
902 900 -----------------
903 901
904 902 $ cat << EOF >> .hg/hgrc
905 903 > [hooks]
906 904 > txnclose.testing=echo txnclose hook called
907 905 > EOF
908 906 $ touch a && hg commit -Aqm a
909 907 warning: untrusted hook txnclose.testing not executed
910 908 $ hg log
911 909 changeset: 0:3903775176ed
912 910 tag: tip
913 911 user: test
914 912 date: Thu Jan 01 00:00:00 1970 +0000
915 913 summary: a
916 914
917 915
918 916 Non-blocking hook
919 917 -----------------
920 918
921 919 $ cat << EOF >> .hg/hgrc
922 920 > [hooks]
923 921 > pretxnclose.testing=echo pre-txnclose hook called
924 922 > EOF
925 923 $ touch b && hg commit -Aqm a
926 924 transaction abort!
927 925 rollback completed
928 926 abort: untrusted hook pretxnclose.testing not executed
929 927 (see 'hg help config.trusted')
930 928 [255]
931 929 $ hg log
932 930 changeset: 0:3903775176ed
933 931 tag: tip
934 932 user: test
935 933 date: Thu Jan 01 00:00:00 1970 +0000
936 934 summary: a
937 935
General Comments 0
You need to be logged in to leave comments. Login now