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!

Can the gitinfo problem be fixed by adding a gitconfig to the snap package and using layout: to map it to /etc/gitconfig to alleviate the requirement to access the host gitconfig? That would get this particular feature working quicker than waiting for the vote.

It might but then it won’t be able to access the real git config and so may not respect the users configured name etc - better to just do the right thing here and provide access via system/personal-files.

+1 from me for auto-connect of system-files named etc-gitconfig for read access to /etc/gitconfig and for personal-files named gitconfig for read access to ~/.gitconfig and ~/.config/git/config for hugo as this is a standard feature for hugo projects to be able to access and include this information.

Can other @reviewers please vote too?

+1 from me for the auto-connect, as above.

+2 votes for, 0 votes against, granting auto-connect and use of system-files named etc-gitconfig for read access to /etc/gitconfig and for personal-files named gitconfig for read access to ~/.gitconfig and ~/.config/git/config for hugo. This is now live.

1 Like