remotenames: abort if literal revset pattern matches nothing
authorYuya Nishihara <yuya@tcha.org>
Fri, 05 Oct 2018 21:43:57 +0900
changeset 40069 fd4d59cf2ebb
parent 40068 b313f2c3b8c6
child 40070 8feae5b989bc
remotenames: abort if literal revset pattern matches nothing This is the convention of the other namespace revsets such as tag(). Let's make the remote variants do the same.
hgext/remotenames.py
tests/test-logexchange.t
--- a/hgext/remotenames.py	Fri Oct 05 21:39:41 2018 +0900
+++ b/hgext/remotenames.py	Fri Oct 05 21:43:57 2018 +0900
@@ -33,6 +33,7 @@
 )
 from mercurial import (
     bookmarks,
+    error,
     extensions,
     logexchange,
     namespaces,
@@ -355,6 +356,7 @@
         kind, pattern, matcher = stringutil.stringmatcher(
             revsetlang.getstring(args[0], _('argument must be a string')))
     else:
+        kind = pattern = None
         matcher = util.always
 
     nodes = set()
@@ -366,6 +368,9 @@
                 if not matcher(name):
                     continue
                 nodes.update(ns.nodes(repo, name))
+    if kind == 'literal' and not nodes:
+        raise error.RepoLookupError(_("remote name '%s' does not exist")
+                                    % pattern)
 
     revs = (cl.rev(n) for n in nodes if cl.hasnode(n))
     return subset & smartset.baseset(revs)
--- a/tests/test-logexchange.t	Fri Oct 05 21:39:41 2018 +0900
+++ b/tests/test-logexchange.t	Fri Oct 05 21:43:57 2018 +0900
@@ -478,13 +478,23 @@
   |
   ~
 
-Testing for a single name which does not exists
+Testing for a literal name which does not exists, which should fail.
 
   $ hg log -r 'remotebranches(def)' -GT "{rev}:{node|short} {remotenames}\n"
+  abort: remote name 'def' does not exist!
+  [255]
 
   $ hg log -r 'remotebookmarks("server3")' -GT "{rev}:{node|short} {remotenames}\n"
+  abort: remote name 'server3' does not exist!
+  [255]
 
   $ hg log -r 'remotenames("server3")' -GT "{rev}:{node|short} {remotenames}\n"
+  abort: remote name 'server3' does not exist!
+  [255]
+
+Testing for a pattern which does not match anything, which shouldn't fail.
+
+  $ hg log -r 'remotenames("re:^server3$")'
 
 Testing for multiple names, which is not supported.