]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
static: Preserve .gitignore and .gitattributes in --cleanDestinationDir
authorAhamed_Meyan <116168645+Ahamed1846@users.noreply.github.com>
Sun, 16 Nov 2025 10:10:20 +0000 (15:40 +0530)
committerGitHub <noreply@github.com>
Sun, 16 Nov 2025 10:10:20 +0000 (11:10 +0100)
 Fixes #14097

commands/hugobuilder.go

index ecca6ecc78e68c8b7b5cfd6db56e6cac14c60a01..bc8eeb588bea63ec58541c41d970ef7efb89929b 100644 (file)
@@ -464,7 +464,15 @@ func (c *hugoBuilder) copyStaticTo(sourceFs *filesystems.SourceFilesystem) (uint
                infol.Logf("removing all files from destination that don't exist in static dirs")
 
                syncer.DeleteFilter = func(f fsync.FileInfo) bool {
-                       return f.IsDir() && strings.HasPrefix(f.Name(), ".")
+                       name := f.Name()
+
+                       // Keep .gitignore and .gitattributes anywhere
+                       if name == ".gitignore" || name == ".gitattributes" {
+                               return true
+                       }
+
+                       // Keep Hugo's original dot-directory behavior
+                       return f.IsDir() && strings.HasPrefix(name, ".")
                }
        }
        start := time.Now()