aboutsummaryrefslogtreecommitdiffhomepage
path: root/hugolib
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2024-04-25 12:30:16 +0200
committerBjørn Erik Pedersen <[email protected]>2024-04-25 14:35:49 +0200
commit7203a95a6069b09a7546e5b2e286abe6455df83a (patch)
treeb61d582829a705f6eb47ba84ff697b656c5a79f6 /hugolib
parentfb084390cd8f2f62220489b8f1692863f57b25b6 (diff)
downloadhugo-7203a95a6069b09a7546e5b2e286abe6455df83a.tar.gz
hugo-7203a95a6069b09a7546e5b2e286abe6455df83a.zip
Fix rebuilds when running hugo -w
This was partly broken in Hugo 0.123.0. We have two internal config options that gets set from the CLI: * Running; a web server is running * Watching; either set via `hugo -w` or `hugo server --watch=false` Part of the change detection code wrongly used the `Running` as a flag when `Watching` would be the correct. Fixes #12296
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/integrationtest_builder.go17
-rw-r--r--hugolib/rebuild_test.go36
-rw-r--r--hugolib/site_new.go4
3 files changed, 41 insertions, 16 deletions
diff --git a/hugolib/integrationtest_builder.go b/hugolib/integrationtest_builder.go
index 8daf7b1ca..7495d3341 100644
--- a/hugolib/integrationtest_builder.go
+++ b/hugolib/integrationtest_builder.go
@@ -38,12 +38,20 @@ import (
type TestOpt func(*IntegrationTestConfig)
+// TestOptRunning will enable running in integration tests.
func TestOptRunning() TestOpt {
return func(c *IntegrationTestConfig) {
c.Running = true
}
}
+// TestOptWatching will enable watching in integration tests.
+func TestOptWatching() TestOpt {
+ return func(c *IntegrationTestConfig) {
+ c.Watching = true
+ }
+}
+
// Enable tracing in integration tests.
// THis should only be used during development and not committed to the repo.
func TestOptTrace() TestOpt {
@@ -570,6 +578,10 @@ func (s *IntegrationTestBuilder) initBuilder() error {
"running": s.Cfg.Running,
"watch": s.Cfg.Running,
})
+ } else if s.Cfg.Watching {
+ flags.Set("internal", maps.Params{
+ "watch": s.Cfg.Watching,
+ })
}
if s.Cfg.WorkingDir != "" {
@@ -817,6 +829,11 @@ type IntegrationTestConfig struct {
// Whether to simulate server mode.
Running bool
+ // Watch for changes.
+ // This is (currently) always set to true when Running is set.
+ // Note that the CLI for the server does allow for --watch=false, but that is not used in these test.
+ Watching bool
+
// Will print the log buffer after the build
Verbose bool
diff --git a/hugolib/rebuild_test.go b/hugolib/rebuild_test.go
index ea7efcb6f..4336d8b61 100644
--- a/hugolib/rebuild_test.go
+++ b/hugolib/rebuild_test.go
@@ -121,14 +121,23 @@ func TestRebuildEditTextFileInBranchBundle(t *testing.T) {
b.AssertRenderCountContent(1)
}
+func testRebuildBothWatchingAndRunning(t *testing.T, files string, withB func(b *IntegrationTestBuilder)) {
+ t.Helper()
+ for _, opt := range []TestOpt{TestOptWatching(), TestOptRunning()} {
+ b := Test(t, files, opt)
+ withB(b)
+ }
+}
+
func TestRebuildRenameTextFileInLeafBundle(t *testing.T) {
- b := TestRunning(t, rebuildFilesSimple)
- b.AssertFileContent("public/mysection/mysectionbundle/index.html", "My Section Bundle Text 2 Content.", "Len Resources: 2|")
+ testRebuildBothWatchingAndRunning(t, rebuildFilesSimple, func(b *IntegrationTestBuilder) {
+ b.AssertFileContent("public/mysection/mysectionbundle/index.html", "My Section Bundle Text 2 Content.", "Len Resources: 2|")
- b.RenameFile("content/mysection/mysectionbundle/mysectionbundletext.txt", "content/mysection/mysectionbundle/mysectionbundletext2.txt").Build()
- b.AssertFileContent("public/mysection/mysectionbundle/index.html", "mysectionbundletext2", "My Section Bundle Text 2 Content.", "Len Resources: 2|")
- b.AssertRenderCountPage(3)
- b.AssertRenderCountContent(3)
+ b.RenameFile("content/mysection/mysectionbundle/mysectionbundletext.txt", "content/mysection/mysectionbundle/mysectionbundletext2.txt").Build()
+ b.AssertFileContent("public/mysection/mysectionbundle/index.html", "mysectionbundletext2", "My Section Bundle Text 2 Content.", "Len Resources: 2|")
+ b.AssertRenderCountPage(3)
+ b.AssertRenderCountContent(3)
+ })
}
func TestRebuilEditContentFileInLeafBundle(t *testing.T) {
@@ -367,8 +376,6 @@ My short.
}
func TestRebuildBaseof(t *testing.T) {
- t.Parallel()
-
files := `
-- hugo.toml --
title = "Hugo Site"
@@ -383,12 +390,13 @@ Baseof: {{ .Title }}|
Home: {{ .Title }}|{{ .Content }}|
{{ end }}
`
- b := Test(t, files, TestOptRunning())
- b.AssertFileContent("public/index.html", "Baseof: Hugo Site|", "Home: Hugo Site||")
- b.EditFileReplaceFunc("layouts/_default/baseof.html", func(s string) string {
- return strings.Replace(s, "Baseof", "Baseof Edited", 1)
- }).Build()
- b.AssertFileContent("public/index.html", "Baseof Edited: Hugo Site|", "Home: Hugo Site||")
+ testRebuildBothWatchingAndRunning(t, files, func(b *IntegrationTestBuilder) {
+ b.AssertFileContent("public/index.html", "Baseof: Hugo Site|", "Home: Hugo Site||")
+ b.EditFileReplaceFunc("layouts/_default/baseof.html", func(s string) string {
+ return strings.Replace(s, "Baseof", "Baseof Edited", 1)
+ }).Build()
+ b.AssertFileContent("public/index.html", "Baseof Edited: Hugo Site|", "Home: Hugo Site||")
+ })
}
func TestRebuildSingleWithBaseof(t *testing.T) {
diff --git a/hugolib/site_new.go b/hugolib/site_new.go
index 59b97e887..496889295 100644
--- a/hugolib/site_new.go
+++ b/hugolib/site_new.go
@@ -123,14 +123,14 @@ func NewHugoSites(cfg deps.DepsCfg) (*HugoSites, error) {
HandlerPost: logHookLast,
Stdout: cfg.LogOut,
Stderr: cfg.LogOut,
- StoreErrors: conf.Running(),
+ StoreErrors: conf.Watching(),
SuppressStatements: conf.IgnoredLogs(),
}
logger = loggers.New(logOpts)
}
- memCache := dynacache.New(dynacache.Options{Running: conf.Running(), Log: logger})
+ memCache := dynacache.New(dynacache.Options{Watching: conf.Watching(), Log: logger})
firstSiteDeps := &deps.Deps{
Fs: cfg.Fs,