Commit 2f945ac535696c9b1e0b14e0b7bb2d6e0c1cf566

Authored by Dmitriy Zaporozhets
2 parents 7611ce72 4d194502

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
Showing 1 changed file with 16 additions and 0 deletions   Show diff stats
app/helpers/submodule_helper.rb 100644 → 100755
@@ -12,6 +12,8 @@ module SubmoduleHelper @@ -12,6 +12,8 @@ module SubmoduleHelper
12 12
13 if self_url?(url, project) 13 if self_url?(url, project)
14 return project_path(project), project_tree_path(project, submodule_item.id) 14 return project_path(project), project_tree_path(project, submodule_item.id)
  15 + elsif relative_self_url?(url)
  16 + relative_self_links(url, submodule_item.id)
15 elsif github_dot_com_url?(url) 17 elsif github_dot_com_url?(url)
16 standard_links('github.com', project, submodule_item.id) 18 standard_links('github.com', project, submodule_item.id)
17 elsif gitlab_dot_com_url?(url) 19 elsif gitlab_dot_com_url?(url)
@@ -36,8 +38,22 @@ module SubmoduleHelper @@ -36,8 +38,22 @@ module SubmoduleHelper
36 url == gitlab_shell.url_to_repo(project) 38 url == gitlab_shell.url_to_repo(project)
37 end 39 end
38 40
  41 + def relative_self_url?(url)
  42 + # (./)?(../repo.git) || (./)?(../../project/repo.git) )
  43 + url =~ /^((\.\/)?(\.\.\/))(?!(\.\.)|(.*\/)).*\.git\Z/ || url =~ /^((\.\/)?(\.\.\/){2})(?!(\.\.))([^\/]*)\/(?!(\.\.)|(.*\/)).*\.git\Z/
  44 + end
  45 +
39 def standard_links(host, project, commit) 46 def standard_links(host, project, commit)
40 base = [ 'https://', host, '/', project ].join('') 47 base = [ 'https://', host, '/', project ].join('')
41 return base, [ base, '/tree/', commit ].join('') 48 return base, [ base, '/tree/', commit ].join('')
42 end 49 end
  50 +
  51 + def relative_self_links(url, commit)
  52 + if url.scan(/(\.\.\/)/).size == 2
  53 + base = url[/([^\/]*\/[^\/]*)\.git/, 1]
  54 + else
  55 + base = [ @project.group.path, '/', url[/([^\/]*)\.git/, 1] ].join('')
  56 + end
  57 + return project_path(base), project_tree_path(base, commit)
  58 + end
43 end 59 end