Fix rebuild logic when editing template using a base template
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 28 Feb 2020 11:39:58 +0000 (12:39 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 28 Feb 2020 13:14:55 +0000 (14:14 +0100)
We have been doing too much work in that case.

Fixes #6968

hugolib/hugo_sites_rebuild_test.go
tpl/tplimpl/template.go

index eca6c730bef8b615773053d7e58d78023fa362d0..1f0b1b5d9f5a14f55b4b4e93f9a729f39abcf03e 100644 (file)
@@ -15,6 +15,8 @@ package hugolib
 
 import (
        "testing"
+
+       qt "github.com/frankban/quicktest"
 )
 
 func TestSitesRebuild(t *testing.T) {
@@ -142,6 +144,29 @@ Data Inline: Rules!`)
 
        })
 
+       // https://github.com/gohugoio/hugo/issues/6968
+       t.Run("Edit single.html with base", func(t *testing.T) {
+               b := newTestSitesBuilder(t).Running()
+
+               b.WithTemplates(
+                       "_default/single.html", `{{ define "main" }}Single{{ end }}`,
+                       "_default/baseof.html", `Base: {{ block "main"  .}}Block{{ end }}`,
+               )
+
+               b.WithContent("p1.md", "---\ntitle: Page\n---")
+
+               b.Build(BuildCfg{})
+
+               b.EditFiles("layouts/_default/single.html", `Single Edit: {{ define "main" }}Single{{ end }}`)
+
+               counters := &testCounters{}
+
+               b.Build(BuildCfg{testCounters: counters})
+
+               b.Assert(int(counters.contentRenderCounter), qt.Equals, 0)
+
+       })
+
        t.Run("Page.Render, edit baseof", func(t *testing.T) {
                b := createSiteBuilder(t)
 
index 457a5cb9285c802e51b7ef82e54d6e316d1dd1e7..b6313e1e5a9d88a5d19fd32a607b19ccc4dbdb4e 100644 (file)
@@ -383,9 +383,15 @@ func (t *templateHandler) LookupVariant(name string, variants tpl.TemplateVarian
 }
 
 func (t *templateHandler) HasTemplate(name string) bool {
+
        if _, found := t.baseof[name]; found {
                return true
        }
+
+       if _, found := t.needsBaseof[name]; found {
+               return true
+       }
+
        _, found := t.Lookup(name)
        return found
 }