changeset 746:174f03c288d4

svnmeta: abort when no UUID given and none is stored on disk. Previously, not passing a UUID when instantiating an SVNMeta instance would cause it to succeed even if no UUID was previously known. First when the UUID was actually read would an exception be raised. This slight refactoring of _set_uuid() makes it so an exception is raised immediately. While at it, the exception message is changed to be slightly more accurate and helpful.
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Thu, 11 Nov 2010 21:32:22 +0100
parents 6252f0cc7b7a
children 34b25f6bc4ef
files hgsubversion/svnmeta.py tests/test_utility_commands.py
diffstat 2 files changed, 18 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/svnmeta.py
+++ b/hgsubversion/svnmeta.py
@@ -134,22 +134,19 @@ class SVNMeta(object):
             return self.__uuid
 
     def _set_uuid(self, uuid):
-        if not uuid:
-            return
-        elif os.path.isfile(os.path.join(self.meta_data_dir, 'uuid')):
+        if os.path.isfile(os.path.join(self.meta_data_dir, 'uuid')):
             stored_uuid = self._get_uuid()
             assert stored_uuid
-            if uuid != stored_uuid:
+            if uuid and uuid != stored_uuid:
                 raise hgutil.Abort('unable to operate on unrelated repository')
+        elif uuid:
+            f = open(os.path.join(self.meta_data_dir, 'uuid'), 'w')
+            f.write(uuid)
+            f.close()
+            self.__uuid = uuid
         else:
-            if uuid:
-                f = open(os.path.join(self.meta_data_dir, 'uuid'), 'w')
-                f.write(uuid)
-                f.close()
-            else:
-                raise hgutil.Abort('unable to operate on unrelated repository')
-
-        self.__uuid = uuid
+            raise hgutil.Abort("hgsubversion metadata unavailable; "
+                               "please run 'hg svn rebuildmeta'")
 
     uuid = property(_get_uuid, _set_uuid, None,
                     'Error-checked UUID of source Subversion repository.')
--- a/tests/test_utility_commands.py
+++ b/tests/test_utility_commands.py
@@ -9,6 +9,7 @@ from mercurial import revlog
 from mercurial import context
 from mercurial import node
 from mercurial import commands
+from mercurial import util as hgutil
 
 from hgsubversion import util
 from hgsubversion import svncommands
@@ -81,6 +82,14 @@ class UtilityTests(test_util.TestBase):
                      })
         self.assertMultiLineEqual(expected, actual)
 
+    def test_info_missing_metadata(self):
+        repo = self._load_fixture_and_fetch('two_heads.svndump')
+        test_util.rmtree(repo.join('svn'))
+        self.assertRaises(hgutil.Abort,
+                          repo.svnmeta)
+        self.assertRaises(hgutil.Abort,
+                          svncommands.info, self.ui, self.repo)
+
     def test_parent_output(self):
         self._load_fixture_and_fetch('two_heads.svndump')
         u = self.ui()