# HG changeset patch # User domruf # Date 2017-11-20 23:18:38 # Node ID eb118291989043b4d88c3a7ca730c8a7b74e1e2e # Parent 0bec9f92745ab6a2e65210f98f2e3ab6c677ee1d git: fix URL for submodules - make it link to the external URL Without this changeset, the link on the files page would not point to the submodule target. Instead it would simple point to ./, which when clicked leads to a '500 Internal Server Error'. diff --git a/kallithea/lib/vcs/backends/git/changeset.py b/kallithea/lib/vcs/backends/git/changeset.py --- a/kallithea/lib/vcs/backends/git/changeset.py +++ b/kallithea/lib/vcs/backends/git/changeset.py @@ -1,7 +1,9 @@ import re from itertools import chain from dulwich import objects +from dulwich.config import ConfigFile from subprocess import Popen, PIPE +from io import BytesIO from kallithea.lib.vcs.conf import settings from kallithea.lib.vcs.backends.base import BaseChangeset, EmptyChangeset @@ -409,7 +411,9 @@ class GitChangeset(BaseChangeset): als = self.repository.alias for name, stat, id in tree.iteritems(): if objects.S_ISGITLINK(stat): - dirnodes.append(SubModuleNode(name, url=None, changeset=id, + cf = ConfigFile.from_file(BytesIO(self.repository._repo.get_object(tree['.gitmodules'][1]).data)) + url = cf.get(('submodule', name), 'url') + dirnodes.append(SubModuleNode(name, url=url, changeset=id, alias=als)) continue @@ -447,7 +451,10 @@ class GitChangeset(BaseChangeset): _GL = lambda m: m and objects.S_ISGITLINK(m) if _GL(self._stat_modes.get(path)): - node = SubModuleNode(path, url=None, changeset=id_, + tree = self.repository._repo[self._tree_id] + cf = ConfigFile.from_file(BytesIO(self.repository._repo.get_object(tree['.gitmodules'][1]).data)) + url = cf.get(('submodule', path), 'url') + node = SubModuleNode(path, url=url, changeset=id_, alias=self.repository.alias) else: obj = self.repository._repo.get_object(id_) diff --git a/kallithea/tests/other/test_vcs_operations.py b/kallithea/tests/other/test_vcs_operations.py --- a/kallithea/tests/other/test_vcs_operations.py +++ b/kallithea/tests/other/test_vcs_operations.py @@ -688,8 +688,7 @@ class TestVCSOperations(TestController): repo_name=fork_name, revision='tip', f_path='/')) - # BUG: the link to testsubmodule doesn't work - it should probably point at the submodule URL - response.mustcontain('testsubmodule @ ') + response.mustcontain('testsubmodule @ ' % clone_url) # check that following a submodule link actually works - and redirects response = self.app.get(url(controller='files', action='index',