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