diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -2522,7 +2522,18 @@ def strip(ui, repo, *revs, **opts): del q.applied[start:end] q.save_dirty() - repo.mq.strip(repo, list(rootnodes), backup=backup, update=update, + revs = list(rootnodes) + if update and opts.get('keep'): + wlock = repo.wlock() + try: + urev = repo.mq.qparents(repo, revs[0]) + repo.dirstate.rebuild(urev, repo[urev].manifest()) + repo.dirstate.write() + update = False + finally: + wlock.release() + + repo.mq.strip(repo, revs, backup=backup, update=update, force=opts.get('force')) return 0 @@ -3145,9 +3156,10 @@ cmdtable = { ('b', 'backup', None, _('bundle only changesets with local revision' ' number greater than REV which are not' ' descendants of REV (DEPRECATED)')), - ('n', 'no-backup', None, _('no backups')), - ('', 'nobackup', None, _('no backups (DEPRECATED)'))], - _('hg strip [-f] [-n] REV...')), + ('n', 'no-backup', None, _('no backups')), + ('', 'nobackup', None, _('no backups (DEPRECATED)')), + ('k', 'keep', None, _("do not modify working copy during strip"))], + _('hg strip [-k] [-f] [-n] REV...')), "qtop": (top, [] + seriesopts, _('hg qtop [-s]')), "qunapplied": (unapplied, diff --git a/tests/test-mq-strip.t b/tests/test-mq-strip.t --- a/tests/test-mq-strip.t +++ b/tests/test-mq-strip.t @@ -380,3 +380,39 @@ stripping ancestor of queue applied patches after stripping ancestor of queue $ hg qapplied + +Verify strip protects against stripping wc parent when there are uncommited mods + + $ echo b > b + $ hg add b + $ hg ci -m 'b' + $ hg log --graph + @ changeset: 1:7519abd79d14 + | tag: tip + | user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: b + | + o changeset: 0:9ab35a2d17cb + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: a + + + $ echo c > b + $ echo c > bar + $ hg strip tip + abort: local changes found + [255] + $ hg strip tip --keep + saved backup bundle to * (glob) + $ hg log --graph + @ changeset: 0:9ab35a2d17cb + tag: tip + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: a + + $ hg status + M bar + ? b