bisect: improve option validation message
authorBrandon McCaig <bamccaig@gmail.com>
Fri, 09 Jun 2017 20:12:39 -0400
changeset 32766 fbe9c4dcc8a0
parent 32765 041d976b662a
child 32767 e5dd44f78ac6
bisect: improve option validation message
mercurial/commands.py
tests/test-bisect.t
--- a/mercurial/commands.py	Sat Jun 10 10:24:33 2017 -0400
+++ b/mercurial/commands.py	Fri Jun 09 20:12:39 2017 -0400
@@ -9,6 +9,7 @@
 
 import difflib
 import errno
+import itertools
 import os
 import re
 import sys
@@ -768,9 +769,22 @@
             bad = True
         else:
             reset = True
-    elif extra or good + bad + skip + reset + extend + bool(command) > 1:
+    elif extra:
         raise error.Abort(_('incompatible arguments'))
 
+    incompatibles = {
+        '--bad': bad,
+        '--command': bool(command),
+        '--extend': extend,
+        '--good': good,
+        '--reset': reset,
+        '--skip': skip,
+    }
+
+    for left, right in itertools.combinations(sorted(incompatibles), 2):
+        if incompatibles[left] and incompatibles[right]:
+            raise error.Abort(_('%s and %s are incompatible') % (left, right))
+
     if reset:
         hbisect.resetstate(repo)
         return
--- a/tests/test-bisect.t	Sat Jun 10 10:24:33 2017 -0400
+++ b/tests/test-bisect.t	Fri Jun 09 20:12:39 2017 -0400
@@ -611,3 +611,51 @@
   date:        Thu Jan 01 00:00:26 1970 +0000
   summary:     msg 26
   
+Test the validation message when exclusive options are used:
+
+  $ hg bisect -r
+  $ hg bisect -b -c false
+  abort: --bad and --command are incompatible
+  [255]
+  $ hg bisect -b -e
+  abort: --bad and --extend are incompatible
+  [255]
+  $ hg bisect -b -g
+  abort: --bad and --good are incompatible
+  [255]
+  $ hg bisect -b -r
+  abort: --bad and --reset are incompatible
+  [255]
+  $ hg bisect -b -s
+  abort: --bad and --skip are incompatible
+  [255]
+  $ hg bisect -c false -e
+  abort: --command and --extend are incompatible
+  [255]
+  $ hg bisect -c false -g
+  abort: --command and --good are incompatible
+  [255]
+  $ hg bisect -c false -r
+  abort: --command and --reset are incompatible
+  [255]
+  $ hg bisect -c false -s
+  abort: --command and --skip are incompatible
+  [255]
+  $ hg bisect -e -g
+  abort: --extend and --good are incompatible
+  [255]
+  $ hg bisect -e -r
+  abort: --extend and --reset are incompatible
+  [255]
+  $ hg bisect -e -s
+  abort: --extend and --skip are incompatible
+  [255]
+  $ hg bisect -g -r
+  abort: --good and --reset are incompatible
+  [255]
+  $ hg bisect -g -s
+  abort: --good and --skip are incompatible
+  [255]
+  $ hg bisect -r -s
+  abort: --reset and --skip are incompatible
+  [255]