# HG changeset patch # User Marcin Kuzminski # Date 2017-11-28 12:23:25 # Node ID b82a308268f7c0fb6d7143a117350f4f9db72609 # Parent a8bbceb1de51ac6b78ad5add25be85708a9c4a21 vcs: also register a global config for vcs_handler. - this solves a case when SVN repository needs to find out a repo without per-repo settings available - we need to get the global config first to be able to extract repo name diff --git a/rhodecode/lib/middleware/simplevcs.py b/rhodecode/lib/middleware/simplevcs.py --- a/rhodecode/lib/middleware/simplevcs.py +++ b/rhodecode/lib/middleware/simplevcs.py @@ -34,6 +34,7 @@ from paste.httpheaders import REMOTE_USE # TODO(marcink): check if we should use webob.exc here ? from pyramid.httpexceptions import ( HTTPNotFound, HTTPForbidden, HTTPNotAcceptable, HTTPInternalServerError) +from zope.cachedescriptors.property import Lazy as LazyProperty import rhodecode from rhodecode.authentication.base import ( @@ -121,12 +122,28 @@ class SimpleVCS(object): auth_ret_code_detection) self.ip_addr = '0.0.0.0' + @LazyProperty + def global_vcs_config(self): + try: + return VcsSettingsModel().get_ui_settings_as_config_obj() + except Exception: + return base.Config() + @property def base_path(self): - settings_path = self.repo_vcs_config.get(*VcsSettingsModel.PATH_SETTING) + settings_path = self.repo_vcs_config.get( + *VcsSettingsModel.PATH_SETTING) + + if not settings_path: + settings_path = self.global_vcs_config.get( + *VcsSettingsModel.PATH_SETTING) + if not settings_path: # try, maybe we passed in explicitly as config option settings_path = self.config.get('base_path') + + if not settings_path: + raise ValueError('FATAL: base_path is empty') return settings_path def set_repo_names(self, environ): diff --git a/rhodecode/tests/lib/middleware/test_vcs.py b/rhodecode/tests/lib/middleware/test_vcs.py --- a/rhodecode/tests/lib/middleware/test_vcs.py +++ b/rhodecode/tests/lib/middleware/test_vcs.py @@ -48,6 +48,7 @@ def test_is_hg_no_cmd(): def test_is_hg_empty_cmd(): environ = { + 'REQUEST_METHOD': 'GET', 'PATH_INFO': svn_repo_path, 'QUERY_STRING': 'cmd=', 'HTTP_ACCEPT': 'application/mercurial' @@ -57,6 +58,7 @@ def test_is_hg_empty_cmd(): def test_is_svn_returns_true_if_subversion_is_in_a_dav_header(): environ = { + 'REQUEST_METHOD': 'GET', 'PATH_INFO': svn_repo_path, 'HTTP_DAV': 'http://subversion.tigris.org/xmlns/dav/svn/log-revprops' } @@ -65,6 +67,7 @@ def test_is_svn_returns_true_if_subversi def test_is_svn_returns_false_if_subversion_is_not_in_a_dav_header(): environ = { + 'REQUEST_METHOD': 'GET', 'PATH_INFO': svn_repo_path, 'HTTP_DAV': 'http://stuff.tigris.org/xmlns/dav/svn/log-revprops' } @@ -73,6 +76,7 @@ def test_is_svn_returns_false_if_subvers def test_is_svn_returns_false_if_no_dav_header(): environ = { + 'REQUEST_METHOD': 'GET', 'PATH_INFO': svn_repo_path, } assert vcs.is_svn(environ) is False @@ -85,6 +89,14 @@ def test_is_svn_returns_true_if_magic_pa assert vcs.is_svn(environ) +def test_is_svn_returns_true_if_propfind(): + environ = { + 'REQUEST_METHOD': 'PROPFIND', + 'PATH_INFO': svn_repo_path, + } + assert vcs.is_svn(environ) is True + + def test_is_svn_allows_to_configure_the_magic_path(monkeypatch): """ This is intended as a fallback in case someone has configured his @@ -93,6 +105,7 @@ def test_is_svn_allows_to_configure_the_ monkeypatch.setitem( rhodecode.CONFIG, 'rhodecode_subversion_magic_path', '/!my-magic') environ = { + 'REQUEST_METHOD': 'POST', 'PATH_INFO': '/stub-repository/!my-magic/rev/4', } assert vcs.is_svn(environ)