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