# HG changeset patch # User Dan Villiom Podlaski Christiansen # Date 1289507542 -3600 # Node ID 174f03c288d44230c6183b4909544ca3f203fcd0 # Parent 6252f0cc7b7a0dd2ae305ab14495fd2fc3706557 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. diff --git a/hgsubversion/svnmeta.py b/hgsubversion/svnmeta.py --- 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.') diff --git a/tests/test_utility_commands.py b/tests/test_utility_commands.py --- 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()