[PATCH 1 of 1] strip: add --keep flag to avoid modifying wc during strip

Augie Fackler durin42 at gmail.com
Sat Oct 9 11:04:03 CDT 2010


# HG changeset patch
# User Augie Fackler <durin42 at gmail.com>
# Date 1286640131 18000
# Node ID 0ddd0bc0ffd7c0e0a1b5d773faf293757073421f
# Parent  7178f6fedb9db000300abda8168d36a890a686c2
strip: add --keep flag to avoid modifying wc during strip

Fixes issue1564.

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -2521,7 +2521,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
 
@@ -3144,9 +3155,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, _("don't 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 @@
 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


More information about the Mercurial-devel mailing list