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?