safegit v0.26.0 /internal/submodule
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 other internal/* packages to avoid import cycles. Git commands use exec.Command directly -- this is the bootstrap exception (same pattern as internal/testutil).

#ErrNestedSubmodules

Go go
var ErrNestedSubmodules = errors.New("nested submodules detected")

ErrNestedSubmodules is returned when a submodule itself contains submodules.

#SubmoduleInfo

Go go
type SubmoduleInfo struct

SubmoduleInfo describes a discovered submodule within a parent repository.

#Enumerate

Go go
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

Go go
func CheckNested(ctx context.Context, parentGitDir string) error

CheckNested verifies that no initialized submodule itself contains nested submodules (indicated by a .gitmodules file in the submodule's working tree).

#DetectParent

Go go
func DetectParent(ctx context.Context) (parentGitDir string, submodulePath string, ok bool)

DetectParent checks whether the current working directory is inside a git submodule and returns information about the parent repo.

Returns ("", "", false) if not inside a submodule. Returns the immediate parent only; callers recurse if needed for nested submodules.

Search