Commits

Patrick Mézard  committed 761a871

rebuildmeta: accept unrelated svn repo with --unsafe-skip-uuid-check

This is useful when switching from an svnsync mirror to the real thing.

  • Participants
  • Parent commits 6918f60

Comments (0)

Files changed (3)

File hgsubversion/__init__.py

           ('', '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> ...',
          ),

File hgsubversion/svncommands.py

     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"
         # 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

File tests/test_utility_commands.py

     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),
           ]