git_handler: test for a raw git ssh uri

By testing the uri early, we can reuse logic later in the method to parse the
git uri. We rely on the isgitsshuri heuristic to return True or False, and if
True, prepend 'git+ssh://' to the uri.

Arguably, this is fragile, and am open to better ideas, but can't think of
anything else currently.
This commit is contained in:
Sean Farley 2015-06-26 16:32:20 -07:00
parent e2c674532c
commit 4d5f0b97d4

View File

@ -1540,10 +1540,34 @@ class GitHandler(object):
return string.decode('ascii', 'replace').encode('utf-8')
def get_transport_and_path(self, uri):
"""Method that sets up the transport (either ssh or http(s))
Tests:
>>> from dulwich.client import HttpGitClient, SSHGitClient
>>> from mercurial.ui import ui
>>> g = GitHandler('', ui())
>>> client, url = g.get_transport_and_path('http://fqdn.com/test.git')
>>> print isinstance(client, HttpGitClient)
True
>>> print url
http://fqdn.com/test.git
>>> client, url = g.get_transport_and_path('git@fqdn.com:user/repo.git')
>>> print isinstance(client, SSHGitClient)
True
>>> print url
user/repo.git
>>> print client.host
git@fqdn.com
"""
# pass hg's ui.ssh config to dulwich
if not issubclass(client.get_ssh_vendor, _ssh.SSHVendor):
client.get_ssh_vendor = _ssh.generate_ssh_vendor(self.ui)
# test for raw git ssh uri here so that we can reuse the logic below
if util.isgitsshuri(uri):
uri = "git+ssh://" + uri
git_match = RE_GIT_URI.match(uri)
if git_match:
res = git_match.groupdict()