Commit 2f945ac5 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets 🌴

Merge branch 'request/relative_submodules' into 'master'

 Add support for relative submodules

Currently there is no support for submodules where the url starts with ./ or ../, it will fail with an Routing Error.
This is required is you don't want to force a submodule to ssh or http usage.

For a given Repository __http://server/group/root.git__


[submodule "sub1"]
	path = sub1
	url = ../submodule.git

Wrong: http://server/group/ __root__ /submodule.git
Correct: http://server/group/submodule.git


[submodule "sub2"]
	path = sub2
	url = ../../any/submodule.git

Wrong: http://server/ __group/any__ /submodule.git
Corrent: http://server/any/submodule.git
parents 7611ce72 4d194502
......@@ -12,6 +12,8 @@ module SubmoduleHelper
if self_url?(url, project)
return project_path(project), project_tree_path(project,
elsif relative_self_url?(url)
elsif github_dot_com_url?(url)
standard_links('', project,
elsif gitlab_dot_com_url?(url)
......@@ -36,8 +38,22 @@ module SubmoduleHelper
url == gitlab_shell.url_to_repo(project)
def relative_self_url?(url)
# (./)?(../repo.git) || (./)?(../../project/repo.git) )
url =~ /^((\.\/)?(\.\.\/))(?!(\.\.)|(.*\/)).*\.git\Z/ || url =~ /^((\.\/)?(\.\.\/){2})(?!(\.\.))([^\/]*)\/(?!(\.\.)|(.*\/)).*\.git\Z/
def standard_links(host, project, commit)
base = [ 'https://', host, '/', project ].join('')
return base, [ base, '/tree/', commit ].join('')
def relative_self_links(url, commit)
if url.scan(/(\.\.\/)/).size == 2
base = url[/([^\/]*\/[^\/]*)\.git/, 1]
base = [, '/', url[/([^\/]*)\.git/, 1] ].join('')
return project_path(base), project_tree_path(base, commit)
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