Add Page.GitInfo support for content from Git modules

Use blobless git clone (--filter=blob:none --no-checkout) to fetch
commit history for content from Git modules, then map it using the
existing gitmap library.  Cloned repos are cached in the modulegitinfo file cache.

Closes #14431
Fixes #5533
This commit is contained in:
Bjørn Erik Pedersen
2026-02-23 17:43:17 +01:00
committed by GitHub
parent 2d691c7e47
commit dfece5b674
16 changed files with 547 additions and 107 deletions
+23
View File
@@ -79,6 +79,17 @@ type Module interface {
// Whether this module's dir is a watch candidate.
Watch() bool
// Origin returns the module's origin info if available (VCS, URL, Hash, etc.).
Origin() ModuleOrigin
}
// ModuleOrigin contains origin info for a Go module.
type ModuleOrigin struct {
VCS string // version control system, e.g. "git"
URL string // repository URL, e.g. "https://github.com/bep/hugo-testing-git-versions"
Hash string // commit hash
Ref string // e.g. "refs/tags/v3.0.1"
}
type Modules []Module
@@ -219,3 +230,15 @@ func (m *moduleAdapter) Watch() bool {
// That leaves modules inside the read-only module cache.
return !m.gomod.Indirect
}
func (m *moduleAdapter) Origin() ModuleOrigin {
if !m.IsGoMod() || m.gomod.Origin == nil {
return ModuleOrigin{}
}
return ModuleOrigin{
VCS: m.gomod.Origin.VCS,
URL: m.gomod.Origin.URL,
Hash: m.gomod.Origin.Hash,
Ref: m.gomod.Origin.Ref,
}
}