--- a/hgext/convert/__init__.py Sun Jul 01 15:02:15 2007 -0700
+++ b/hgext/convert/__init__.py Sun Jul 01 19:23:10 2007 -0700
@@ -10,7 +10,7 @@
from git import convert_git
from hg import convert_mercurial
-import os
+import os, shutil
from mercurial import hg, ui, util, commands
commands.norepo += " convert"
@@ -274,15 +274,12 @@
srcauthor=whatever string you want
'''
- srcc = converter(ui, src, rev=opts.get('rev'))
- if not hasattr(srcc, "getcommit"):
- raise util.Abort("%s: can't read from this repo type" % src)
-
if not dest:
dest = src + "-hg"
ui.status("assuming destination %s\n" % dest)
# Try to be smart and initalize things when required
+ created = False
if os.path.isdir(dest):
if len(os.listdir(dest)) > 0:
try:
@@ -297,16 +294,27 @@
else:
ui.status("initializing destination %s repository\n" % dest)
hg.repository(ui, dest, create=True)
+ created = True
elif os.path.exists(dest):
raise util.Abort("destination %s exists and is not a directory" % dest)
else:
ui.status("initializing destination %s repository\n" % dest)
hg.repository(ui, dest, create=True)
+ created = True
destc = converter(ui, dest)
if not hasattr(destc, "putcommit"):
raise util.Abort("%s: can't write to this repo type" % src)
+ try:
+ srcc = converter(ui, src, rev=opts.get('rev'))
+ if not hasattr(srcc, "getcommit"):
+ raise util.Abort("%s: can't read from this repo type" % src)
+ except Exception:
+ if created:
+ shutil.rmtree(dest, True)
+ raise
+
if not mapfile:
try:
mapfile = destc.mapfile()