Patchwork D6215: localrepo: don't allow lookup of working directory revision

login
register
mail settings
Submitter phabricator
Date April 5, 2019, 6:34 p.m.
Message ID <differential-rev-PHID-DREV-qoze33cpwthozvqfe26r-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/39513/
State Superseded
Headers show

Comments

phabricator - April 5, 2019, 6:34 p.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  It seems that repo.lookup(), which is what supports the "lookup" wire
  protocol command, should not allow the working copy revision
  input.
  
  This fixes both the pull test and the convert test I just added.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/localrepo.py
  tests/test-convert-hg-source.t
  tests/test-pull.t

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/tests/test-pull.t b/tests/test-pull.t
--- a/tests/test-pull.t
+++ b/tests/test-pull.t
@@ -76,10 +76,9 @@ 
   [255]
 
 Test pull of working copy revision
-BROKEN: should give a better error message
   $ hg pull -r 'ffffffffffff'
   pulling from http://foo@localhost:$HGPORT/
-  abort: b2a_hex() argument 1 must be string or buffer, not None!
+  abort: unknown revision 'ffffffffffff'!
   [255]
 
 Issue622: hg init && hg pull -u URL doesn't checkout default branch
diff --git a/tests/test-convert-hg-source.t b/tests/test-convert-hg-source.t
--- a/tests/test-convert-hg-source.t
+++ b/tests/test-convert-hg-source.t
@@ -221,11 +221,10 @@ 
   $ hg ci -Aqm 'the working copy is called ffffffffffff'
 
   $ cd ..
-BROKEN: crashes when the "ffffffffffff" is encountered
   $ hg convert commit-references new-commit-references -q \
-  >     --config convert.hg.startrev=1 2>&1 | grep TypeError
-  TypeError: b2a_hex() argument 1 must be string or buffer, not None
+  >     --config convert.hg.startrev=1 2>&1
   $ cd new-commit-references
   $ hg log -T '{node|short} {desc}\n'
+  0becf8e61603 the working copy is called ffffffffffff
   38a97fe212e7 the previous commit was 3cf70f7c1f3b
   3cf70f7c1f3b initial
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1564,7 +1564,10 @@ 
                 pass
 
     def lookup(self, key):
-        return scmutil.revsymbol(self, key).node()
+        node = scmutil.revsymbol(self, key).node()
+        if node is None:
+            raise error.RepoLookupError(_("unknown revision '%s'") % key)
+        return node
 
     def lookupbranch(self, key):
         if self.branchmap().hasbranch(key):