changeset 4821:b8c69e4deacd

remotes: add support to clone from Mercurial repositories over ssh This commit adds support to clone a remote Mercurial repository over ssh. Interactive password authentication is not implemented, nor is support for pbulic key authentication with passphrases; the repository should be accessible using bare ssh key authentication. For this reason, the ssh options -oBatchMode=yes and -oIdentitiesOnly=yes are added to the ui.ssh setting of Mercurial.
author Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
date Sat, 24 Jan 2015 22:07:35 +0100
parents 953ee49f3b30
children 53d766fc9782
files kallithea/lib/utils.py kallithea/lib/vcs/backends/hg/repository.py kallithea/lib/vcs/utils/hgcompat.py kallithea/model/validators.py kallithea/templates/admin/repos/repo_add_base.html kallithea/templates/admin/repos/repo_edit_settings.html
diffstat 6 files changed, 17 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/utils.py	Sun Nov 02 13:52:55 2014 -0800
+++ b/kallithea/lib/utils.py	Sat Jan 24 22:07:35 2015 +0100
@@ -381,6 +381,11 @@
                                  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
 
 
--- a/kallithea/lib/vcs/backends/hg/repository.py	Sun Nov 02 13:52:55 2014 -0800
+++ b/kallithea/lib/vcs/backends/hg/repository.py	Sat Jan 24 22:07:35 2015 +0100
@@ -31,7 +31,7 @@
 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 @@
         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)
--- a/kallithea/lib/vcs/utils/hgcompat.py	Sun Nov 02 13:52:55 2014 -0800
+++ b/kallithea/lib/vcs/utils/hgcompat.py	Sat Jan 24 22:07:35 2015 +0100
@@ -25,6 +25,7 @@
 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
--- a/kallithea/model/validators.py	Sun Nov 02 13:52:55 2014 -0800
+++ b/kallithea/model/validators.py	Sat Jan 24 22:07:35 2015 +0100
@@ -444,7 +444,7 @@
     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 @@
         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):
--- a/kallithea/templates/admin/repos/repo_add_base.html	Sun Nov 02 13:52:55 2014 -0800
+++ b/kallithea/templates/admin/repos/repo_add_base.html	Sat Jan 24 22:07:35 2015 +0100
@@ -24,7 +24,7 @@
             </div>
             <div class="input">
                 ${h.text('clone_uri',class_="small")}
-                <span class="help-block">${_('Optional http[s] url from which repository should be cloned.')}</span>
+                <span class="help-block">${_('Optional url from which repository should be cloned.')}</span>
             </div>
         </div>
         <div class="field">
--- a/kallithea/templates/admin/repos/repo_edit_settings.html	Sun Nov 02 13:52:55 2014 -0800
+++ b/kallithea/templates/admin/repos/repo_edit_settings.html	Sat Jan 24 22:07:35 2015 +0100
@@ -34,7 +34,7 @@
                     ${h.text('clone_uri',class_="medium")}
                     ${h.hidden('clone_uri_change', 'NEW')}
                    %endif
-                 <span id="alter_clone_uri_help_block" class="help-block">${_('http[s] url used for doing remote pulls.')}</span>
+                 <span id="alter_clone_uri_help_block" class="help-block">${_('Url used for doing remote pulls.')}</span>
                </div>
             </div>
             <div class="field">