# HG changeset patch # User Edouard Gomez # Date 1181250970 -7200 # Node ID d634b61e9cecfe2728ad57a14821f4f66ef4f6c5 # Parent ce1fed4a5b9458dcd95a36140544d829702183b9 Add some more smart when initializing destination repository diff --git a/hgext/convert/__init__.py b/hgext/convert/__init__.py --- a/hgext/convert/__init__.py +++ b/hgext/convert/__init__.py @@ -6,7 +6,7 @@ # of the GNU General Public License, incorporated herein by reference. import sys, os, zlib, sha, time, re, locale, socket -from mercurial import hg, ui, util, commands +from mercurial import hg, ui, util, commands, repo commands.norepo += " convert" @@ -701,9 +701,28 @@ def _convert(ui, src, dest=None, mapfile if not dest: dest = src + "-hg" ui.status("assuming destination %s\n" % dest) - if not os.path.isdir(dest): - ui.status("creating repository %s\n" % dest) - os.system("hg init " + dest) + + # Try to be smart and initalize things when required + if os.path.isdir(dest): + if len(os.listdir(dest)) > 0: + try: + hg.repository(ui, dest) + ui.status("destination %s is a Mercurial repository\n" % dest) + except repo.RepoError: + raise util.Abort( +"""destination directory %s is not empty. +Please specify an empty directory to be initialized or an already initialized +mercurial repository +""" % dest) + else: + ui.status("initializing destination %s repository\n" % dest) + hg.repository(ui, dest, create=True) + elif os.path.exists(dest): + raise util.Abort("destination %s exists and is not a directory\n" % dest) + else: + ui.status("initializing destination %s repository\n" % dest) + hg.repository(ui, dest, create=True) + destc = converter(ui, dest) if not hasattr(destc, "putcommit"): raise util.Abort("%s: can't write to this repo type\n" % src)