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