diff options
author | Stan Hu <stanhu@gmail.com> | 2015-04-10 08:07:32 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2015-04-10 08:10:59 +0300 |
commit | 7d089701f1a9c15117e3e2d6f21eabaf08659ff6 (patch) | |
tree | 7b6f0f23130eca7d2708a1819d3290e77057d696 /app/helpers/submodule_helper.rb | |
parent | f3f856029bc5f966c5a7ee24cf7efefdd20e6019 (diff) |
Fix broken file browsing with a submodule that has a relative link
Closes #775
Diffstat (limited to 'app/helpers/submodule_helper.rb')
-rw-r--r-- | app/helpers/submodule_helper.rb | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/app/helpers/submodule_helper.rb b/app/helpers/submodule_helper.rb index 241462e5e4c..99231084cfe 100644 --- a/app/helpers/submodule_helper.rb +++ b/app/helpers/submodule_helper.rb @@ -53,15 +53,22 @@ module SubmoduleHelper 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('') + # Map relative links to a namespace and project + # For example: + # ../bar.git -> same namespace, repo bar + # ../foo/bar.git -> namespace foo, repo bar + # ../../foo/bar/baz.git -> namespace bar, repo baz + components = url.split('/') + base = components.pop.gsub(/.git$/, '') + namespace = components.pop.gsub(/^\.\.$/, '') + + if namespace.empty? + namespace = @project.group.path end [ - namespace_project_path(base.namespace, base), - namespace_project_tree_path(base.namespace, base, commit) + namespace_project_path(namespace, base), + namespace_project_tree_path(namespace, base, commit) ] end end |