Fix submodule link to then project under subgroup

Before this change only last namespace in full path was extracted. It's
fine unless you have a link to submodule under subgroups. In that case
self_url? method returns false and link is processed as external. I
could not find a proper regex to cover all cases and correctly extract
full path to repository and instead used current instance host name
to get correct path to namespace and project.
Signed-off-by: 's avatarDmitriy Zaporozhets <>
parent 64a22c56
......@@ -13,6 +13,17 @@ module SubmoduleHelper
if url =~ /([^\/:]+)\/([^\/]+(?:\.git)?)\Z/
namespace, project = $1, $2
gitlab_hosts = [Gitlab.config.gitlab.url,
gitlab_hosts.each do |host|
if url.start_with?(host)
namespace, _, project = url.sub(host, '').rpartition('/')
namespace.sub!(/\A\//, '')
project.sub!(/\.git\z/, '')
......@@ -52,6 +52,14 @@ describe SubmoduleHelper do
stub_url(['http://',, '/gitlab/root/gitlab-org/gitlab-ce.git'].join(''))
expect(submodule_links(submodule_item)).to eq([namespace_project_path('gitlab-org', 'gitlab-ce'), namespace_project_tree_path('gitlab-org', 'gitlab-ce', 'hash')])
it 'works with subgroups' do
allow(Gitlab.config.gitlab).to receive(:port).and_return(80) # set this just to be sure
allow(Gitlab.config.gitlab).to receive(:relative_url_root).and_return('/gitlab/root')
allow(Gitlab.config.gitlab).to receive(:url).and_return(Settings.send(:build_gitlab_url))
stub_url(['http://',, '/gitlab/root/gitlab-org/sub/gitlab-ce.git'].join(''))
expect(submodule_links(submodule_item)).to eq([namespace_project_path('gitlab-org/sub', 'gitlab-ce'), namespace_project_tree_path('gitlab-org/sub', 'gitlab-ce', 'hash')])
context 'submodule on' do
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment