mq: add qgoto command.
authorBryan O'Sullivan <bos@serpentine.com>
Tue, 08 May 2007 13:10:27 -0700
changeset 4432 905397be7688
parent 4431 8014159074a9
child 4433 ba22e867cb23
mq: add qgoto command.
hgext/mq.py
tests/test-mq-qgoto
tests/test-mq-qgoto.out
tests/test-mq.out
--- a/hgext/mq.py	Tue May 08 11:51:16 2007 -0700
+++ b/hgext/mq.py	Tue May 08 13:10:27 2007 -0700
@@ -1762,6 +1762,17 @@
     q.delete(repo, patches, opts)
     q.save_dirty()
 
+def goto(ui, repo, patch, **opts):
+    '''push or pop patches until named patch is at top of stack'''
+    q = repo.mq
+    patch = q.lookup(patch)
+    if q.isapplied(patch):
+        ret = q.pop(repo, patch, force=opts['force'])
+    else:
+        ret = q.push(repo, patch, force=opts['force'])
+    q.save_dirty()
+    return ret
+
 def guard(ui, repo, *args, **opts):
     '''set or print guards for a patch
 
@@ -2202,6 +2213,8 @@
           ('k', 'keep', None, _('keep folded patch files'))
           ] + commands.commitopts,
          'hg qfold [-e] [-m <text>] [-l <file] PATCH...'),
+    'qgoto': (goto, [('f', 'force', None, _('overwrite any local changes'))],
+              'hg qgoto [OPT]... PATCH'),
     'qguard': (guard, [('l', 'list', None, _('list all patches and guards')),
                        ('n', 'none', None, _('drop all guards'))],
                'hg qguard [PATCH] [+GUARD]... [-GUARD]...'),
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-mq-qgoto	Tue May 08 13:10:27 2007 -0700
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+echo "[extensions]" >> $HGRCPATH
+echo "mq=" >> $HGRCPATH
+
+hg init a
+cd a
+echo a > a
+hg ci -Ama
+
+hg qnew a.patch
+echo a >> a
+hg qrefresh
+
+hg qnew b.patch
+echo b > b
+hg add b
+hg qrefresh
+
+hg qnew c.patch
+echo c > c
+hg add c
+hg qrefresh
+
+hg qgoto a.patch
+hg qgoto c.patch
+hg qgoto b.patch
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-mq-qgoto.out	Tue May 08 13:10:27 2007 -0700
@@ -0,0 +1,6 @@
+adding a
+Now at: a.patch
+applying b.patch
+applying c.patch
+Now at: c.patch
+Now at: b.patch
--- a/tests/test-mq.out	Tue May 08 11:51:16 2007 -0700
+++ b/tests/test-mq.out	Tue May 08 13:10:27 2007 -0700
@@ -30,6 +30,7 @@
  qdelete      remove patches from queue
  qdiff        diff of the current patch
  qfold        fold the named patches into the current patch
+ qgoto        push or pop patches until named patch is at top of stack
  qguard       set or print guards for a patch
  qheader      Print the header of the topmost or specified patch
  qimport      import a patch