]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Fix server rebuild when adding a new leaf bundle with resources in one go
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 21 Aug 2025 08:38:57 +0000 (10:38 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 21 Aug 2025 19:52:31 +0000 (21:52 +0200)
E.g. `cp -r`.

Note that this was not an issue if you first created the bundle, waited, and then created the resource(s).

Fixes #13925

hugolib/hugo_sites_build.go
hugolib/rebuild_test.go

index bad55a210b69dbf9333e6b40adb03cd8466d54ec..70c806b78a330edfb72e78112c8b5aa8185d960e 100644 (file)
@@ -830,6 +830,7 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo
 
        changedPaths := struct {
                changedFiles []*paths.Path
+               addedFiles   []*paths.Path
                changedDirs  []*paths.Path
                deleted      []*paths.Path
        }{}
@@ -896,13 +897,15 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo
                        changedPaths.deleted = append(changedPaths.deleted, pss...)
                } else if ev.isChangedDir {
                        changedPaths.changedDirs = append(changedPaths.changedDirs, pss...)
+               } else if ev.added {
+                       changedPaths.addedFiles = append(changedPaths.addedFiles, pss...)
                } else {
                        changedPaths.changedFiles = append(changedPaths.changedFiles, pss...)
                }
        }
 
        // Find the most specific identity possible.
-       handleChange := func(pathInfo *paths.Path, delete, isDir bool) {
+       handleChange := func(pathInfo *paths.Path, delete, add, isDir bool) {
                switch pathInfo.Component() {
                case files.ComponentFolderContent:
                        logger.Println("Source changed", pathInfo.Path())
@@ -963,7 +966,10 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo
                                }
                        }
 
-                       addedOrChangedContent = append(addedOrChangedContent, pathChange{p: pathInfo, structural: delete, isDir: isDir})
+                       structural := delete
+                       structural = structural || (add && pathInfo.IsLeafBundle())
+
+                       addedOrChangedContent = append(addedOrChangedContent, pathChange{p: pathInfo, structural: structural, isDir: isDir})
 
                case files.ComponentFolderLayouts:
                        tmplChanged = true
@@ -1019,6 +1025,7 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo
        }
 
        changedPaths.deleted = removeDuplicatePaths(changedPaths.deleted)
+       changedPaths.addedFiles = removeDuplicatePaths(changedPaths.addedFiles)
        changedPaths.changedFiles = removeDuplicatePaths(changedPaths.changedFiles)
 
        h.Log.Trace(logg.StringFunc(func() string {
@@ -1029,6 +1036,11 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo
                        sb.WriteString("path: " + p.Path())
                        sb.WriteString("\n")
                }
+               sb.WriteString("Added:\n")
+               for _, p := range changedPaths.addedFiles {
+                       sb.WriteString("path: " + p.Path())
+                       sb.WriteString("\n")
+               }
                sb.WriteString("Changed:\n")
                for _, p := range changedPaths.changedFiles {
                        sb.WriteString("path: " + p.Path())
@@ -1074,15 +1086,19 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo
        }
 
        for _, deleted := range changedPaths.deleted {
-               handleChange(deleted, true, false)
+               handleChange(deleted, true, false, false)
+       }
+
+       for _, id := range changedPaths.addedFiles {
+               handleChange(id, false, true, false)
        }
 
        for _, id := range changedPaths.changedFiles {
-               handleChange(id, false, false)
+               handleChange(id, false, false, false)
        }
 
        for _, id := range changedPaths.changedDirs {
-               handleChange(id, false, true)
+               handleChange(id, false, false, true)
        }
 
        for _, id := range changes {
index d4a15fb5bf14b12c531dab519a63208e86191713..38752b90e05e187f61753c233396cac8b48c1bb1 100644 (file)
@@ -125,6 +125,24 @@ func TestRebuildEditTextFileInLeafBundle(t *testing.T) {
        b.AssertRenderCountContent(0)
 }
 
+func TestRebuildAddingALeaffBundleIssue13925(t *testing.T) {
+       t.Parallel()
+
+       b := TestRunning(t, rebuildFilesSimple)
+
+       b.AddFiles(
+               "content/mysection/mysectionbundle2/index.md", "",
+               "content/mysection/mysectionbundle2/mysectionbundletext.txt", "mysectionbundletext.txt").Build()
+
+       b.AssertFileContent("public/mysection/mysectionbundle2/index.html", "Len Resources: 1|")
+
+       b.AddFiles(
+               "content/mynewsection/_index.md", "",
+               "content/mynewsection/mynewsectiontext.txt", "foo").Build()
+
+       b.AssertFileContent("public/mynewsection/index.html", "Len Resources: 1|")
+}
+
 func TestRebuildEditTextFileInShortcode(t *testing.T) {
        t.Parallel()
        for range 3 {