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.
This commit is contained in:
Dan Villiom Podlaski Christiansen 2010-11-11 21:32:22 +01:00
parent 1421248efb
commit 341229e195
2 changed files with 18 additions and 12 deletions

View File

@ -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.')

View File

@ -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()