alias: fail gracefully when invalid global options are given (issue2442)
authorSteve Losh <steve@stevelosh.com>
Sun, 17 Oct 2010 13:24:37 -0400
changeset 12748 d10369fefd01
parent 12747 175fb1b193f4
child 12749 338b4b615d33
alias: fail gracefully when invalid global options are given (issue2442) This patch modifies the check for shell aliases to prevent crashing when an invalid global option is given. When an invalid global option is given the check will simply return and let the normal error handling for this case happen.
mercurial/dispatch.py
tests/test-alias.t
--- a/mercurial/dispatch.py	Thu Oct 07 13:44:17 2010 -0700
+++ b/mercurial/dispatch.py	Sun Oct 17 13:24:37 2010 -0400
@@ -433,7 +433,11 @@
     cwd = os.getcwd()
     norepo = commands.norepo
     options = {}
-    args = fancyopts.fancyopts(args, commands.globalopts, options)
+
+    try:
+        args = fancyopts.fancyopts(args, commands.globalopts, options)
+    except fancyopts.getopt.GetoptError:
+        return
 
     if not args:
         return
--- a/tests/test-alias.t	Thu Oct 07 13:44:17 2010 -0700
+++ b/tests/test-alias.t	Sun Oct 17 13:24:37 2010 -0400
@@ -261,3 +261,85 @@
   
   use "hg -v help rt" to show global options
   [255]
+
+invalid global arguments for normal commands, aliases, and shell aliases
+
+  $ hg --invalid root
+  hg: option --invalid not recognized
+  Mercurial Distributed SCM
+  
+  basic commands:
+  
+   add        add the specified files on the next commit
+   annotate   show changeset information by line for each file
+   clone      make a copy of an existing repository
+   commit     commit the specified files or all outstanding changes
+   diff       diff repository (or selected files)
+   export     dump the header and diffs for one or more changesets
+   forget     forget the specified files on the next commit
+   init       create a new repository in the given directory
+   log        show revision history of entire repository or files
+   merge      merge working directory with another revision
+   pull       pull changes from the specified source
+   push       push changes to the specified destination
+   remove     remove the specified files on the next commit
+   serve      start stand-alone webserver
+   status     show changed files in the working directory
+   summary    summarize working directory state
+   update     update working directory (or switch revisions)
+  
+  use "hg help" for the full list of commands or "hg -v" for details
+  [255]
+  $ hg --invalid mylog
+  hg: option --invalid not recognized
+  Mercurial Distributed SCM
+  
+  basic commands:
+  
+   add        add the specified files on the next commit
+   annotate   show changeset information by line for each file
+   clone      make a copy of an existing repository
+   commit     commit the specified files or all outstanding changes
+   diff       diff repository (or selected files)
+   export     dump the header and diffs for one or more changesets
+   forget     forget the specified files on the next commit
+   init       create a new repository in the given directory
+   log        show revision history of entire repository or files
+   merge      merge working directory with another revision
+   pull       pull changes from the specified source
+   push       push changes to the specified destination
+   remove     remove the specified files on the next commit
+   serve      start stand-alone webserver
+   status     show changed files in the working directory
+   summary    summarize working directory state
+   update     update working directory (or switch revisions)
+  
+  use "hg help" for the full list of commands or "hg -v" for details
+  [255]
+  $ hg --invalid blank
+  hg: option --invalid not recognized
+  Mercurial Distributed SCM
+  
+  basic commands:
+  
+   add        add the specified files on the next commit
+   annotate   show changeset information by line for each file
+   clone      make a copy of an existing repository
+   commit     commit the specified files or all outstanding changes
+   diff       diff repository (or selected files)
+   export     dump the header and diffs for one or more changesets
+   forget     forget the specified files on the next commit
+   init       create a new repository in the given directory
+   log        show revision history of entire repository or files
+   merge      merge working directory with another revision
+   pull       pull changes from the specified source
+   push       push changes to the specified destination
+   remove     remove the specified files on the next commit
+   serve      start stand-alone webserver
+   status     show changed files in the working directory
+   summary    summarize working directory state
+   update     update working directory (or switch revisions)
+  
+  use "hg help" for the full list of commands or "hg -v" for details
+  [255]
+