Hugo Server incorrect source change detection

I have an odd behaviour. The following is the smallest possible way I can reproduce it.

In one terminal I’m running git. I’m on the main branch and everything is up to date, git diff returns nothing.

command 1> git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
command 2> git diff
command 3> 

If I’m running hugo server in another terminal, right after the git diff returns I get a panic as given below.

command> hugo server
.... Lots of lines
Source changed /posts/2025-203/themes/eclectic-develop/examplesite/themes/eclectic/examplesite
Source changed /posts/2025-203/themes/eclectic-develop/examplesite/themes/eclectic/examplesite/themes/eclectic
Source changed /posts/2025-203/themes/eclectic-develop/examplesite/themes/eclectic/static
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
Total in 13 ms
panic: runtime error: index out of range [793] with length 793
goroutine 21 [running]:
github.com/gohugoio/hugo/hugolib.(*HugoSites).fileEventsContentPaths(0x140027a3030?, {0x1400463c008?, 0x4e?, 0xa?})
github.com/gohugoio/hugo/hugolib/site.go:1135 +0xa98
github.com/gohugoio/hugo/hugolib.(*HugoSites).processPartialFileEvents(0x14000a60f20, {0x1051ca238, 0x1069a6040}, {0x1051d54f0, 0x140005219e0}, 0x14003de64c0, 0x140000634c0, {0x140039a4000, 0x31f, 0x400})
github.com/gohugoio/hugo/hugolib/hugo_sites_build.go:1046 +0xa64
github.com/gohugoio/hugo/hugolib.(*HugoSites).process(0x14000a60f20, {0x1051ca238, 0x1069a6040}, {0x1051d54f0?, 0x140005219e0?}, 0x14003de64c0, 0x140000634c0, {0x140039a4000, 0x31f, 0x400})
github.com/gohugoio/hugo/hugolib/hugo_sites_build.go:255 +0x1e4
github.com/gohugoio/hugo/hugolib.(*HugoSites).Build.func4()
github.com/gohugoio/hugo/hugolib/hugo_sites_build.go:148 +0x88
github.com/gohugoio/hugo/hugolib.(*HugoSites).Build(0x14000a60f20, {0x0, 0x0, 0x0, 0x0, 0x140001235f0, 0x0, 0x1, 0x0}, {0x140039a4000, ...})
github.com/gohugoio/hugo/hugolib/hugo_sites_build.go:159 +0x52c
github.com/gohugoio/hugo/commands.(*hugoBuilder).rebuildSites(0x14000907c00, {0x140039a4000, 0x31f, 0x400})
github.com/gohugoio/hugo/commands/hugobuilder.go:1106 +0x144
github.com/gohugoio/hugo/commands.(*hugoBuilder).handleEvents.func7(0x14000907c00, 0x14003060a50)
github.com/gohugoio/hugo/commands/hugobuilder.go:910 +0x7c
github.com/gohugoio/hugo/commands.(*hugoBuilder).handleEvents(0x14000907c00, 0x14000b43680, 0x14000c1d738, {0x14002092848, 0xf, 0x11}, 0x14000ba44b0)
github.com/gohugoio/hugo/commands/hugobuilder.go:913 +0x164c
github.com/gohugoio/hugo/commands.(*hugoBuilder).newWatcher.func2()
github.com/gohugoio/hugo/commands/hugobuilder.go:368 +0x208
created by github.com/gohugoio/hugo/commands.(*hugoBuilder).newWatcher in goroutine 1
github.com/gohugoio/hugo/commands/hugobuilder.go:339 +0x400

The panic appears to be due to a commit I did two days ago where I checked in around 2000 files in error. I had a similar failure at the time when hugo server would run at all, but after I checked in the files all was OK.

The weird thing now is that something is that someone hugo (or fsnotify) is “remembering” the old checkin when I run the diff command.

I’m using the latest version of hugo as follows

prompt> hugo version
hugo v0.140.2+extended+withdeploy darwin/arm64 BuildDate=2024-12-30T15:01:53Z VendorInfo=brew

The issue here of course is that every time I run git diff, I have to rerun hugo server.

I presume something is being cached somewhere. Any suggestions for how I can clear this, either in git or in hugo?

Are you using git diff out of the box or did you configure any program that makes your diffing-life easier? If the latter, does that maybe create temporary files?

It could be that the diff has nothing to do with the error, because you left out “lots of lines”. A more specific issue could hide there. But let’s see if diff could break things. If your diff for instance shows changes in layout files and then some of the logic is borked and put into a temporary file in one of the monitored folders then Hugo will see it and panic.

Another question: Are you in a VSCode terminal? That one is behaving odd recently and remembers and caches stuff in the filesystem. Using a terminal from the startmenu might fix it in that case.

I’m using vanilla Terminal.app on a Mac with the git which comes with XCode command line tools.

I too wondered if git diff was creating temporary files, but if this was the case I’d expect to see this sort of thing all the time.

By the way the panic happens when I quit git diff, i.e hit q.

what about git maintenance gc pack… just a thought

Still have the issue, but it looks like it is only with recent versions of hugo

Here is what I’ve tried

  1. I tried git fsck, no difference.
  2. I tried to create a fresh checkout, no difference.
  3. Really strangely, if I run git diff in another repository I still get the same issue.

However I don’t have the issue in earlier versions of hugo. Note that I original used homebrew which won’t let me (easily) revert to an older version, so I’ve downloaded from the release area instead.

For this version I have the issue

hugo v0.140.2-aae02ca612a02e085c08366a9c9279f4abb39d94+extended darwin/arm64 BuildDate=2024-12-30T15:01:53Z VendorInfo=gohugoio

For this version I have the issue

hugo v0.140.1-a9b0b95ef402a1cc70bc5386d649d947e2bcc027+extended+withdeploy darwin/arm64 BuildDate=2024-12-23T16:26:35Z VendorInfo=gohugoio

For this version I have the issue

hugo v0.140.0-3f35721fb2c75a1f7cc5a7a14400b66e73d4b06e+extended+withdeploy darwin/arm64 BuildDate=2024-12-17T14:20:55Z VendorInfo=gohugoio

For this version I don’t have the issue

hugo v0.137.1-17e15b2148cee6da923acd7adf2ec31ea6b3415c+extended darwin/arm64 BuildDate=2024-11-05T11:49:09Z VendorInfo=gohugoio

So now it is time to narrow down which version introduced the issue. Note that it doesn’t appear to depend on whether I have extended or withdeploy, so I’ll just try extended

For this version I have the issue

hugo v0.139.4-3afe91d4b1b069abbedd6a96ed755b1e12581dfe+extended darwin/arm64 BuildDate=2024-12-09T17:45:23Z VendorInfo=gohugoio

For this version I don’t have the issue

hugo v0.138.0-ad82998d54b3f9f8c2741b67356813b55b3134b9+extended darwin/arm64 BuildDate=2024-11-06T11:22:34Z VendorInfo=gohugoio

For this version I do have the issue

hugo v0.139.2-770f548b47b39e6f0fd4da1cc80552024e5829e1+extended darwin/arm64 BuildDate=2024-11-23T15:33:51Z VendorInfo=gohugoio

For this version I do have the issue

hugo v0.139.0-dacef0df92a9a20072b4eaa42003e1a63ace8f41+extended darwin/arm64 BuildDate=2024-11-18T16:17:45Z VendorInfo=gohugoio

So it looks like the issue, whatever it is, was introduced in v0.139.0. I can see that fs-notify was bumped from 1.7.0 to 1.8.0. 1.8.0 was released on October 31, 2024. I can see a number have issues have been raised since then although none of them are obviously related to what I’m seeing here although those who use the fsnotify API might be able to see a connection.

I’d been happily running hugo 0.119 for quite some time so didn’t see this until I did an upgrade a few days ago. If I’m the only one who has triggered this I’m more than happy to just use 0.138.0 until there is a new release of fsnotify and hugo includes it. I can try again.

On the other hand if this is something that needs more immediate attention then if there is anything I can do to assist with narrowing down the issue (e.g. running with logging or against a dev branch) please let me know.

You can bypass fsnotify by specifying the poll CLI flag. For example:

hugo server --poll 700ms

This FAQ provides a little more detail.

Maybe just test it, or maybe run with it if it solves your particular problem.

I’ve gone back to 0.140.2 to try this and the issue isn’t appearing.

Thanks!