On this page
Package submodule enumerates initialized and deinitialized git submodules, detects parent repos, checks for nesting, and resolves paths through symlinks.
#internal/submodule
#internal/submodule
Package submodule enumerates initialized and deinitialized git submodules, detects parent repos, checks for nesting, and resolves paths through symlinks.
This package intentionally does NOT import internal/git, which would create an import cycle. Its git calls still go through internal/gitexec, safegit's single git-execution boundary: gitexec is a leaf package (standard library only), so both this package and internal/git can route through it.
#ErrNestedSubmodules
var ErrNestedSubmodules = errors.New("nested submodules detected")ErrNestedSubmodules is returned when a submodule itself contains submodules.
#SubmoduleInfo
type SubmoduleInfo structSubmoduleInfo describes a discovered submodule within a parent repository.
#Parent
type Parent structParent describes the superproject a submodule is checked out inside.
WorkTree is carried alongside GitDir because several things a parent owns live in the work tree rather than the git directory -- its committed hook store above all -- and a caller handed only the git directory cannot find them without re-asking git.
#Enumerate
func Enumerate(ctx context.Context, parentGitDir string) ([]SubmoduleInfo, error)Enumerate discovers all submodules in a repo. parentGitDir is the absolute path to the parent's .git directory (e.g. "/repo/.git").
Initialized submodules are found via git submodule foreach. Deinitialized submodules are found by walking .git/modules/. The two sets are merged with initialized taking precedence in case of overlap.
Returns an empty slice (not error) if no submodules exist.
#CheckNested
func CheckNested(ctx context.Context, parentGitDir string) errorCheckNested verifies that no initialized submodule itself contains nested submodules (indicated by a .gitmodules file in the submodule's working tree).
#DetectParent
func DetectParent(ctx context.Context) (parent Parent, ok bool)DetectParent checks whether the current working directory is inside a git submodule and returns information about the parent repo.
Returns ok=false if not inside a submodule. Returns the immediate parent only; callers recurse if needed for nested submodules.