Fix a rebuild on resource rename case

This commit is contained in:
Bjørn Erik Pedersen 2024-12-15 10:52:53 +01:00
parent 7de5317aef
commit 744b8566ec
2 changed files with 28 additions and 4 deletions

View file

@ -738,15 +738,15 @@ type pathChange struct {
// The path to the changed file. // The path to the changed file.
p *paths.Path p *paths.Path
// If true, this is a delete operation (a delete or a rename). // If true, this is a structural change (e.g. a delete or a rename).
delete bool structural bool
// If true, this is a directory. // If true, this is a directory.
isDir bool isDir bool
} }
func (p pathChange) isStructuralChange() bool { func (p pathChange) isStructuralChange() bool {
return p.delete || p.isDir return p.structural || p.isDir
} }
func (h *HugoSites) processPartialRebuildChanges(ctx context.Context, l logg.LevelLogger, config *BuildCfg) error { func (h *HugoSites) processPartialRebuildChanges(ctx context.Context, l logg.LevelLogger, config *BuildCfg) error {
@ -912,7 +912,7 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo
} }
} }
addedOrChangedContent = append(addedOrChangedContent, pathChange{p: pathInfo, delete: delete, isDir: isDir}) addedOrChangedContent = append(addedOrChangedContent, pathChange{p: pathInfo, structural: delete, isDir: isDir})
case files.ComponentFolderLayouts: case files.ComponentFolderLayouts:
tmplChanged = true tmplChanged = true
@ -1033,6 +1033,16 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo
handleChange(id, false, true) handleChange(id, false, true)
} }
for _, id := range changes {
if id == identity.GenghisKhan {
for i, cp := range addedOrChangedContent {
cp.structural = true
addedOrChangedContent[i] = cp
}
break
}
}
resourceFiles := h.fileEventsContentPaths(addedOrChangedContent) resourceFiles := h.fileEventsContentPaths(addedOrChangedContent)
changed := &WhatChanged{ changed := &WhatChanged{

View file

@ -184,6 +184,20 @@ func TestBatchEditScriptParam(t *testing.T) {
b.AssertFileContent("public/mybatch/mygroup.js", "param-p1-main-edited") b.AssertFileContent("public/mybatch/mygroup.js", "param-p1-main-edited")
} }
func TestBatchRenameBundledScript(t *testing.T) {
files := jsBatchFilesTemplate
b := hugolib.TestRunning(t, files, hugolib.TestOptWithOSFs())
b.AssertFileContent("public/mybatch/p1.js", "P1 Script")
b.RenameFile("content/p1/p1script.js", "content/p1/p1script2.js")
_, err := b.BuildE()
b.Assert(err, qt.IsNotNil)
b.Assert(err.Error(), qt.Contains, "resource not set")
// Rename it back.
b.RenameFile("content/p1/p1script2.js", "content/p1/p1script.js")
b.Build()
}
func TestBatchErrorScriptResourceNotSet(t *testing.T) { func TestBatchErrorScriptResourceNotSet(t *testing.T) {
files := strings.Replace(jsBatchFilesTemplate, `(resources.Get "js/main.js")`, `(resources.Get "js/doesnotexist.js")`, 1) files := strings.Replace(jsBatchFilesTemplate, `(resources.Get "js/main.js")`, `(resources.Get "js/doesnotexist.js")`, 1)
b, err := hugolib.TestE(t, files, hugolib.TestOptWithOSFs()) b, err := hugolib.TestE(t, files, hugolib.TestOptWithOSFs())