[PATCH 4 of 4] mq: introduce mq.check setting

Patrick Mezard patrick at mezard.eu
Fri May 11 18:12:43 CDT 2012


# HG changeset patch
# User Patrick Mezard <patrick at mezard.eu>
# Date 1336774770 -7200
# Node ID ed81cb27341e285d539617ba961f48c69dd18135
# Parent  f4da2aeb000408aa54f59829acb092ec85914475
mq: introduce mq.check setting

When:

  [mq]
  check = True

is set, qpush, qpop and qgoto behave as if -c/--check were passed. If
incompatible options like -f/--force or --exact are set, this setting is
ignored.

This setting enables what many users expect mq default behaviour to be.

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -46,6 +46,17 @@
 
 You will by default be managing a patch queue named "patches". You can
 create other, independent patch queues with the :hg:`qqueue` command.
+
+If the working directory contains uncommitted files, qpush, qpop and
+qgoto abort immediately. If -f/--force is used, the changes are
+discarded. Setting:
+
+  [mq]
+  check = True
+
+make them behave as if -c/--check were passed, and non-conflicting
+local changes will be tolerated and preserved. If incompatible options
+such as -f/--force or --exact are passed, this setting is ignored.
 '''
 
 from mercurial.i18n import _
@@ -1986,6 +1997,14 @@
         self.removeundo(repo)
         return imported
 
+def fixcheckopts(ui, opts):
+    if (not ui.configbool('mq', 'check') or opts.get('force')
+        or opts.get('exact')):
+        return opts
+    opts = dict(opts)
+    opts['check'] = True
+    return opts
+
 @command("qdelete|qremove|qrm",
          [('k', 'keep', None, _('keep patch file')),
           ('r', 'rev', [],
@@ -2533,6 +2552,7 @@
     '''push or pop patches until named patch is at top of stack
 
     Returns 0 on success.'''
+    opts = fixcheckopts(ui, opts)
     q = repo.mq
     patch = q.lookup(patch)
     nobackup = opts.get('no_backup')
@@ -2687,6 +2707,7 @@
     q = repo.mq
     mergeq = None
 
+    opts = fixcheckopts(ui, opts)
     if opts.get('merge'):
         if opts.get('name'):
             newpath = repo.join(opts.get('name'))
@@ -2725,6 +2746,7 @@
 
     Return 0 on success.
     """
+    opts = fixcheckopts(ui, opts)
     localupdate = True
     if opts.get('name'):
         q = queue(ui, repo.path, repo.join(opts.get('name')))
diff --git a/tests/test-mq-qpush-fail.t b/tests/test-mq-qpush-fail.t
--- a/tests/test-mq-qpush-fail.t
+++ b/tests/test-mq-qpush-fail.t
@@ -387,3 +387,38 @@
   now at: p2
   $ hg st a
   M a
+
+test mq.check setting
+
+  $ hg --config mq.check=1 qpush
+  applying p3
+  now at: p3
+  $ hg st a
+  M a
+  $ hg --config mq.check=1 qpop
+  popping p3
+  now at: p2
+  $ hg st a
+  M a
+  $ hg --config mq.check=1 qgoto p3
+  applying p3
+  now at: p3
+  $ hg st a
+  M a
+  $ echo b >> b
+  $ hg --config mq.check=1 qpop --force
+  popping p3
+  now at: p2
+  $ hg st b
+  $ hg --config mq.check=1 qpush --exact
+  abort: local changes found, refresh first
+  [255]
+  $ hg revert -qa a
+  $ hg qpop
+  popping p2
+  patch queue now empty
+  $ echo a >> a
+  $ hg --config mq.check=1 qpush --force
+  applying p2
+  now at: p2
+  $ hg st a
diff --git a/tests/test-mq.t b/tests/test-mq.t
--- a/tests/test-mq.t
+++ b/tests/test-mq.t
@@ -59,6 +59,15 @@
   You will by default be managing a patch queue named "patches". You can create
   other, independent patch queues with the "hg qqueue" command.
   
+  If the working directory contains uncommitted files, qpush, qpop and qgoto
+  abort immediately. If -f/--force is used, the changes are discarded. Setting:
+  
+    [mq] check = True
+  
+  make them behave as if -c/--check were passed, and non-conflicting local
+  changes will be tolerated and preserved. If incompatible options such as
+  -f/--force or --exact are passed, this setting is ignored.
+  
   list of commands:
   
    qapplied      print the patches already applied


More information about the Mercurial-devel mailing list