Changeset - eb1182919890
[Not reviewed]
default
0 2 0
domruf - 8 years ago 2017-11-20 23:18:38
dominikruf@gmail.com
Grafted from: 35f75876280c
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 ./<submodulename>, which when
clicked leads to a '500 Internal Server Error'.
2 files changed with 10 insertions and 4 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/vcs/backends/git/changeset.py
Show inline comments
 
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
 
from kallithea.lib.vcs.exceptions import (
 
    RepositoryError, ChangesetError, NodeDoesNotExistError, VCSError,
 
    ChangesetDoesNotExistError, ImproperArchiveTypeError
 
@@ -406,13 +408,15 @@ class GitChangeset(BaseChangeset):
 
        tree = self.repository._repo[id]
 
        dirnodes = []
 
        filenodes = []
 
        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
 

	
 
            obj = self.repository._repo.get_object(id)
 
            if path != '':
 
                obj_path = '/'.join((path, name))
 
@@ -444,13 +448,16 @@ class GitChangeset(BaseChangeset):
 
            except ChangesetError:
 
                raise NodeDoesNotExistError("Cannot find one of parents' "
 
                    "directories for a given path: %s" % path)
 

	
 
            _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_)
 

	
 
                if isinstance(obj, objects.Tree):
 
                    if path == '':
kallithea/tests/other/test_vcs_operations.py
Show inline comments
 
@@ -685,14 +685,13 @@ class TestVCSOperations(TestController):
 
        # check for testsubmodule link in files page
 
        self.log_user()
 
        response = self.app.get(url(controller='files', action='index',
 
                                    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('<a class="submodule-dir" href="testsubmodule"><i class="icon-file-submodule"></i><span>testsubmodule @ ')
 
        response.mustcontain('<a class="submodule-dir" href="%s"><i class="icon-file-submodule"></i><span>testsubmodule @ ' % clone_url)
 

	
 
        # check that following a submodule link actually works - and redirects
 
        response = self.app.get(url(controller='files', action='index',
 
                                    repo_name=fork_name,
 
                                    revision='tip',
 
                                    f_path='/testsubmodule'),
0 comments (0 inline, 0 general)