mq/qqueue: add --purge option to delete a queue and its patch dir
qqueue --delete only deletes the reference to the queue, and leaves
the associated patch directory behind. There is no Mercurial-way of
getting rid of that patch directory afterward.
This patch adds the --purge option to qqueue, that deletes the queue
from the list, and also removes the associated patch dir. If the queue
was non-existant, but the patch dir was, it is removed nonetheless.
This is to avoid manual intervention in the .hg directory.
--- a/hgext/mq.py Wed Aug 18 23:34:28 2010 +0200
+++ b/hgext/mq.py Wed Aug 18 23:37:19 2010 +0200
@@ -47,7 +47,7 @@
from mercurial.lock import release
from mercurial import commands, cmdutil, hg, patch, util
from mercurial import repair, extensions, url, error
-import os, sys, re, errno
+import os, sys, re, errno, shutil
commands.norepo += " qclone"
@@ -2762,6 +2762,12 @@
_setactivenocheck(name)
elif opts.get('delete'):
_delete(name)
+ elif opts.get('purge'):
+ if name in existing:
+ _delete(name)
+ qdir = _queuedir(name)
+ if os.path.exists(qdir):
+ shutil.rmtree(qdir)
else:
if name not in existing:
raise util.Abort(_('use --create to create a new queue'))
@@ -3089,6 +3095,7 @@
('c', 'create', False, _('create new queue')),
('', 'rename', False, _('rename active queue')),
('', 'delete', False, _('delete reference to queue')),
+ ('', 'purge', False, _('delete queue, and remove patch dir')),
],
_('[OPTION] [QUEUE]')),
}
--- a/tests/test-mq-qqueue Wed Aug 18 23:34:28 2010 +0200
+++ b/tests/test-mq-qqueue Wed Aug 18 23:37:19 2010 +0200
@@ -54,6 +54,21 @@
hg qqueue --delete buz
hg qqueue
+echo %% create queue for purge
+hg qqueue --create purge-me
+hg qqueue
+
+echo %% create patch for purge
+hg qnew patch-purge-me
+ls -1d .hg/patches-purge-me 2>/dev/null || true
+hg qpop -a
+
+echo %% purge queue
+hg qqueue foo
+hg qqueue --purge purge-me
+hg qqueue
+ls -1d .hg/patches-purge-me 2>/dev/null || true
+
echo %% unapplied patches
hg qun
echo c > a
--- a/tests/test-mq-qqueue.out Wed Aug 18 23:34:28 2010 +0200
+++ b/tests/test-mq-qqueue.out Wed Aug 18 23:37:19 2010 +0200
@@ -34,6 +34,17 @@
%% switch back to previous queue
foo (active)
patches
+%% create queue for purge
+foo
+patches
+purge-me (active)
+%% create patch for purge
+.hg/patches-purge-me
+popping patch-purge-me
+patch queue now empty
+%% purge queue
+foo (active)
+patches
%% unapplied patches
%% fail switching back
abort: patches applied - cannot set new queue active