diff --git a/kallithea/lib/utils.py b/kallithea/lib/utils.py --- a/kallithea/lib/utils.py +++ b/kallithea/lib/utils.py @@ -381,6 +381,11 @@ def make_ui(read_from='file', path=None, False) if clear_session: meta.Session.remove() + + # prevent interactive questions for ssh password / passphrase + ssh = baseui.config('ui', 'ssh', default='ssh') + baseui.setconfig('ui', 'ssh', '%s -oBatchMode=yes -oIdentitiesOnly=yes' % ssh) + return baseui diff --git a/kallithea/lib/vcs/backends/hg/repository.py b/kallithea/lib/vcs/backends/hg/repository.py --- a/kallithea/lib/vcs/backends/hg/repository.py +++ b/kallithea/lib/vcs/backends/hg/repository.py @@ -31,7 +31,7 @@ from kallithea.lib.vcs.utils.paths impor from kallithea.lib.vcs.utils.hgcompat import ( ui, nullid, match, patch, diffopts, clone, get_contact, pull, localrepository, RepoLookupError, Abort, RepoError, hex, scmutil, hg_url, - httpbasicauthhandler, httpdigestauthhandler, peer, httppeer + httpbasicauthhandler, httpdigestauthhandler, peer, httppeer, sshpeer ) from .changeset import MercurialChangeset @@ -282,6 +282,12 @@ class MercurialRepository(BaseRepository if os.path.isdir(url) or url.startswith('file:'): return True + if url.startswith('ssh:'): + # in case of invalid uri or authentication issues, sshpeer will + # throw an exception. + sshpeer(repoui or ui.ui(), url).lookup('tip') + return True + url_prefix = None if '+' in url[:url.find('://')]: url_prefix, url = url.split('+', 1) diff --git a/kallithea/lib/vcs/utils/hgcompat.py b/kallithea/lib/vcs/utils/hgcompat.py --- a/kallithea/lib/vcs/utils/hgcompat.py +++ b/kallithea/lib/vcs/utils/hgcompat.py @@ -25,6 +25,7 @@ from mercurial.encoding import tolocal from mercurial.discovery import findcommonoutgoing from mercurial.hg import peer from mercurial.httppeer import httppeer +from mercurial.sshpeer import sshpeer from mercurial.util import url as hg_url from mercurial.scmutil import revrange from mercurial.node import nullrev diff --git a/kallithea/model/validators.py b/kallithea/model/validators.py --- a/kallithea/model/validators.py +++ b/kallithea/model/validators.py @@ -444,7 +444,7 @@ def ValidCloneUri(): def url_handler(repo_type, url, ui): if repo_type == 'hg': from kallithea.lib.vcs.backends.hg.repository import MercurialRepository - if url.startswith('http'): + if url.startswith('http') or url.startswith('ssh'): # initially check if it's at least the proper URL # or does it pass basic auth MercurialRepository._check_url(url, ui) @@ -473,7 +473,7 @@ def ValidCloneUri(): messages = { 'clone_uri': _(u'invalid clone url'), 'invalid_clone_uri': _(u'Invalid clone url, provide a ' - 'valid clone http(s)/svn+http(s) url') + 'valid clone http(s)/svn+http(s)/ssh url') } def validate_python(self, value, state): diff --git a/kallithea/templates/admin/repos/repo_add_base.html b/kallithea/templates/admin/repos/repo_add_base.html --- a/kallithea/templates/admin/repos/repo_add_base.html +++ b/kallithea/templates/admin/repos/repo_add_base.html @@ -24,7 +24,7 @@ ${h.form(url('repos'))}