changeset 918:761a87134501

rebuildmeta: accept unrelated svn repo with --unsafe-skip-uuid-check This is useful when switching from an svnsync mirror to the real thing.
author Patrick Mezard <patrick@mezard.eu>
date Tue, 26 Jun 2012 09:23:37 +0200
parents 6918f60d0e28
children 92bd7b3678ea
files hgsubversion/__init__.py hgsubversion/svncommands.py tests/test_utility_commands.py
diffstat 3 files changed, 25 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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 <subcommand> ...',
          ),
--- 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
--- 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),
           ]