mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
Source files keep their SPDX-License-Identifier and Hanzo copyright line; the Gitea, Gogs and LFS Test Server copyrights they used to repeat now live once in NOTICE, alongside LICENSE. The header lint accepts any copyright line above the SPDX line, so it no longer demands an upstream one. Co-authored-by: Hanzo Dev <[email protected]>
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package git
|
|
|
|
import "context"
|
|
|
|
type SubmoduleWebLink struct {
|
|
RepoWebLink, CommitWebLink string
|
|
}
|
|
|
|
// GetSubModules get all the submodules of current revision git tree
|
|
func (c *Commit) GetSubModules(ctx context.Context, gitRepo *Repository) (*ObjectCache[*SubModule], error) {
|
|
if c.submoduleCache != nil {
|
|
return c.submoduleCache, nil
|
|
}
|
|
|
|
entry, err := c.GetTreeEntryByPath(ctx, gitRepo, ".gitmodules")
|
|
if err != nil {
|
|
if _, ok := err.(ErrNotExist); ok {
|
|
return nil, nil //nolint:nilnil // return nil to indicate that the submodule does not exist
|
|
}
|
|
return nil, err
|
|
}
|
|
|
|
rd, err := entry.Blob(gitRepo).DataAsync()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rd.Close()
|
|
|
|
// at the moment we do not strictly limit the size of the .gitmodules file because some users would have huge .gitmodules files (>1MB)
|
|
c.submoduleCache, err = configParseSubModules(rd)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return c.submoduleCache, nil
|
|
}
|
|
|
|
// GetSubModule gets the submodule by the entry name.
|
|
// It returns "nil, nil" if the submodule does not exist, caller should always remember to check the "nil"
|
|
func (c *Commit) GetSubModule(ctx context.Context, gitRepo *Repository, entryName string) (*SubModule, error) {
|
|
modules, err := c.GetSubModules(ctx, gitRepo)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if modules != nil {
|
|
if module, has := modules.Get(entryName); has {
|
|
return module, nil
|
|
}
|
|
}
|
|
return nil, nil //nolint:nilnil // return nil to indicate that the submodule does not exist
|
|
}
|