From 74b71f464ec326bcb133521508e7699b008e6364 Mon Sep 17 00:00:00 2001 From: Dusty Phillips Date: Wed, 6 Mar 2013 15:58:44 -0700 Subject: [PATCH] Catch a RepoError if an hg clone fails and print a nice message instead of a freaky traceback. Fixes #50. --- gitifyhg.py | 13 ++++++++++--- test/test_clone.py | 8 ++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/gitifyhg.py b/gitifyhg.py index edaa3d2..482315d 100644 --- a/gitifyhg.py +++ b/gitifyhg.py @@ -38,7 +38,7 @@ from mercurial.ui import ui from mercurial.context import memctx, memfilectx -from mercurial.error import Abort +from mercurial.error import Abort, RepoError from mercurial import encoding from mercurial.bookmarks import listbookmarks, readcurrent, pushbookmark from mercurial.util import sha1 @@ -311,8 +311,15 @@ def build_repo(self, url): local_path = self.remotedir.joinpath('clone') if not local_path.exists(): - self.peer, dstpeer = hg.clone(myui, {}, url.encode('utf-8'), - local_path.encode('utf-8'), update=False, pull=True) + try: + self.peer, dstpeer = hg.clone(myui, {}, url.encode('utf-8'), + local_path.encode('utf-8'), update=False, pull=True) + except (RepoError, Abort) as e: + sys.stderr.write("abort: %s\n" % e) + if e.hint: + sys.stderr.write("(%s)\n" % e.hint) + sys.exit(-1) + self.repo = dstpeer.local() else: self.repo = hg.repository(myui, local_path.encode('utf-8')) diff --git a/test/test_clone.py b/test/test_clone.py index 2ea278f..0fd25b9 100644 --- a/test/test_clone.py +++ b/test/test_clone.py @@ -447,3 +447,11 @@ def test_clone_replace_dir_by_symlink(git_dir, hg_repo): assert p('dir_or_link').isfile() assert p('dir_or_link').islink() + + +def test_clone_remote_fail(git_dir): + # Ensure it has an error message instead of a exception if you try + # to clone something which cannot be cloned. + err = sh.git.clone("gitifyhg::ssh://hg@hg.example.domain/repo", + _ok_code=128).stderr + assert "Traceback" not in err