changeset 12682:58a3e2608ae4

strip: add --keep flag to avoid modifying wc during strip Fixes issue1564.
author Augie Fackler <durin42@gmail.com>
date Sat, 09 Oct 2010 11:02:11 -0500
parents bc13e17067d9
children ada47c38f4e5
files hgext/mq.py tests/test-mq-strip.t
diffstat 2 files changed, 52 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/mq.py	Sat Oct 09 17:02:28 2010 -0500
+++ b/hgext/mq.py	Sat Oct 09 11:02:11 2010 -0500
@@ -2522,7 +2522,18 @@
             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 @@
           ('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,
--- a/tests/test-mq-strip.t	Sat Oct 09 17:02:28 2010 -0500
+++ b/tests/test-mq-strip.t	Sat Oct 09 11:02:11 2010 -0500
@@ -380,3 +380,39 @@
 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