[PATCH hglib] context: raise same error when not found for all hg versions

Alexander Plavin me at aplavin.ru
Thu Apr 25 17:31:11 CDT 2013


# HG changeset patch
# User Alexander Plavin <me at aplavin.ru>
# Date 1366926368 -14400
# Node ID 039faa0bddbbd2531c7c9fb4fc8e9e6cfd5ddf74
# Parent  9324a89dd84e1562b87556a3b2788fdf04ba8179
context: raise same error when not found for all hg versions

hg log behavior changed, so modify context constructor to account for this

diff -r 9324a89dd84e -r 039faa0bddbb hglib/context.py
--- a/hglib/context.py	Tue Apr 23 22:11:26 2013 +0200
+++ b/hglib/context.py	Fri Apr 26 01:46:08 2013 +0400
@@ -1,3 +1,4 @@
+from hglib.error import CommandError
 import client, util, templates
 
 _nullcset = ['-1', '000000000000000000000000000000000000000', '', '', '', '', '']
@@ -18,8 +19,13 @@
             if isinstance(changeid, (long, int)):
                 changeid = 'rev(%d)' % changeid
 
-            cset = self._repo.log(changeid)
-            if not len(cset):
+            notfound = False
+            try:
+                cset = self._repo.log(changeid)
+            except CommandError:
+                notfound = True
+
+            if notfound or not len(cset):
                 raise ValueError('changeid %r not found in repo' % changeid)
             if len(cset) > 1:
                 raise ValueError('changeid must yield a single changeset')
diff -r 9324a89dd84e -r 039faa0bddbb tests/test-context.py
--- a/tests/test-context.py	Tue Apr 23 22:11:26 2013 +0200
+++ b/tests/test-context.py	Fri Apr 26 01:46:08 2013 +0400
@@ -1,9 +1,10 @@
+from hglib.error import CommandError
 import common, hglib
 from hglib import context
 
 class test_context(common.basetest):
     def test_non_existent(self):
-        self.assertRaises(ValueError, context.changectx, self.client, 'foo')
+        self.assertRaisesRegexp(ValueError, 'not found', context.changectx, self.client, 'foo')
 
     def test_basic(self):
         self.append('a', 'a')
diff -r 9324a89dd84e -r 039faa0bddbb tests/test-log.py
--- a/tests/test-log.py	Tue Apr 23 22:11:26 2013 +0200
+++ b/tests/test-log.py	Fri Apr 26 01:46:08 2013 +0400
@@ -16,3 +16,9 @@
 
         self.assertEquals(revs[0], self.client.log('0')[0])
         self.assertEquals(self.client.log(), self.client.log(files=['a']))
+
+    # def test_errors(self):
+    #     self.assertRaisesRegexp(CommandError, 'abort: unknown revision', self.client.log, 'foo')
+    #     self.append('a', 'a')
+    #     self.client.commit('first', addremove=True)
+    #     self.assertRaisesRegexp(CommandError, 'abort: unknown revision', self.client.log, 'bar')
\ No newline at end of file


More information about the Mercurial-devel mailing list