.Hugo.CommitHash doesn't render

Steps to reproduce:

  1. hugo new site hugo-commit-hash && cd hugo-commit-hash
  2. echo "Hugo commit hash: {{ .Hugo.CommitHash }}" > layouts/index.html
  3. hugo
  4. cat public/index.html

Output of hugo env:

Hugo Static Site Generator v0.52/extended darwin/amd64 BuildDate: 2018-11-28T14:58:25Z
GOOS="darwin"
GOARCH="amd64"
GOVERSION="go1.11"

There are 2 issues with your approach:

  1. You need a Git repository and a committed source.
  2. You need to enable Git info (default off)

As a “proof” that it’s working: https://gohugo.io/maintenance/

Ah, silly mistake by me, thanks for pointing that out :sweat_smile:


So I’ve updated my test case with your feedback:

  1. hugo new site hugo-commit-hash && cd hugo-commit-hash
  2. Create content/_index.md as:
    ---
    title: Index
    ---
    
  3. Create layouts/index.html as:
    Hugo commit hash: {{ .Hugo.CommitHash }}
    <br><br>
    {{ $page := .Page.GetPage "/_index.md" }}
    Git info: {{ $page.GitInfo }}
    
  4. Add below line to config.toml
    enableGitInfo = true
    
  5. git init && git add -A && git commit -m "Initial"
  6. hugo
  7. Inspect public/index.html (and see that commit hash is still blank)
    Hugo commit hash: 
    <br><br>
    Git info: {3de9712d0faca4221740e45a00b9253475b953d6 3de9712 Initial MyName MyEmail 2018-11-29 11:35:16 -0600 CST}
    

Thanks for the link. I see this partial is using .GitInfo, but I don’t see any occurrence of .Hugo.CommitHash

To me, I would expect .Hugo.CommitHash to work regardless of the site being in a git repo, or git info being enabled. The same way that .Hugo.Version and .Hugo.BuildDate work, since they are retrieved from the binary.

Thoughts?

OK, I misread your first post.

Hugo.CommitHash should be set at build time. Not sure why it’s not.