# HG changeset patch # User Patrick Mezard # Date 1340695417 -7200 # Node ID 761a8713450164a5754adff55223d6f08e37cfab # Parent 6918f60d0e286dae9fc04b269d170436db88a2e5 rebuildmeta: accept unrelated svn repo with --unsafe-skip-uuid-check This is useful when switching from an svnsync mirror to the real thing. diff --git a/hgsubversion/__init__.py b/hgsubversion/__init__.py --- a/hgsubversion/__init__.py +++ b/hgsubversion/__init__.py @@ -206,6 +206,8 @@ cmdtable = { ('', 'username', '', 'username for authentication'), ('', 'password', '', 'password for authentication'), ('r', 'rev', '', 'Mercurial revision'), + ('', 'unsafe-skip-uuid-check', False, + 'skip repository uuid check in rebuildmeta'), ], 'hg svn ...', ), diff --git a/hgsubversion/svncommands.py b/hgsubversion/svncommands.py --- a/hgsubversion/svncommands.py +++ b/hgsubversion/svncommands.py @@ -31,13 +31,13 @@ def updatemeta(ui, repo, args, **opts): return _buildmeta(ui, repo, args, partial=True) -def rebuildmeta(ui, repo, args, **opts): +def rebuildmeta(ui, repo, args, unsafe_skip_uuid_check=False, **opts): """rebuild hgsubversion metadata using values stored in revisions """ + return _buildmeta(ui, repo, args, partial=False, + skipuuid=unsafe_skip_uuid_check) - return _buildmeta(ui, repo, args, partial=False) - -def _buildmeta(ui, repo, args, partial=False): +def _buildmeta(ui, repo, args, partial=False, skipuuid=False): if repo is None: raise error.RepoError("There is no Mercurial repository" @@ -183,9 +183,12 @@ def _buildmeta(ui, repo, args, partial=F # write repository uuid if required if uuid is None: uuid = convinfo[4:40] - assert uuid == svn.uuid, 'UUIDs did not match!' + if not skipuuid: + if uuid != svn.uuid: + raise hgutil.Abort('remote svn repository identifier ' + 'does not match') uuidfile = open(os.path.join(svnmetadir, 'uuid'), 'w') - uuidfile.write(uuid) + uuidfile.write(svn.uuid) uuidfile.close() # don't reflect closed branches 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 @@ -308,6 +308,20 @@ missing file: binary3 def test_corruption_stupid(self): self.test_corruption(True) + def test_svnrebuildmeta(self): + otherpath = self.load_svndump('binaryfiles-broken.svndump') + otherurl = test_util.fileurl(otherpath) + self.load_and_fetch('replace_trunk_with_branch.svndump') + # rebuildmeta with original repo + svncommands.rebuildmeta(self.ui(), repo=self.repo, args=[]) + # rebuildmeta with unrelated repo + self.assertRaises(hgutil.Abort, + svncommands.rebuildmeta, + self.ui(), repo=self.repo, args=[otherurl]) + # rebuildmeta --unsafe-skip-uuid-check with unrelated repo + svncommands.rebuildmeta(self.ui(), repo=self.repo, args=[otherurl], + unsafe_skip_uuid_check=True) + def suite(): all_tests = [unittest.TestLoader().loadTestsFromTestCase(UtilityTests), ]