Skip to content

Commit 744b856

Browse files
committed
Fix a rebuild on resource rename case
1 parent 7de5317 commit 744b856

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

hugolib/hugo_sites_build.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -738,15 +738,15 @@ type pathChange struct {
738738
// The path to the changed file.
739739
p *paths.Path
740740

741-
// If true, this is a delete operation (a delete or a rename).
742-
delete bool
741+
// If true, this is a structural change (e.g. a delete or a rename).
742+
structural bool
743743

744744
// If true, this is a directory.
745745
isDir bool
746746
}
747747

748748
func (p pathChange) isStructuralChange() bool {
749-
return p.delete || p.isDir
749+
return p.structural || p.isDir
750750
}
751751

752752
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
912912
}
913913
}
914914

915-
addedOrChangedContent = append(addedOrChangedContent, pathChange{p: pathInfo, delete: delete, isDir: isDir})
915+
addedOrChangedContent = append(addedOrChangedContent, pathChange{p: pathInfo, structural: delete, isDir: isDir})
916916

917917
case files.ComponentFolderLayouts:
918918
tmplChanged = true
@@ -1033,6 +1033,16 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo
10331033
handleChange(id, false, true)
10341034
}
10351035

1036+
for _, id := range changes {
1037+
if id == identity.GenghisKhan {
1038+
for i, cp := range addedOrChangedContent {
1039+
cp.structural = true
1040+
addedOrChangedContent[i] = cp
1041+
}
1042+
break
1043+
}
1044+
}
1045+
10361046
resourceFiles := h.fileEventsContentPaths(addedOrChangedContent)
10371047

10381048
changed := &WhatChanged{

internal/js/esbuild/batch_integration_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,20 @@ func TestBatchEditScriptParam(t *testing.T) {
184184
b.AssertFileContent("public/mybatch/mygroup.js", "param-p1-main-edited")
185185
}
186186

187+
func TestBatchRenameBundledScript(t *testing.T) {
188+
files := jsBatchFilesTemplate
189+
b := hugolib.TestRunning(t, files, hugolib.TestOptWithOSFs())
190+
b.AssertFileContent("public/mybatch/p1.js", "P1 Script")
191+
b.RenameFile("content/p1/p1script.js", "content/p1/p1script2.js")
192+
_, err := b.BuildE()
193+
b.Assert(err, qt.IsNotNil)
194+
b.Assert(err.Error(), qt.Contains, "resource not set")
195+
196+
// Rename it back.
197+
b.RenameFile("content/p1/p1script2.js", "content/p1/p1script.js")
198+
b.Build()
199+
}
200+
187201
func TestBatchErrorScriptResourceNotSet(t *testing.T) {
188202
files := strings.Replace(jsBatchFilesTemplate, `(resources.Get "js/main.js")`, `(resources.Get "js/doesnotexist.js")`, 1)
189203
b, err := hugolib.TestE(t, files, hugolib.TestOptWithOSFs())

0 commit comments

Comments
 (0)