This is an upstream bug, but this workaround seem to work fine.
Fixes #14564
continue
}
hasGitModules = true
- if mod.Owner() == nil {
+ if mod.Owner() == nil && !mod.Origin().IsZero() {
+ // TODO(bep) I'm not sure if this will ever be true. Needs some investigation,
+ // as I'm sure there will be cases where this could be useful.
projectIsGitModule = true
}
}
gitRepo, err := mapLocalRepo(cfg)
if err != nil {
if hasGitModules {
+ // We added GitInfo module support in Hugo v0.157.0 and need some real world experience,
+ // but for now, don't fail if the local repo is not a Git repo, but there are Git modules.
+ // I'm not sure we should even warn, but let's do that for now.
cfg.Logger.Warnf("Failed to read local Git log: %v", err)
return g, nil
}
"testing"
)
-func TestGitInfoFromGitModule(t *testing.T) {
+func TestGitInfoFromGitModuleWithVersionQuery(t *testing.T) {
t.Parallel()
files := `
"AuthorName: Bjørn Erik Pedersen|",
)
}
+
+func TestGitInfoFromGitModuleWithGoMod(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- hugo.toml --
+baseURL = "https://example.com/"
+enableGitInfo = true
+
+[module]
+[[module.imports]]
+path = "github.com/bep/hugo-mod-testing-content"
+[[module.imports.mounts]]
+source = "content"
+target = "content"
+-- layouts/page.html --
+Title: {{ .Title }}|
+GitInfo: {{ with .GitInfo }}Hash: {{ .Hash }}|Subject: {{ .Subject }}|AuthorName: {{ .AuthorName }}{{ end }}|
+Content: {{ .Content }}|
+-- layouts/_default/list.html --
+List: {{ .Title }}
+-- go.mod --
+module hugotest
+`
+
+ b := Test(t, files, TestOptOsFs())
+
+ b.AssertFileContent("public/docs/functions/kurtosis/index.html",
+ "Hash: 668663b54d0937df05185d144765d13c3ffda489|",
+ "AuthorName: Bjørn Erik Pedersen|",
+ )
+}
}
gi, err := newGitInfo(cfg)
if err != nil {
- h.Log.Errorln("Failed to read Git log:", err)
+ return err
} else {
h.gitInfo = gi
}
if m.Dir == "" {
modulesToDownload = append(modulesToDownload, fmt.Sprintf("%s@%s", m.Path, m.Version))
}
+
+ // See https://github.com/golang/go/issues/67363
+ // Origin isn't always set.
+ if m.Origin == nil && m.GoMod != "" {
+ // There's sometimes an Info field with a JSON filename with this info, but that is also not always set.
+ // But we seem to always get the go.mod filename, so we can determine the info filename from that,
+ // just replace the .mod suffix with .info.
+ infoFilename := strings.TrimSuffix(m.GoMod, ".mod") + ".info"
+ // JSON on the form {"Version":"v0.0.0-20260225095909-668663b54d09","Time":"2026-02-25T09:59:09Z","Origin":{"VCS":"git","URL":"https://github.com/bep/hugo-mod-testing-content","Hash":"668663b54d0937df05185d144765d13c3ffda489"}}
+ if b, err := afero.ReadFile(c.fs, infoFilename); err == nil {
+ var info struct {
+ Version string
+ Time time.Time
+ Origin *goModuleOrigin
+ }
+ if err := json.Unmarshal(b, &info); err == nil {
+ m.Origin = info.Origin
+ }
+ }
+ }
}
if len(modulesToDownload) > 0 {
Ref string // e.g. "refs/tags/v3.0.1"
}
+func (o ModuleOrigin) IsZero() bool {
+ return o.URL == ""
+}
+
type Modules []Module
type moduleAdapter struct {