diff mercurial/ui.py @ 41484:7f366dd3df1f

hg: raise Abort on invalid path Currently, some os.path functions when opening repositories may raise an uncaught TypeError or ValueError if the path is invalid. Let's catch these exceptions and turn them into an Abort for convenience. Differential Revision: https://phab.mercurial-scm.org/D5772
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 30 Jan 2019 17:22:07 -0800
parents 876494fd967d
children 97ab4cbb342e
line wrap: on
line diff
--- a/mercurial/ui.py	Wed Jan 30 19:29:32 2019 -0500
+++ b/mercurial/ui.py	Wed Jan 30 17:22:07 2019 -0800
@@ -2051,7 +2051,11 @@
         This is its own function so that extensions can change the definition of
         'valid' in this case (like when pulling from a git repo into a hg
         one)."""
-        return os.path.isdir(os.path.join(path, '.hg'))
+        try:
+            return os.path.isdir(os.path.join(path, '.hg'))
+        # Python 2 may return TypeError. Python 3, ValueError.
+        except (TypeError, ValueError):
+            return False
 
     @property
     def suboptions(self):