From 59e0446fe5c7cb8080a3f0736c4453110b89f732 Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Thu, 12 Mar 2026 18:31:12 -0700 Subject: [PATCH] hugolib: Fix server no watch Closes #14615 Co-authored-by: Claude Sonnet 4.6 --- hugolib/hugo_sites_build.go | 2 +- testscripts/server/server__watch_false.txt | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 testscripts/server/server__watch_false.txt diff --git a/hugolib/hugo_sites_build.go b/hugolib/hugo_sites_build.go index 17f7c492e..84b070d13 100644 --- a/hugolib/hugo_sites_build.go +++ b/hugolib/hugo_sites_build.go @@ -61,7 +61,7 @@ import ( // Build builds all sites. If filesystem events are provided, // this is considered to be a potential partial rebuild. func (h *HugoSites) Build(config BuildCfg, events ...fsnotify.Event) error { - if h.isRebuild() && !h.Conf.Watching() { + if h.isRebuild() && !h.Conf.Watching() && !h.Conf.Running() { return errors.New("Build called multiple times when not in watch or server mode (typically with hugolib.Test(t, files).Build(); Build() is already called once by Test)") } if !h.isRebuild() && terminal.PrintANSIColors(os.Stdout) { diff --git a/testscripts/server/server__watch_false.txt b/testscripts/server/server__watch_false.txt new file mode 100644 index 000000000..2c6fe0b71 --- /dev/null +++ b/testscripts/server/server__watch_false.txt @@ -0,0 +1,17 @@ +# Test the hugo server command with watch disabled. + +hugo server --watch=false & + +waitServer + +httpget $HUGOTEST_BASEURL_0 'HOME' +httpget $HUGOTEST_BASEURL_0 'HOME' + +stopServer +! stderr . + +-- hugo.toml -- +baseURL = 'https://example.org/' +disableKinds = ['page','rss','section','sitemap','taxonomy','term'] +-- layouts/home.html -- +HOME -- 2.39.5