##// END OF EJS Templates
py3: add b'' prefixes in tests/test-rollback.t...
Pulkit Goyal -
r36504:fb9b8004 default
parent child Browse files
Show More
@@ -1,466 +1,466 b''
1 1 setup repo
2 2 $ hg init t
3 3 $ cd t
4 4 $ echo a > a
5 5 $ hg commit -Am'add a'
6 6 adding a
7 7 $ hg verify
8 8 checking changesets
9 9 checking manifests
10 10 crosschecking files in changesets and manifests
11 11 checking files
12 12 1 files, 1 changesets, 1 total revisions
13 13 $ hg parents
14 14 changeset: 0:1f0dee641bb7
15 15 tag: tip
16 16 user: test
17 17 date: Thu Jan 01 00:00:00 1970 +0000
18 18 summary: add a
19 19
20 20
21 21 rollback to null revision
22 22 $ hg status
23 23 $ hg rollback
24 24 repository tip rolled back to revision -1 (undo commit)
25 25 working directory now based on revision -1
26 26 $ hg verify
27 27 checking changesets
28 28 checking manifests
29 29 crosschecking files in changesets and manifests
30 30 checking files
31 31 0 files, 0 changesets, 0 total revisions
32 32 $ hg parents
33 33 $ hg status
34 34 A a
35 35
36 36 Two changesets this time so we rollback to a real changeset
37 37 $ hg commit -m'add a again'
38 38 $ echo a >> a
39 39 $ hg commit -m'modify a'
40 40
41 41 Test issue 902 (current branch is preserved)
42 42 $ hg branch test
43 43 marked working directory as branch test
44 44 (branches are permanent and global, did you want a bookmark?)
45 45 $ hg rollback
46 46 repository tip rolled back to revision 0 (undo commit)
47 47 working directory now based on revision 0
48 48 $ hg branch
49 49 default
50 50
51 51 Test issue 1635 (commit message saved)
52 52 $ cat .hg/last-message.txt ; echo
53 53 modify a
54 54
55 55 Test rollback of hg before issue 902 was fixed
56 56
57 57 $ hg commit -m "test3"
58 58 $ hg branch test
59 59 marked working directory as branch test
60 60 (branches are permanent and global, did you want a bookmark?)
61 61 $ rm .hg/undo.branch
62 62 $ hg rollback
63 63 repository tip rolled back to revision 0 (undo commit)
64 64 named branch could not be reset: current branch is still 'test'
65 65 working directory now based on revision 0
66 66 $ hg branch
67 67 test
68 68
69 69 working dir unaffected by rollback: do not restore dirstate et. al.
70 70 $ hg log --template '{rev} {branch} {desc|firstline}\n'
71 71 0 default add a again
72 72 $ hg status
73 73 M a
74 74 $ hg bookmark foo
75 75 $ hg commit -m'modify a again'
76 76 $ echo b > b
77 77 $ hg bookmark bar -r default #making bar active, before the transaction
78 78 $ hg commit -Am'add b'
79 79 adding b
80 80 $ hg log --template '{rev} {branch} {desc|firstline}\n'
81 81 2 test add b
82 82 1 test modify a again
83 83 0 default add a again
84 84 $ hg update bar
85 85 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
86 86 (activating bookmark bar)
87 87 $ cat .hg/undo.branch ; echo
88 88 test
89 89 $ hg rollback -f
90 90 repository tip rolled back to revision 1 (undo commit)
91 91 $ hg id -n
92 92 0
93 93 $ hg branch
94 94 default
95 95 $ cat .hg/bookmarks.current ; echo
96 96 bar
97 97 $ hg bookmark --delete foo bar
98 98
99 99 rollback by pretxncommit saves commit message (issue1635)
100 100
101 101 $ echo a >> a
102 102 $ hg --config hooks.pretxncommit=false commit -m"precious commit message"
103 103 transaction abort!
104 104 rollback completed
105 105 abort: pretxncommit hook exited with status * (glob)
106 106 [255]
107 107 $ cat .hg/last-message.txt ; echo
108 108 precious commit message
109 109
110 110 same thing, but run $EDITOR
111 111
112 112 $ cat > editor.sh << '__EOF__'
113 113 > echo "another precious commit message" > "$1"
114 114 > __EOF__
115 115 $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg --config hooks.pretxncommit=false commit 2>&1
116 116 note: commit message saved in .hg/last-message.txt
117 117 transaction abort!
118 118 rollback completed
119 119 abort: pretxncommit hook exited with status * (glob)
120 120 [255]
121 121 $ cat .hg/last-message.txt
122 122 another precious commit message
123 123
124 124 test rollback on served repository
125 125
126 126 #if serve
127 127 $ hg commit -m "precious commit message"
128 128 $ hg serve -p $HGPORT -d --pid-file=hg.pid -A access.log -E errors.log
129 129 $ cat hg.pid >> $DAEMON_PIDS
130 130 $ cd ..
131 131 $ hg clone http://localhost:$HGPORT u
132 132 requesting all changes
133 133 adding changesets
134 134 adding manifests
135 135 adding file changes
136 136 added 3 changesets with 2 changes to 1 files (+1 heads)
137 137 new changesets 23b0221f3370:068774709090
138 138 updating to branch default
139 139 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
140 140 $ cd u
141 141 $ hg id default
142 142 068774709090
143 143
144 144 now rollback and observe that 'hg serve' reloads the repository and
145 145 presents the correct tip changeset:
146 146
147 147 $ hg -R ../t rollback
148 148 repository tip rolled back to revision 1 (undo commit)
149 149 working directory now based on revision 0
150 150 $ hg id default
151 151 791dd2169706
152 152
153 153 $ killdaemons.py
154 154 #endif
155 155
156 156 update to older changeset and then refuse rollback, because
157 157 that would lose data (issue2998)
158 158 $ cd ../t
159 159 $ hg -q update
160 160 $ rm `hg status -un`
161 161 $ template='{rev}:{node|short} [{branch}] {desc|firstline}\n'
162 162 $ echo 'valuable new file' > b
163 163 $ echo 'valuable modification' >> a
164 164 $ hg commit -A -m'a valuable change'
165 165 adding b
166 166 $ hg update 0
167 167 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
168 168 $ hg rollback
169 169 abort: rollback of last commit while not checked out may lose data
170 170 (use -f to force)
171 171 [255]
172 172 $ hg tip -q
173 173 2:4d9cd3795eea
174 174 $ hg rollback -f
175 175 repository tip rolled back to revision 1 (undo commit)
176 176 $ hg status
177 177 $ hg log --removed b # yep, it's gone
178 178
179 179 same again, but emulate an old client that doesn't write undo.desc
180 180 $ hg -q update
181 181 $ echo 'valuable modification redux' >> a
182 182 $ hg commit -m'a valuable change redux'
183 183 $ rm .hg/undo.desc
184 184 $ hg update 0
185 185 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
186 186 $ hg rollback
187 187 rolling back unknown transaction
188 188 $ cat a
189 189 a
190 190
191 191 corrupt journal test
192 192 $ echo "foo" > .hg/store/journal
193 193 $ hg recover
194 194 rolling back interrupted transaction
195 195 couldn't read journal entry 'foo\n'!
196 196 checking changesets
197 197 checking manifests
198 198 crosschecking files in changesets and manifests
199 199 checking files
200 200 1 files, 2 changesets, 2 total revisions
201 201
202 202 rollback disabled by config
203 203 $ cat >> $HGRCPATH <<EOF
204 204 > [ui]
205 205 > rollback = false
206 206 > EOF
207 207 $ echo narf >> pinky-sayings.txt
208 208 $ hg add pinky-sayings.txt
209 209 $ hg ci -m 'First one.'
210 210 $ hg rollback
211 211 abort: rollback is disabled because it is unsafe
212 212 (see `hg help -v rollback` for information)
213 213 [255]
214 214
215 215 $ cd ..
216 216
217 217 I/O errors on stdio are handled properly (issue5658)
218 218
219 219 $ cat > badui.py << EOF
220 220 > import errno
221 221 > from mercurial.i18n import _
222 222 > from mercurial import (
223 223 > registrar,
224 224 > error,
225 225 > ui as uimod,
226 226 > )
227 227 >
228 228 > configtable = {}
229 229 > configitem = registrar.configitem(configtable)
230 230 >
231 > configitem('ui', 'ioerrors',
231 > configitem(b'ui', b'ioerrors',
232 232 > default=list,
233 233 > )
234 234 >
235 235 > def pretxncommit(ui, repo, **kwargs):
236 > ui.warn('warn during pretxncommit\n')
236 > ui.warn(b'warn during pretxncommit\n')
237 237 >
238 238 > def pretxnclose(ui, repo, **kwargs):
239 > ui.warn('warn during pretxnclose\n')
239 > ui.warn(b'warn during pretxnclose\n')
240 240 >
241 241 > def txnclose(ui, repo, **kwargs):
242 > ui.warn('warn during txnclose\n')
242 > ui.warn(b'warn during txnclose\n')
243 243 >
244 244 > def txnabort(ui, repo, **kwargs):
245 > ui.warn('warn during abort\n')
245 > ui.warn(b'warn during abort\n')
246 246 >
247 247 > class fdproxy(object):
248 248 > def __init__(self, ui, o):
249 249 > self._ui = ui
250 250 > self._o = o
251 251 >
252 252 > def __getattr__(self, attr):
253 253 > return getattr(self._o, attr)
254 254 >
255 255 > def write(self, msg):
256 > errors = set(self._ui.configlist('ui', 'ioerrors'))
257 > pretxncommit = msg == 'warn during pretxncommit\n'
258 > pretxnclose = msg == 'warn during pretxnclose\n'
259 > txnclose = msg == 'warn during txnclose\n'
260 > txnabort = msg == 'warn during abort\n'
261 > msgabort = msg == _('transaction abort!\n')
262 > msgrollback = msg == _('rollback completed\n')
256 > errors = set(self._ui.configlist(b'ui', b'ioerrors'))
257 > pretxncommit = msg == b'warn during pretxncommit\n'
258 > pretxnclose = msg == b'warn during pretxnclose\n'
259 > txnclose = msg == b'warn during txnclose\n'
260 > txnabort = msg == b'warn during abort\n'
261 > msgabort = msg == _(b'transaction abort!\n')
262 > msgrollback = msg == _(b'rollback completed\n')
263 263 >
264 > if pretxncommit and 'pretxncommit' in errors:
264 > if pretxncommit and b'pretxncommit' in errors:
265 265 > raise IOError(errno.EPIPE, 'simulated epipe')
266 > if pretxnclose and 'pretxnclose' in errors:
266 > if pretxnclose and b'pretxnclose' in errors:
267 267 > raise IOError(errno.EIO, 'simulated eio')
268 > if txnclose and 'txnclose' in errors:
268 > if txnclose and b'txnclose' in errors:
269 269 > raise IOError(errno.EBADF, 'simulated badf')
270 > if txnabort and 'txnabort' in errors:
270 > if txnabort and b'txnabort' in errors:
271 271 > raise IOError(errno.EPIPE, 'simulated epipe')
272 > if msgabort and 'msgabort' in errors:
272 > if msgabort and b'msgabort' in errors:
273 273 > raise IOError(errno.EBADF, 'simulated ebadf')
274 > if msgrollback and 'msgrollback' in errors:
274 > if msgrollback and b'msgrollback' in errors:
275 275 > raise IOError(errno.EIO, 'simulated eio')
276 276 >
277 277 > return self._o.write(msg)
278 278 >
279 279 > def uisetup(ui):
280 280 > class badui(ui.__class__):
281 281 > def write_err(self, *args, **kwargs):
282 282 > olderr = self.ferr
283 283 > try:
284 284 > self.ferr = fdproxy(self, olderr)
285 285 > return super(badui, self).write_err(*args, **kwargs)
286 286 > finally:
287 287 > self.ferr = olderr
288 288 >
289 289 > ui.__class__ = badui
290 290 >
291 291 > def reposetup(ui, repo):
292 > ui.setconfig('hooks', 'pretxnclose.badui', pretxnclose, 'badui')
293 > ui.setconfig('hooks', 'txnclose.badui', txnclose, 'badui')
294 > ui.setconfig('hooks', 'pretxncommit.badui', pretxncommit, 'badui')
295 > ui.setconfig('hooks', 'txnabort.badui', txnabort, 'badui')
292 > ui.setconfig(b'hooks', b'pretxnclose.badui', pretxnclose, b'badui')
293 > ui.setconfig(b'hooks', b'txnclose.badui', txnclose, b'badui')
294 > ui.setconfig(b'hooks', b'pretxncommit.badui', pretxncommit, b'badui')
295 > ui.setconfig(b'hooks', b'txnabort.badui', txnabort, b'badui')
296 296 > EOF
297 297
298 298 $ cat >> $HGRCPATH << EOF
299 299 > [extensions]
300 300 > badui = $TESTTMP/badui.py
301 301 > EOF
302 302
303 303 An I/O error during pretxncommit is handled
304 304
305 305 $ hg init ioerror-pretxncommit
306 306 $ cd ioerror-pretxncommit
307 307 $ echo 0 > foo
308 308 $ hg -q commit -A -m initial
309 309 warn during pretxncommit
310 310 warn during pretxnclose
311 311 warn during txnclose
312 312 $ echo 1 > foo
313 313 $ hg --config ui.ioerrors=pretxncommit commit -m 'error during pretxncommit'
314 314 warn during pretxnclose
315 315 warn during txnclose
316 316
317 317 $ hg commit -m 'commit 1'
318 318 nothing changed
319 319 [1]
320 320
321 321 $ cd ..
322 322
323 323 An I/O error during pretxnclose is handled
324 324
325 325 $ hg init ioerror-pretxnclose
326 326 $ cd ioerror-pretxnclose
327 327 $ echo 0 > foo
328 328 $ hg -q commit -A -m initial
329 329 warn during pretxncommit
330 330 warn during pretxnclose
331 331 warn during txnclose
332 332
333 333 $ echo 1 > foo
334 334 $ hg --config ui.ioerrors=pretxnclose commit -m 'error during pretxnclose'
335 335 warn during pretxncommit
336 336 warn during txnclose
337 337
338 338 $ hg commit -m 'commit 1'
339 339 nothing changed
340 340 [1]
341 341
342 342 $ cd ..
343 343
344 344 An I/O error during txnclose is handled
345 345
346 346 $ hg init ioerror-txnclose
347 347 $ cd ioerror-txnclose
348 348 $ echo 0 > foo
349 349 $ hg -q commit -A -m initial
350 350 warn during pretxncommit
351 351 warn during pretxnclose
352 352 warn during txnclose
353 353
354 354 $ echo 1 > foo
355 355 $ hg --config ui.ioerrors=txnclose commit -m 'error during txnclose'
356 356 warn during pretxncommit
357 357 warn during pretxnclose
358 358
359 359 $ hg commit -m 'commit 1'
360 360 nothing changed
361 361 [1]
362 362
363 363 $ cd ..
364 364
365 365 An I/O error writing "transaction abort" is handled
366 366
367 367 $ hg init ioerror-msgabort
368 368 $ cd ioerror-msgabort
369 369
370 370 $ echo 0 > foo
371 371 $ hg -q commit -A -m initial
372 372 warn during pretxncommit
373 373 warn during pretxnclose
374 374 warn during txnclose
375 375
376 376 $ echo 1 > foo
377 377 $ hg --config ui.ioerrors=msgabort --config hooks.pretxncommit=false commit -m 'error during abort message'
378 378 warn during abort
379 379 rollback completed
380 380 abort: pretxncommit hook exited with status 1
381 381 [255]
382 382
383 383 $ hg commit -m 'commit 1'
384 384 warn during pretxncommit
385 385 warn during pretxnclose
386 386 warn during txnclose
387 387
388 388 $ cd ..
389 389
390 390 An I/O error during txnabort should still result in rollback
391 391
392 392 $ hg init ioerror-txnabort
393 393 $ cd ioerror-txnabort
394 394
395 395 $ echo 0 > foo
396 396 $ hg -q commit -A -m initial
397 397 warn during pretxncommit
398 398 warn during pretxnclose
399 399 warn during txnclose
400 400
401 401 $ echo 1 > foo
402 402 $ hg --config ui.ioerrors=txnabort --config hooks.pretxncommit=false commit -m 'error during abort'
403 403 transaction abort!
404 404 rollback completed
405 405 abort: pretxncommit hook exited with status 1
406 406 [255]
407 407
408 408 $ hg commit -m 'commit 1'
409 409 warn during pretxncommit
410 410 warn during pretxnclose
411 411 warn during txnclose
412 412
413 413 $ cd ..
414 414
415 415 An I/O error writing "rollback completed" is handled
416 416
417 417 $ hg init ioerror-msgrollback
418 418 $ cd ioerror-msgrollback
419 419
420 420 $ echo 0 > foo
421 421 $ hg -q commit -A -m initial
422 422 warn during pretxncommit
423 423 warn during pretxnclose
424 424 warn during txnclose
425 425
426 426 $ echo 1 > foo
427 427
428 428 $ hg --config ui.ioerrors=msgrollback --config hooks.pretxncommit=false commit -m 'error during rollback message'
429 429 transaction abort!
430 430 warn during abort
431 431 abort: pretxncommit hook exited with status 1
432 432 [255]
433 433
434 434 $ hg verify
435 435 checking changesets
436 436 checking manifests
437 437 crosschecking files in changesets and manifests
438 438 checking files
439 439 1 files, 1 changesets, 1 total revisions
440 440
441 441 $ cd ..
442 442
443 443 Multiple I/O errors after transaction open are handled.
444 444 This is effectively what happens if a peer disconnects in the middle
445 445 of a transaction.
446 446
447 447 $ hg init ioerror-multiple
448 448 $ cd ioerror-multiple
449 449 $ echo 0 > foo
450 450 $ hg -q commit -A -m initial
451 451 warn during pretxncommit
452 452 warn during pretxnclose
453 453 warn during txnclose
454 454
455 455 $ echo 1 > foo
456 456
457 457 $ hg --config ui.ioerrors=pretxncommit,pretxnclose,txnclose,txnabort,msgabort,msgrollback commit -m 'multiple errors'
458 458
459 459 $ hg verify
460 460 checking changesets
461 461 checking manifests
462 462 crosschecking files in changesets and manifests
463 463 checking files
464 464 1 files, 2 changesets, 2 total revisions
465 465
466 466 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now