.GitInfo.AuthorDate when not committed

I have a layout where i show the commit date with .GitInfo.AuthorDate
This works fine, except if a content file is added locally which was not committed yet,

hugo server throws an error:

executing "events/list.ics" at <.GitInfo.AuthorDate>: can't evaluate field GitInfo in type time.Time

Tried with…

{{ with .GitInfo.AuthorDate }}DTSTAMP:{{dateFormat "20060102T150405" .GitInfo.AuthorDate}}{{ end }}

But same error.
So how can i make it not throwing an error but just ignoring that line?

Stating the obvious: Hugo gets it Git information from commits, not your local repo status.

So, as there is no author available at this point, you might want to use an error handler like the following (not tested):

{{ with .GitInfo }}
Do something...
{{ else }}
Do something else or even throw an error
{{ errorf "No author data available" }}
{{ end }}

This errorf is a recent feature, so you should use the latest Hugo, at least 50 I think.

After re-reading your requirements: the following does not throw errors (this time tested):

{{ with .GitInfo }}
{{ with .GitInfo.AuthorDate }}DTSTAMP:{{dateFormat "20060102T150405" .GitInfo.AuthorDate}}{{ end }}
{{ end }}

If you only use the inner with-line, then Hugo has to assume, that .GitInfo exists - which throws the error. If .GitInfo would exist, but no AuthorDate then the inner line would not throw an error.

Thanks for your help, but I still get thrown this error.
The issue is that not all content .md files are committed, so .GitInfo exists, but .GitInfo.AuthorDate does not.

BTW, this is the file that gives me the error:

Does using Lastmod change anything (click the link, it goes to the last section on the page)?

The way I understand this doc part it should take the frontmatter date if no gitdate is found?

Other than that I feel like this might be worth a bug report over in github. I would expect the “with”-loop to fail silently.