Merge pull request 'fix: return correct type in GetSubModule' (#6114) from gusted/forgejo-submodule-entry into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6114
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
This commit is contained in:
Gusted 2024-12-03 03:24:01 +00:00
commit 45cec645de
4 changed files with 46 additions and 12 deletions

View file

@ -395,20 +395,20 @@ func parseSubmoduleContent(bs []byte) (*ObjectCache, error) {
return submoduleCache, nil
}
// GetSubModule get the sub module according entryname
func (c *Commit) GetSubModule(entryname string) (*SubModule, error) {
// GetSubModule returns the URL to the submodule according entryname
func (c *Commit) GetSubModule(entryname string) (string, error) {
modules, err := c.GetSubModules()
if err != nil {
return nil, err
return "", err
}
if modules != nil {
module, has := modules.Get(entryname)
if has {
return module.(*SubModule), nil
return module.(string), nil
}
}
return nil, nil
return "", nil
}
// GetBranchName gets the closest branch name (as returned by 'git name-rev --name-only')

View file

@ -72,17 +72,15 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, commit *Commit, treePath
// If the entry if a submodule add a submodule file for this
if entry.IsSubModule() {
subModuleURL := ""
var fullPath string
if len(treePath) > 0 {
fullPath = treePath + "/" + entry.Name()
} else {
fullPath = entry.Name()
}
if subModule, err := commit.GetSubModule(fullPath); err != nil {
subModuleURL, err := commit.GetSubModule(fullPath)
if err != nil {
return nil, nil, err
} else if subModule != nil {
subModuleURL = subModule.URL
}
subModuleFile := NewSubModuleFile(commitsInfo[i].Commit, subModuleURL, entry.ID.String())
commitsInfo[i].SubModuleFile = subModuleFile