Skip to content

Commit 74b71f4

Browse files
author
Dusty Phillips
committed
Catch a RepoError if an hg clone fails and print a nice message instead of a freaky traceback.
Fixes #50.
1 parent 5e23978 commit 74b71f4

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

gitifyhg.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
from mercurial.ui import ui
4040
from mercurial.context import memctx, memfilectx
41-
from mercurial.error import Abort
41+
from mercurial.error import Abort, RepoError
4242
from mercurial import encoding
4343
from mercurial.bookmarks import listbookmarks, readcurrent, pushbookmark
4444
from mercurial.util import sha1
@@ -311,8 +311,15 @@ def build_repo(self, url):
311311

312312
local_path = self.remotedir.joinpath('clone')
313313
if not local_path.exists():
314-
self.peer, dstpeer = hg.clone(myui, {}, url.encode('utf-8'),
315-
local_path.encode('utf-8'), update=False, pull=True)
314+
try:
315+
self.peer, dstpeer = hg.clone(myui, {}, url.encode('utf-8'),
316+
local_path.encode('utf-8'), update=False, pull=True)
317+
except (RepoError, Abort) as e:
318+
sys.stderr.write("abort: %s\n" % e)
319+
if e.hint:
320+
sys.stderr.write("(%s)\n" % e.hint)
321+
sys.exit(-1)
322+
316323
self.repo = dstpeer.local()
317324
else:
318325
self.repo = hg.repository(myui, local_path.encode('utf-8'))

test/test_clone.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,3 +447,11 @@ def test_clone_replace_dir_by_symlink(git_dir, hg_repo):
447447

448448
assert p('dir_or_link').isfile()
449449
assert p('dir_or_link').islink()
450+
451+
452+
def test_clone_remote_fail(git_dir):
453+
# Ensure it has an error message instead of a exception if you try
454+
# to clone something which cannot be cloned.
455+
err = sh.git.clone("gitifyhg::ssh://hg@hg.example.domain/repo",
456+
_ok_code=128).stderr
457+
assert "Traceback" not in err

0 commit comments

Comments
 (0)