changeset 7973:db3a68fd9387

convert: attempt to check repo type before checking for tool
author Matt Mackall <mpm@selenic.com>
date Sat, 04 Apr 2009 12:28:13 -0500
parents 425a30ddfff6
children a8a719ff150a
files hgext/convert/bzr.py hgext/convert/darcs.py hgext/convert/monotone.py hgext/convert/p4.py hgext/convert/subversion.py tests/test-convert.out
diffstat 6 files changed, 23 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/bzr.py	Sat Apr 04 19:43:00 2009 +0200
+++ b/hgext/convert/bzr.py	Sat Apr 04 12:28:13 2009 -0500
@@ -27,15 +27,15 @@
     def __init__(self, ui, path, rev=None):
         super(bzr_source, self).__init__(ui, path, rev=rev)
 
+        if not os.path.exists(os.path.join(path, '.bzr')):
+            raise NoRepo('%s does not look like a Bazaar repo' % path)
+
         try:
             # access bzrlib stuff
             branch
         except NameError:
             raise NoRepo('Bazaar modules could not be loaded')
 
-        if not os.path.exists(os.path.join(path, '.bzr')):
-            raise NoRepo('%s does not look like a Bazaar repo' % path)
-
         path = os.path.abspath(path)
         self.branch = branch.Branch.open(path)
         self.sourcerepo = self.branch.repository
--- a/hgext/convert/darcs.py	Sat Apr 04 19:43:00 2009 +0200
+++ b/hgext/convert/darcs.py	Sat Apr 04 12:28:13 2009 -0500
@@ -24,6 +24,9 @@
 
         # check for _darcs, ElementTree, _darcs/inventory so that we can
         # easily skip test-convert-darcs if ElementTree is not around
+        if not os.path.exists(os.path.join(path, '_darcs', 'inventories')):
+            raise NoRepo("%s does not look like a darcs repo" % path)
+
         if not os.path.exists(os.path.join(path, '_darcs')):
             raise NoRepo("%s does not look like a darcs repo" % path)
 
@@ -32,9 +35,6 @@
         if ElementTree is None:
             raise util.Abort(_("Python ElementTree module is not available"))
 
-        if not os.path.exists(os.path.join(path, '_darcs', 'inventories')):
-            raise NoRepo("%s does not look like a darcs repo" % path)
-
         self.path = os.path.realpath(path)
 
         self.lastrev = None
--- a/hgext/convert/monotone.py	Sat Apr 04 19:43:00 2009 +0200
+++ b/hgext/convert/monotone.py	Sat Apr 04 12:28:13 2009 -0500
@@ -14,6 +14,10 @@
         self.ui = ui
         self.path = path
 
+        norepo = NoRepo (_("%s does not look like a monotone repo") % path)
+        if not os.path.exists(os.path.join(path, '_MTN')):
+            raise norepo
+
         # regular expressions for parsing monotone output
         space    = r'\s*'
         name     = r'\s+"((?:\\"|[^"])*)"\s*'
@@ -39,10 +43,6 @@
         self.files = None
         self.dirs  = None
 
-        norepo = NoRepo (_("%s does not look like a monotone repo") % path)
-        if not os.path.exists(path):
-            raise norepo
-
         checktool('mtn', abort=False)
 
         # test if there are any revisions
--- a/hgext/convert/p4.py	Sat Apr 04 19:43:00 2009 +0200
+++ b/hgext/convert/p4.py	Sat Apr 04 12:28:13 2009 -0500
@@ -10,7 +10,7 @@
 from mercurial import util
 from mercurial.i18n import _
 
-from common import commit, converter_source, checktool
+from common import commit, converter_source, checktool, NoRepo
 import marshal
 
 def loaditer(f):
@@ -28,6 +28,9 @@
     def __init__(self, ui, path, rev=None):
         super(p4_source, self).__init__(ui, path, rev=rev)
 
+        if not path.startswith('//'):
+            raise NoRepo('%s does not look like a P4 repo' % path)
+
         checktool('p4', abort=False)
 
         self.p4changes = {}
--- a/hgext/convert/subversion.py	Sat Apr 04 19:43:00 2009 +0200
+++ b/hgext/convert/subversion.py	Sat Apr 04 12:28:13 2009 -0500
@@ -152,6 +152,12 @@
     def __init__(self, ui, url, rev=None):
         super(svn_source, self).__init__(ui, url, rev=rev)
 
+        if not (url.startswith('svn://') or url.startswith('svn+ssh://') or
+                (os.path.exists(url) and
+                 os.path.exists(os.path.join(url, '.svn'))) or
+                 (url.startswith('file://'))):
+            raise NoRepo("%s does not look like a Subversion repo" % url)
+
         try:
             SubversionException
         except NameError:
--- a/tests/test-convert.out	Sat Apr 04 19:43:00 2009 +0200
+++ b/tests/test-convert.out	Sat Apr 04 12:28:13 2009 -0500
@@ -231,11 +231,11 @@
 initializing destination emptydir-hg repository
 emptydir does not look like a CVS checkout
 emptydir does not look like a Git repo
-.../emptydir does not look like a Subversion repo
+emptydir does not look like a Subversion repo
 emptydir is not a local Mercurial repo
 emptydir does not look like a darcs repo
-cannot find required "mtn" tool
+emptydir does not look like a monotone repo
 emptydir does not look like a GNU Arch repo
 emptydir does not look like a Bazaar repo
-cannot find required "p4" tool
+emptydir does not look like a P4 repo
 abort: emptydir: missing or unsupported repository