mercurial/dispatch.py
changeset 52745 8780d5707812
parent 52744 25b344f2aeef
--- a/mercurial/dispatch.py	Wed Jan 29 16:09:06 2025 -0500
+++ b/mercurial/dispatch.py	Thu Feb 06 00:56:25 2025 -0500
@@ -1151,7 +1151,22 @@
             encoding.fallbackencoding = fallback
 
         fullargs = args
-        cmd, func, args, options, cmdoptions = _parse(lui, args)
+        try:
+            cmd, func, args, options, cmdoptions = _parse(lui, args)
+        except error.CommandError as e:
+            cause = e.__context__
+            if isinstance(cause, getopt.GetoptError):
+                if cause.opt and "config".startswith(cause.opt):
+                    # pycompat._getoptbwrapper() decodes bytes with latin-1
+                    opt = cause.opt.encode('latin-1')
+                    all_long = {o[1] for o in commands.globalopts}
+                    possible = [o for o in all_long if o.startswith(opt)]
+
+                    if len(possible) != 1:
+                        raise error.InputError(
+                            _(b"option --config may not be abbreviated")
+                        )
+            raise
 
         # store the canonical command name in request object for later access
         req.canonical_command = cmd