# HG changeset patch # User Marcin Kuzminski # Date 2019-12-09 12:12:15 # Node ID 23b8627db13ed3436275095972a630f7b7817aeb # Parent ca85e1b229e4ba720a0db84e8fc6039da7e937ee svn: fix checkout SVN ssh url. G: changed rhodecode/tests/lib/test_libs.py diff --git a/rhodecode/lib/utils2.py b/rhodecode/lib/utils2.py --- a/rhodecode/lib/utils2.py +++ b/rhodecode/lib/utils2.py @@ -654,7 +654,7 @@ def get_host_info(request): } -def get_clone_url(request, uri_tmpl, repo_name, repo_id, **override): +def get_clone_url(request, uri_tmpl, repo_name, repo_id, repo_type, **override): qualified_home_url = request.route_url('home') parsed_url = urlobject.URLObject(qualified_home_url) decoded_path = safe_unicode(urllib.unquote(parsed_url.path.rstrip('/'))) @@ -668,7 +668,8 @@ def get_clone_url(request, uri_tmpl, rep 'hostname': parsed_url.hostname, 'prefix': decoded_path, 'repo': repo_name, - 'repoid': str(repo_id) + 'repoid': str(repo_id), + 'repo_type': repo_type } args.update(override) args['user'] = urllib.quote(safe_str(args['user'])) @@ -676,6 +677,10 @@ def get_clone_url(request, uri_tmpl, rep for k, v in args.items(): uri_tmpl = uri_tmpl.replace('{%s}' % k, v) + # special case for SVN clone url + if repo_type == 'svn': + uri_tmpl = uri_tmpl.replace('ssh://', 'svn+ssh://') + # remove leading @ sign if it's present. Case of empty user url_obj = urlobject.URLObject(uri_tmpl) url = url_obj.with_netloc(url_obj.netloc.lstrip('@')) diff --git a/rhodecode/model/db.py b/rhodecode/model/db.py --- a/rhodecode/model/db.py +++ b/rhodecode/model/db.py @@ -2297,9 +2297,11 @@ class Repository(Base, BaseModel): rc_config = request.call_context.rc_config else: rc_config = SettingsModel().get_all_settings(cache=True) + if ssh: uri_tmpl = rc_config.get( 'rhodecode_clone_uri_ssh_tmpl') or self.DEFAULT_CLONE_URI_SSH + else: uri_tmpl = rc_config.get( 'rhodecode_clone_uri_tmpl') or self.DEFAULT_CLONE_URI @@ -2307,7 +2309,9 @@ class Repository(Base, BaseModel): return get_clone_url(request=request, uri_tmpl=uri_tmpl, repo_name=self.repo_name, - repo_id=self.repo_id, **override) + repo_id=self.repo_id, + repo_type=self.repo_type, + **override) def set_state(self, state): self.repo_state = state diff --git a/rhodecode/tests/lib/test_libs.py b/rhodecode/tests/lib/test_libs.py --- a/rhodecode/tests/lib/test_libs.py +++ b/rhodecode/tests/lib/test_libs.py @@ -450,10 +450,27 @@ def test_clone_url_generator(tmpl, repo_ clone_url = get_clone_url( request=RequestStub(), uri_tmpl=tmpl, - repo_name=repo_name, repo_id=23, **overrides) + repo_name=repo_name, repo_id=23, repo_type='hg', **overrides) assert clone_url == expected +def test_clone_url_svn_ssh_generator(): + from rhodecode.lib.utils2 import get_clone_url + + class RequestStub(object): + def request_url(self, name): + return 'http://vps1:8000' + + def route_url(self, name): + return self.request_url(name) + + clone_url = get_clone_url( + request=RequestStub(), + uri_tmpl=Repository.DEFAULT_CLONE_URI_SSH, + repo_name='svn-test', repo_id=23, repo_type='svn', **{'sys_user': 'rcdev'}) + assert clone_url == 'svn+ssh://rcdev@vps1/svn-test' + + idx = 0