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 ...@@ -12,6 +12,8 @@ module SubmoduleHelper
if self_url?(url, project) if self_url?(url, project)
return project_path(project), project_tree_path(project, submodule_item.id) 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) elsif github_dot_com_url?(url)
standard_links('github.com', project, submodule_item.id) standard_links('github.com', project, submodule_item.id)
elsif gitlab_dot_com_url?(url) elsif gitlab_dot_com_url?(url)
...@@ -36,8 +38,22 @@ module SubmoduleHelper ...@@ -36,8 +38,22 @@ module SubmoduleHelper
url == gitlab_shell.url_to_repo(project) url == gitlab_shell.url_to_repo(project)
end 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) def standard_links(host, project, commit)
base = [ 'https://', host, '/', project ].join('') base = [ 'https://', host, '/', project ].join('')
return base, [ base, '/tree/', commit ].join('') return base, [ base, '/tree/', commit ].join('')
end 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 end
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