# HG changeset patch # User Greg Ward # Date 1317434334 14400 # Node ID 68475648cd7e889535bbc4e85be1992f48680fa6 # Parent 52af2791a71ee818d5b22b1a0a33dfa7d8af8486 rollback: avoid unsafe rollback when not at tip (issue2998) You can get into trouble if you commit, update back to an older changeset, and then rollback. The update removes your valuable changes from the working dir, then rollback removes them history. Oops: you've just irretrievably lost data running nothing but core Mercurial commands. (More subtly: rollback from a shared clone that was already at an older changeset -- no update required, just rollback from the wrong directory.) The fix assumes that only "commit" transactions have irreplaceable data, and allows rolling back non-commit transactions as always. But when rolling back a commit, check that the working dir is checked out to tip, i.e. the changeset we're about to destroy. If not, abort. You can get back the old (dangerous) behaviour with --force. [ original upstream message ] diff -r 52af2791a71e -r 68475648cd7e hgkw/keyword.py --- a/hgkw/keyword.py Thu Oct 13 17:54:37 2011 +0200 +++ b/hgkw/keyword.py Fri Sep 30 21:58:54 2011 -0400 @@ -590,12 +590,12 @@ kwt.restrict = restrict return n - def rollback(self, dryrun=False): + def rollback(self, dryrun=False, force=False): wlock = self.wlock() try: if not dryrun: changed = self['.'].files() - ret = super(kwrepo, self).rollback(dryrun) + ret = super(kwrepo, self).rollback(dryrun, force) if not dryrun: ctx = self['.'] modified, added = _preselect(self[None].status(), changed)