System-files and personal-files request for hugo

Hello,

Hugo needs access to the gitconfig file if it exists. It would be nice to allow autoconnect of system-files and personal-files to allow this access (Snap: Add {system,user}-gitconfig plugs to read gitconfig).

plugs:
  system-gitconfig:
    interface: system-files
    read:
    - /etc/gitconfig
  user-gitconfig:
    interface: personal-files
    read:
    - $HOME/.gitconfig
    - $HOME/.config/git/config

Many thanks to the onefetch team for their store-request at https://forum.snapcraft.io/t/system-files-and-personal-files-request-for-onefetch/28963 which showed us the way to follow.

As per my response to onefetch - can you please instead use the names etc-gitconfig and gitconfig for these interfaces to keep consistency with other snaps?

Also can you please provide some details on why this access is needed for hugo? Thanks.

Thank you @alexmurray!

As per my response to onefetch - can you please instead use the names etc-gitconfig and gitconfig for these interfaces to keep consistency with other snaps?

Yes, for sure! Sorry for the oversight. I have just pushed the fix to gohugoio/hugo master in commit fd3953c:

Also can you please provide some details on why this access is needed for hugo ? Thanks.

This is to fix Hugo Issue #6226 on GitHub:

where Julian Klode reported:

Running the hugo snap fails with

Building sites … ERROR 2019/08/15 19:04:04 Failed to read Git log:
fatal: unknown error occured while reading the configuration files

It can be reproduced today with the following commands:

$ git clone https://github.com/gohugoio/hugoDocs.git
Cloning into 'hugoDocs'...

$ cd hugoDocs

$ snap run hugo
Start building sites … 
hugo v0.96.0-2fd4a7d3d6845e75f8b8ae3a2a7bd91438967bbb+extended linux/amd64 BuildDate=2022-03-26T09:15:58Z VendorInfo=mage
ERROR 2022/06/24 01:24:45 Failed to read Git log: warning: unable to access '/etc/gitconfig': Permission denied
warning: unable to access '/etc/gitconfig': Permission denied
fatal: unknown error occurred while reading the configuration files
Error: Error building site: logged 1 error(s)

This happens on any Hugo sites where enableGitInfo is set to true because Hugo would then call git (via https://github.com/bep/gitmap) to “get the last Git revision information for every content file”. See Git Info Variables in the Hugo documentation for more information:

And note especially how, on that documentation page, the following Git commit info was included:

Last updated: December 26, 2021: docs: add a link to the mailmap documentation (963ddc994)

Thanks!