diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -2675,6 +2675,12 @@ def qqueue(ui, repo, name=None, **opts): fh.write('%s\n' % (name,)) fh.close() + def _queuedir(name): + if name == 'patches': + return repo.join('patches') + else: + return repo.join('patches-' + name) + def _validname(name): for n in name: if n in ':\\/.': @@ -2704,6 +2710,31 @@ def qqueue(ui, repo, name=None, **opts): _addqueue(_defaultqueue) _addqueue(name) _setactive(name) + elif opts.get('rename'): + current = _getcurrent() + if name == current: + raise util.Abort(_('can\'t rename "%s" to its current name') % name) + if name in existing: + raise util.Abort(_('queue "%s" already exists') % name) + + olddir = _queuedir(current) + newdir = _queuedir(name) + + if os.path.exists(newdir): + raise util.Abort(_('non-queue directory "%s" already exists') % + newdir) + + fh = repo.opener('patches.queues.new', 'w') + for queue in existing: + if queue == current: + fh.write('%s\n' % (name,)) + if os.path.exists(olddir): + util.rename(olddir, newdir) + else: + fh.write('%s\n' % (queue,)) + fh.close() + util.rename(repo.join('patches.queues.new'), repo.join(_allqueues)) + _setactivenocheck(name) elif opts.get('delete'): if name not in existing: raise util.Abort(_('cannot delete queue that does not exist')) @@ -3045,6 +3076,7 @@ cmdtable = { [ ('l', 'list', False, _('list all available queues')), ('c', 'create', False, _('create new queue')), + ('', 'rename', False, _('rename active queue')), ('', 'delete', False, _('delete reference to queue')), ], _('[OPTION] [QUEUE]')), diff --git a/tests/test-mq-qqueue b/tests/test-mq-qqueue --- a/tests/test-mq-qqueue +++ b/tests/test-mq-qqueue @@ -35,6 +35,25 @@ echo %% fail creating queue with already hg qqueue --create foo hg qqueue +echo %% create new queue for rename +hg qqueue --create bar +hg qqueue + +echo %% rename queue, same name +hg qqueue --rename bar + +echo %% rename queue to existing +hg qqueue --rename foo + +echo %% rename queue +hg qqueue --rename buz +hg qqueue + +echo %% switch back to previous queue +hg qqueue foo +hg qqueue --delete buz +hg qqueue + echo %% unapplied patches hg qun echo c > a diff --git a/tests/test-mq-qqueue.out b/tests/test-mq-qqueue.out --- a/tests/test-mq-qqueue.out +++ b/tests/test-mq-qqueue.out @@ -19,6 +19,21 @@ patches abort: queue "foo" already exists foo (active) patches +%% create new queue for rename +bar (active) +foo +patches +%% rename queue, same name +abort: can't rename "bar" to its current name +%% rename queue to existing +abort: queue "foo" already exists +%% rename queue +buz (active) +foo +patches +%% switch back to previous queue +foo (active) +patches %% unapplied patches %% fail switching back abort: patches applied - cannot set new queue active