Patchwork [5,of,5] remotenames: abort if literal revset pattern matches nothing

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 5, 2018, 1:30 p.m.
Message ID <4fcbf5e3c74ec52e7802.1538746200@mimosa>
Download mbox | patch
Permalink /patch/35488/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 5, 2018, 1:30 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1538743437 -32400
#      Fri Oct 05 21:43:57 2018 +0900
# Node ID 4fcbf5e3c74ec52e78026376b09d4cb4e7ff9783
# Parent  5b90cef0b86041b89572d4655e4507a9641c3be4
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.

Patch

diff --git a/hgext/remotenames.py b/hgext/remotenames.py
--- a/hgext/remotenames.py
+++ b/hgext/remotenames.py
@@ -33,6 +33,7 @@  from mercurial.node import (
 )
 from mercurial import (
     bookmarks,
+    error,
     extensions,
     logexchange,
     namespaces,
@@ -355,6 +356,7 @@  def _revsetutil(repo, subset, x, rtypes)
         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 @@  def _revsetutil(repo, subset, x, rtypes)
                 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)
diff --git a/tests/test-logexchange.t b/tests/test-logexchange.t
--- a/tests/test-logexchange.t
+++ b/tests/test-logexchange.t
@@ -478,13 +478,23 @@  Testing for a single remote name which e
   |
   ~
 
-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.