Hugo

Grouse, a diff tool for hugo sites

Hi everyone!

I just released the first version of grouse, a diff tool for hugo sites.

It works similarly to git diff, but instead of showing the differences in the source files, it shows you the differences in the generated site at the commit refs you supply.

e.g. running grouse master new-post will:

  • Checkout master, and build the site using hugo
  • Checkout new-post, and build the site using hugo
  • Display the difference in the two generated outputs using git diff.

I built this as a bash script when converting my blog over from Jekyll to Hugo, so that I could ensure that template and structure modifications didn’t have any unexpected side effects, and it’s something I’ve continued to use as I add more content to my site. I’ve since productionised it in the hope it would be useful to someone else :slight_smile:

There’s install and usage instructions at Grouse on Github – please let me know here or file issues there if you have any issues or questions!

6 Likes

This looks cool, thanks for sharing.

I tried this out and have three questions.

  1. Can you maybe provide an animated gif on here and/or the readme to demo this? Because of my new two questions, I’ve yet to see it work.
  2. I ran this on one of my repos with HEAD~1 and I get the following:
Computing diff between revisions HEAD~1 (7ce465a) and HEAD (218ead9)
Building revision HEAD~1 (7ce465a)…
panic: open /home/felicianotech/Repos/felicianotech/www.feliciano.tech/.git/objects/pack/pack-690942c8bc31c15142decb8c93a24d08d1d80b57.pack: too many open files

goroutine 1 [running]:
github.com/capnfabs/grouse/internal/pkg.runMain(0xc00011c380, 0xc00012c100, 0xc00011c380)
        /Users/fabian/Code/grouse/internal/pkg/functionality.go:116 +0xf23
github.com/capnfabs/grouse/internal/pkg.RunRootCommand(0xee82e0)
        /Users/fabian/Code/grouse/internal/pkg/functionality.go:44 +0x15e
main.glob..func1(0xee82e0, 0xc00011e790, 0x1, 0x1)
        /Users/fabian/Code/grouse/main.go:46 +0x2b
github.com/spf13/cobra.(*Command).execute(0xee82e0, 0xc00000c090, 0x1, 0x1, 0xee82e0, 0xc00000c090)
        /Users/fabian/Code/go/pkg/mod/github.com/spf13/cobra@v0.0.5/command.go:830 +0x2ae
github.com/spf13/cobra.(*Command).ExecuteC(0xee82e0, 0xa29538, 0x5, 0x0)
        /Users/fabian/Code/go/pkg/mod/github.com/spf13/cobra@v0.0.5/command.go:914 +0x2fc
github.com/spf13/cobra.(*Command).Execute(...)
        /Users/fabian/Code/go/pkg/mod/github.com/spf13/cobra@v0.0.5/command.go:864
main.main()
        /Users/fabian/Code/grouse/main.go:27 +0x1df

Any idea?

  1. I also tried running it with HEAD^ and instead I get this:
Computing diff between revisions HEAD^ (7ce465a) and HEAD (218ead9)
Building revision HEAD^ (7ce465a)…
Error: add site dependencies: create deps: failed to create file caches from configuration: mkdir /var/lib/snapd/void/resources: permission denied
Error: Building at commit HEAD^ (7ce465a) failed: exit status 255

This second issue looks different. Perhaps this is because I use Hugo as a snap?

Hi @FelicianoTech - thanks for the feedback; this is extremely helpful!

  1. Can you maybe provide an animated gif on here and/or the readme to demo this? Because of my new two questions, I’ve yet to see it work.

An animated gif is a great idea; thanks for the suggestion. With regards to the readme; do you mean adding a sample tool run, including the output? e.g, something like this?

$ git log --oneline
af215c7 (HEAD -> source, origin/source, origin/HEAD) Bump grouse date
2c0e9d9 Add featured photos to light leaks and isfabianstillalive posts
...

$ grouse HEAD^ --diffargs='--stat'
Computing diff between revisions HEAD^ (2c0e9d9) and HEAD (af215c7)
Building revision HEAD^ (2c0e9d9)…
Building revision HEAD (af215c7)…
Diffing…
 feed.xml                                                      |  4 ++--
 index.html                                                    |  2 +-
 index.xml                                                     |  4 ++--
 posts/grouse-diff-tool-hugo-static-site-generators/index.html | 12 ++++++------
 posts/index.html                                              |  4 ++--
 posts/index.xml                                               |  4 ++--
 posts/lofoten-norway/index.html                               |  2 +-
 sitemap.xml                                                   | 18 +++++++++---------
 tags/golang/index.html                                        |  4 ++--
 tags/golang/index.xml                                         |  4 ++--
 tags/index.html                                               | 12 ++++++------
 tags/index.xml                                                | 12 ++++++------
 tags/indie-web/index.html                                     |  4 ++--
 tags/indie-web/index.xml                                      |  4 ++--
 tags/projects/index.html                                      |  4 ++--
 tags/projects/index.xml                                       |  4 ++--
 tags/software-dev/index.html                                  |  4 ++--
 tags/software-dev/index.xml                                   |  4 ++--
 tags/tools/index.html                                         |  4 ++--
 tags/tools/index.xml                                          |  4 ++--
 20 files changed, 57 insertions(+), 57 deletions(-)
  1. I ran this on one of my repos with HEAD~1 and I get the following:

Ah, yep – it looks like I’d forgotten to close some open files in the code, and the repos I’d tested on thus far had less files than yours, so they didn’t hit any limits. I was able to reproduce that, and it’s now fixed on the latest version.

  1. I also tried running it with HEAD^ and instead I get this…Perhaps this is because I use Hugo as a snap?

Sounds plausible. Grouse makes extensive use of temporary files / directories, and that sounds like the sort of thing that could cause problems with a sandbox? I’ve so far had zero experience with snaps, but I’ll set up a VM and try and fix it sometime this weekend. :grinning:

Thanks again for the feedback / bug reports!

Ok, this does appear to be a limitation of snap-installed Hugo – according to #3143, it can’t be run in locations outside of $HOME or “gvfs-mounted directories owned by the user”; and that means that the /tmp/ directory is out. :frowning:

For the time being, there’s no good workaround for this, aside from installing Hugo through e.g. apt. I’ll think about if this is a problem I want to solve or not, and let you know if I come up with something :slight_smile:

  1. I mean if you create an animated gif, you can add it to the readme. Like what this project does: https://github.com/manifoldco/promptui
  2. Awesome.
  3. Yup. I’ll try investigate myself as well.
1 Like