[PATCH 1 of 1 STABLE V3] introduce new RequirementError (issue2649)

Adrian Buehlmann adrian at cadifra.com
Fri Feb 18 19:05:59 CST 2011


# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1298057125 -3600
# Branch stable
# Node ID f71af078110789215a58bad5fb769b6d041eb7bf
# Parent  b366a5e021c6d8d1e3774d7829af2c0c74d2163c
introduce new RequirementError (issue2649)

This improves the misleading error message

  $ hg identify
  abort: there is no Mercurial repository here (.hg not found)!

to the more explicit

  $ hg identify
  abort: requirement 'fake' not supported!

for all commands in commands.optionalrepo, which includes the identify
and serve commands in particular.

This is for the case when a new entry in .hg/requires will be defined
in a future Mercurial release.

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -576,6 +576,8 @@ def _dispatch(ui, args):
             if not repo.local():
                 raise util.Abort(_("repository '%s' is not local") % path)
             ui.setconfig("bundle", "mainreporoot", repo.root)
+        except error.RequirementError:
+            raise
         except error.RepoError:
             if cmd not in commands.optionalrepo.split():
                 if args and not path: # try to infer -R from command args
diff --git a/mercurial/error.py b/mercurial/error.py
--- a/mercurial/error.py
+++ b/mercurial/error.py
@@ -51,6 +51,10 @@ class RepoLookupError(RepoError):
 class CapabilityError(RepoError):
     pass
 
+class RequirementError(RepoError):
+    """Exception raised if .hg/requires has an unknown entry."""
+    pass
+
 class LockError(IOError):
     def __init__(self, errno, strerror, filename, desc):
         IOError.__init__(self, errno, strerror, filename)
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -75,7 +75,8 @@ class localrepository(repo.repository):
                 if inst.errno != errno.ENOENT:
                     raise
             for r in requirements - self.supported:
-                raise error.RepoError(_("requirement '%s' not supported") % r)
+                raise error.RequirementError(
+                          _("requirement '%s' not supported") % r)
 
         self.sharedpath = self.path
         try:
diff --git a/mercurial/statichttprepo.py b/mercurial/statichttprepo.py
--- a/mercurial/statichttprepo.py
+++ b/mercurial/statichttprepo.py
@@ -112,7 +112,8 @@ class statichttprepository(localrepo.loc
         # check them
         for r in requirements:
             if r not in self.supported:
-                raise error.RepoError(_("requirement '%s' not supported") % r)
+                raise error.RequirementError(
+                        _("requirement '%s' not supported") % r)
 
         # setup store
         self.store = store.store(requirements, self.path, opener)
diff --git a/tests/test-commit.t b/tests/test-commit.t
--- a/tests/test-commit.t
+++ b/tests/test-commit.t
@@ -92,6 +92,15 @@ An empty date was interpreted as epoch o
   $ hg commit -d '' -m commit-no-date
   $ hg tip --template '{date|isodate}\n' | grep '1970'
   [1]
+
+Make sure we do not obscure unknown requires file entries (issue2649)
+
+  $ echo foo >> foo
+  $ echo fake >> .hg/requires
+  $ hg commit -m bla
+  abort: requirement 'fake' not supported!
+  [255]
+
   $ cd ..
 
 
diff --git a/tests/test-identify.t b/tests/test-identify.t
--- a/tests/test-identify.t
+++ b/tests/test-identify.t
@@ -67,3 +67,16 @@ remote with tags?
   $ hg id -t http://localhost:$HGPORT1/
   abort: can't query remote revision number, branch, or tags
   [255]
+
+Make sure we do not obscure unknown requires file entries (issue2649)
+
+  $ echo fake >> .hg/requires
+  $ hg id
+  abort: requirement 'fake' not supported!
+  [255]
+
+  $ cd ..
+  $ hg id test
+  abort: requirement 'fake' not supported!
+  [255]
+


More information about the Mercurial-devel mailing list