Patchwork D10265: path: error out if the `path://` reference point to an unknown path

login
register
mail settings
Submitter phabricator
Date March 24, 2021, 8:53 a.m.
Message ID <differential-rev-PHID-DREV-2t3trezr6jvnzntnvv2i-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48579/
State Superseded
Headers show

Comments

phabricator - March 24, 2021, 8:53 a.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D10265

AFFECTED FILES
  mercurial/ui.py
  tests/test-paths.t

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-paths.t b/tests/test-paths.t
--- a/tests/test-paths.t
+++ b/tests/test-paths.t
@@ -370,3 +370,18 @@ 
   $ hg pull chain_path
   abort: cannot use `path://other_default`, "other_default" is also define as a `path://`
   [255]
+
+Test basic error cases
+----------------------
+
+  $ cat << EOF > .hg/hgrc
+  > [paths]
+  > error-missing=path://unknown
+  > EOF
+  $ hg path
+  abort: cannot use `path://unknown`, "unknown" is not a known path
+  [255]
+  $ hg pull error-missing
+  abort: cannot use `path://unknown`, "unknown" is not a known path
+  [255]
+
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -2339,7 +2339,12 @@ 
     def chain_path(self, ui, paths):
         if self.url.scheme == b'path':
             assert self.url.path is None
-            subpath = paths[self.url.host]
+            try:
+                subpath = paths[self.url.host]
+            except KeyError:
+                m = _('cannot use `%s`, "%s" is not a known path')
+                m %= (self.rawloc, self.url.host)
+                raise error.Abort(m)
             if subpath.raw_url.scheme == b'path':
                 m = _('cannot use `%s`, "%s" is also define as a `path://`')
                 m %= (self.rawloc, self.url.host)