Skip to content

Commit

Permalink
Catch a RepoError if an hg clone fails and print a nice message inste…
Browse files Browse the repository at this point in the history
…ad of a freaky traceback.

Fixes #50.
  • Loading branch information
Dusty Phillips committed Mar 6, 2013
1 parent 5e23978 commit 74b71f4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
13 changes: 10 additions & 3 deletions gitifyhg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'))
Expand Down
8 changes: 8 additions & 0 deletions test/test_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 74b71f4

Please sign in to comment.