Add support for relative submodules

This commit is contained in:
Timm Drevensek 2014-02-25 22:42:45 +01:00
parent 1c7aecc8f5
commit fe8c902126
2 changed files with 18 additions and 0 deletions

View File

@ -3,6 +3,7 @@ v 6.7.0
- Add edit file button to MergeRequest diff
- Public groups (Jason Hollingsworth)
- Cleaner headers in Notification Emails (Pierre de La Morinerie)
- Add support for relative submodules
v 6.6.2
- Fix 500 error on branch/tag create or remove via UI

17
app/helpers/submodule_helper.rb Normal file → Executable file
View File

@ -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,23 @@ module SubmoduleHelper
url == gitlab_shell.url_to_repo(project)
end
def relative_self_url?(url)
# (./)? ( (../repo.git) | (../../project/repo.git) )
url =~ /(^((\.\/)?(((\.\.)\/)|((\.\.)\/(\.\.)\/.*\/)))[^\.\/]*\.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 = [ Gitlab.config.gitlab.url, '/', url[/.*\/(.*)\/.*\.git/, 1] ].join('')
else
base = [ Gitlab.config.gitlab.url, '/', @project.group.path ].join('')
end
base = [ base, '/', url[/.*\/(.*)\.git/, 1] ].join('')
return base, [ base, '/tree/', commit ].join('')
end
end