enableGitInfo documentation and behavior

The v0.20 documentation states:

Enable the GitInfo feature in Hugo by using --enableGitInfo on the command line or by setting enableGitInfo to true in your site configuration.

Emphasis mine. Setting enableGitInfo to true in the site config without the --enableGitInfo flag on the command line does not seem to actually enable GitInfo.

I found that adding the command line flag to the hugo server enables GitInfo regardless of whether it is enabled in the config file.

Does anyone know what the actual expected behavior is? I’d like to update the documentation if possible.

It does, we have had it enabled for Hugo docs for a long time (I recently removed it from the site config to make editing faster (live reload)), but that is another story. I suspect you have something else wrong going on.

Ahh I think I may have found the problem.

If I add “enableGitInfo = true” to my config.toml while running “hugo server”, hugo rebuilds my site but does not appear to reload the config file. If I restart the hugo server, GitInfo is enabled.

Does hugo server not reload edits to the config file?

Does hugo server not reload edits to the config file?

Yes, but there may be operating systems / editor combos that could be problematic.

Interesting. I’m running the 64 bit Windows Hugo executable on Windows10, editing inside of WebStorm, and viewing on Chrome. Is there any other useful information I could relay?

I’ll just post my findings here, may be just for the sake of my future self who might end up on this thread again… as this is not documented in the official documentation.

If I add enableGitInfo = true to my site config.toml, I can start seeing the value of .GitInfo.AuthorDate unique to each .md file. Below is the little code snippet I used for debug in my theme:

    {{ if $.GitInfo }}      <!-- To enable this, put "enableGitInfo = true" in your site config.toml -->
        <p>
            {{ printf "GitInfo debug:: %#v" $.GitInfo }}
        </p>
        <p>
            LastMod Date using GitInfo: {{ .GitInfo.AuthorDate }}
        </p>
    {{ end }}

What is missing in the docs above?

Also important to know: If GitInfo is enabled, .Lastmod (on Page) is fetched from Git. So don’t have to use the “if GitInfo” if you only need the last mod date.

The documentation was missing the exact usage as I show in my example. For instance, I learnt through experimentation that that {{ if $.GitInfo }} block is actually needed.

If I try to use {{ .GitInfo.AuthorDate }} outside that, and if I have enableGitInfo set to false (or unset), I will get error at hugo build time. Now with that if block, I can safely put it in my theme, and not have to worry about whether the site config.toml has enableGitInfo set or not.

Ah! Do you mean that I can just use .Lastmod instead of .GitInfo.AuthorDate if I have enableGitInfo set?


Edit: Fix typo

Yes… But it is spelled .Lastmod.

Also: A PR to the hugoDocs repo with some clarity on this would be great!

Done!