mq: add qdelete --forget option
authorBrendan Cully <brendan@kublai.com>
Thu, 14 Sep 2006 15:35:55 +0200
changeset 3088 dc784839516d
parent 3087 fd1479e30aaf
child 3089 e7fc04dc6349
mq: add qdelete --forget option This removes an applied patch from the series and status files without popping it. It is useful when an mq patch has been applied upstream.
hgext/mq.py
tests/test-mq-qdelete
tests/test-mq-qdelete.out
--- a/hgext/mq.py	Wed Sep 13 16:41:03 2006 -0700
+++ b/hgext/mq.py	Thu Sep 14 15:35:55 2006 +0200
@@ -483,24 +483,35 @@
         tr.close()
         return (err, n)
 
-    def delete(self, repo, patches, keep=False):
+    def delete(self, repo, patches, opts):
         realpatches = []
+        appliedbase = 0
+        forget = opts.get('forget')
         for patch in patches:
             patch = self.lookup(patch, strict=True)
             info = self.isapplied(patch)
-            if info:
+            if info and not forget:
                 raise util.Abort(_("cannot delete applied patch %s") % patch)
             if patch not in self.series:
                 raise util.Abort(_("patch %s not in series file") % patch)
+            if forget:
+                if not info:
+                    raise util.Abort(_("cannot forget unapplied patch %s") % patch)
+                if info[0] != appliedbase:
+                    raise util.Abort(_("patch %s not at base") % patch)
+                appliedbase += 1
             realpatches.append(patch)
 
-        if not keep:
+        if not opts.get('keep'):
             r = self.qrepo()
             if r:
                 r.remove(realpatches, True)
             else:
                 os.unlink(self.join(patch))
 
+        if forget:
+            del self.applied[:appliedbase]
+            self.applied_dirty = 1
         indices = [self.find_series(p) for p in realpatches]
         indices.sort()
         for i in indices[-1::-1]:
@@ -1306,10 +1317,15 @@
 def delete(ui, repo, patch, *patches, **opts):
     """remove patches from queue
 
-    The patches must not be applied.
-    With -k, the patch files are preserved in the patch directory."""
+    With --forget, mq will stop managing the named patches. The
+    patches must be applied and at the base of the stack. This option
+    is useful when the patches have been applied upstream.
+
+    Otherwise, the patches must not be applied.
+
+    With --keep, the patch files are preserved in the patch directory."""
     q = repo.mq
-    q.delete(repo, (patch,) + patches, keep=opts.get('keep'))
+    q.delete(repo, (patch,) + patches, opts)
     q.save_dirty()
     return 0
 
@@ -1917,8 +1933,9 @@
                'hg qdiff [-I] [-X] [FILE]...'),
     "qdelete|qremove|qrm":
         (delete,
-         [('k', 'keep', None, _('keep patch file'))],
-          'hg qdelete [-k] PATCH'),
+         [('f', 'forget', None, _('stop managing an applied patch')),
+          ('k', 'keep', None, _('keep patch file'))],
+          'hg qdelete [-f] [-k] PATCH'),
     'qfold':
         (fold,
          [('e', 'edit', None, _('edit patch header')),
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-mq-qdelete	Thu Sep 14 15:35:55 2006 +0200
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+echo "[extensions]" >> $HGRCPATH
+echo "mq=" >> $HGRCPATH
+
+hg init a
+cd a
+
+echo 'base' > base
+hg ci -Ambase -d '1 0'
+
+hg qnew a
+hg qnew b
+hg qnew c
+
+hg qdel c
+hg qpop
+hg qdel c
+hg qseries
+ls .hg/patches
+hg qpop
+hg qdel -k b
+ls .hg/patches
+hg qdel -f a
+hg qapplied
+hg log --template '{rev} {desc}\n'
+
+hg qnew d
+hg qnew e
+hg qnew f
+
+hg qdel -f e
+hg qdel -f d e
+hg qapplied
+hg log --template '{rev} {desc}\n'
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-mq-qdelete.out	Thu Sep 14 15:35:55 2006 +0200
@@ -0,0 +1,23 @@
+adding base
+abort: cannot delete applied patch c
+Now at: b
+a
+b
+a
+b
+series
+status
+Now at: a
+a
+b
+series
+status
+1 New patch: a
+0 base
+abort: patch e not at base
+f
+4 New patch: f
+3 New patch: e
+2 New patch: d
+1 New patch: a
+0 base