[PATCH 1 of 4 STABLE] dispatch: do not drop unpaired argument at _earlygetopt()

Yuya Nishihara yuya at tcha.org
Sat Nov 11 10:02:46 EST 2017


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1510369759 -32400
#      Sat Nov 11 12:09:19 2017 +0900
# Branch stable
# Node ID ffd80f114a5568161658da273af2942f471e05bc
# Parent  691524f0bbf6cd44fc26ebfce046e6c4888a1b0f
dispatch: do not drop unpaired argument at _earlygetopt()

Before, "hg log -R" just worked.

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -661,6 +661,10 @@ def _earlygetopt(aliases, args):
     >>> args = [b'x', b'-Rbar', b'y']
     >>> _earlygetopt([b'-R'], args), args
     (['bar'], ['x', 'y'])
+
+    >>> args = [b'x', b'-R', b'--', b'y']
+    >>> _earlygetopt([b'-R'], args), args
+    ([], ['x', '-R', '--', 'y'])
     """
     try:
         argcount = args.index("--")
@@ -675,14 +679,15 @@ def _earlygetopt(aliases, args):
         if equals > -1:
             arg = arg[:equals]
         if arg in aliases:
-            del args[pos]
             if equals > -1:
+                del args[pos]
                 values.append(fullarg[equals + 1:])
                 argcount -= 1
             else:
                 if pos + 1 >= argcount:
                     # ignore and let getopt report an error if there is no value
                     break
+                del args[pos]
                 values.append(args.pop(pos))
                 argcount -= 2
         elif arg[:2] in shortopts:
diff --git a/tests/test-bookmarks-pushpull.t b/tests/test-bookmarks-pushpull.t
--- a/tests/test-bookmarks-pushpull.t
+++ b/tests/test-bookmarks-pushpull.t
@@ -175,7 +175,7 @@ divergent bookmarks
      Z                         1:0d2164f0ce0d
 
   $ cd ../b
-  $ hg up --config
+  $ hg up
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   updating bookmark foobar
   $ echo c2 > f2
diff --git a/tests/test-dispatch.t b/tests/test-dispatch.t
--- a/tests/test-dispatch.t
+++ b/tests/test-dispatch.t
@@ -30,6 +30,18 @@ Missing arg:
   (use 'hg cat -h' to show more help)
   [255]
 
+Missing parameter for early option:
+
+  $ hg log -R 2>&1 | grep 'hg log'
+  hg log: option -R requires argument
+  hg log [OPTION]... [FILE]
+  (use 'hg log -h' to show more help)
+
+  $ hg log -R -- 2>&1 | grep 'hg log'
+  hg log: option -R requires argument
+  hg log [OPTION]... [FILE]
+  (use 'hg log -h' to show more help)
+
 [defaults]
 
   $ hg cat a
diff --git a/tests/test-setdiscovery.t b/tests/test-setdiscovery.t
--- a/tests/test-setdiscovery.t
+++ b/tests/test-setdiscovery.t
@@ -17,7 +17,7 @@ Function to test discovery between two r
   >     hg -R a debugdiscovery b --verbose --debug --config progress.debug=true
   >     echo
   >     echo "% -- b -> a tree"
-  >     hg -R b debugdiscovery a --verbose --old --config
+  >     hg -R b debugdiscovery a --verbose --old
   >     echo
   >     echo "% -- b -> a set"
   >     hg -R b debugdiscovery a --verbose --debug --config progress.debug=true


More information about the Mercurial-devel mailing list