changeset 39707:2f067e365532

localrepo: check for .hg/ directory in makelocalrepository() As part of this, we move the check to before .hg/hgrc is loaded, as it makes sense to check for the directory before attempting to open a file in it. Differential Revision: https://phab.mercurial-scm.org/D4567
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 12 Sep 2018 12:36:07 -0700
parents e0c5017124b3
children 6a3162ed881d
files mercurial/localrepo.py
diffstat 1 files changed, 17 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/localrepo.py	Wed Sep 12 11:44:57 2018 -0700
+++ b/mercurial/localrepo.py	Wed Sep 12 12:36:07 2018 -0700
@@ -397,6 +397,17 @@
     hgpath = wdirvfs.join(b'.hg')
     hgvfs = vfsmod.vfs(hgpath, cacheaudited=True)
 
+    # The .hg/ path should exist and should be a directory. All other
+    # cases are errors.
+    if not hgvfs.isdir():
+        try:
+            hgvfs.stat()
+        except OSError as e:
+            if e.errno != errno.ENOENT:
+                raise
+
+        raise error.RepoError(_(b'repository %s not found') % path)
+
     # The .hg/hgrc file may load extensions or contain config options
     # that influence repository construction. Attempt to load it and
     # process any new extensions that it may have pulled in.
@@ -503,7 +514,6 @@
         self.vfs = hgvfs
         self.path = hgvfs.base
 
-        self.requirements = set()
         self.filtername = None
         # svfs: usually rooted at .hg/store, used to access repository history
         # If this is a shared repository, this vfs may point to another
@@ -535,20 +545,12 @@
             if engine.revlogheader():
                 self.supported.add('exp-compression-%s' % name)
 
-        if not self.vfs.isdir():
-            try:
-                self.vfs.stat()
-            except OSError as inst:
-                if inst.errno != errno.ENOENT:
-                    raise
-            raise error.RepoError(_("repository %s not found") % origroot)
-        else:
-            try:
-                self.requirements = scmutil.readrequires(
-                        self.vfs, self.supported)
-            except IOError as inst:
-                if inst.errno != errno.ENOENT:
-                    raise
+        try:
+            self.requirements = scmutil.readrequires(self.vfs, self.supported)
+        except IOError as inst:
+            if inst.errno != errno.ENOENT:
+                raise
+            self.requirements = set()
 
         cachepath = self.vfs.join('cache')
         self.sharedpath = self.path