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
This commit is contained in:
commit
2f945ac535
|
@ -12,6 +12,8 @@ module SubmoduleHelper
|
|||
|
||||
if self_url?(url, project)
|
||||
return project_path(project), project_tree_path(project, submodule_item.id)
|
||||
elsif relative_self_url?(url)
|
||||
relative_self_links(url, submodule_item.id)
|
||||
elsif github_dot_com_url?(url)
|
||||
standard_links('github.com', project, submodule_item.id)
|
||||
elsif gitlab_dot_com_url?(url)
|
||||
|
@ -36,8 +38,22 @@ module SubmoduleHelper
|
|||
url == gitlab_shell.url_to_repo(project)
|
||||
end
|
||||
|
||||
def relative_self_url?(url)
|
||||
# (./)?(../repo.git) || (./)?(../../project/repo.git) )
|
||||
url =~ /^((\.\/)?(\.\.\/))(?!(\.\.)|(.*\/)).*\.git\Z/ || url =~ /^((\.\/)?(\.\.\/){2})(?!(\.\.))([^\/]*)\/(?!(\.\.)|(.*\/)).*\.git\Z/
|
||||
end
|
||||
|
||||
def standard_links(host, project, commit)
|
||||
base = [ 'https://', host, '/', project ].join('')
|
||||
return base, [ base, '/tree/', commit ].join('')
|
||||
end
|
||||
|
||||
def relative_self_links(url, commit)
|
||||
if url.scan(/(\.\.\/)/).size == 2
|
||||
base = url[/([^\/]*\/[^\/]*)\.git/, 1]
|
||||
else
|
||||
base = [ @project.group.path, '/', url[/([^\/]*)\.git/, 1] ].join('')
|
||||
end
|
||||
return project_path(base), project_tree_path(base, commit)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue