From: Ahamed_Meyan <116168645+Ahamed1846@users.noreply.github.com> Date: Sun, 16 Nov 2025 10:10:20 +0000 (+0530) Subject: static: Preserve .gitignore and .gitattributes in --cleanDestinationDir X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=5e6b269c412cd564c3ea33c74453192efc9aa044;p=brevno-suite%2Fhugo static: Preserve .gitignore and .gitattributes in --cleanDestinationDir Fixes #14097 --- diff --git a/commands/hugobuilder.go b/commands/hugobuilder.go index ecca6ecc7..bc8eeb588 100644 --- a/commands/hugobuilder.go +++ b/commands/hugobuilder.go @@ -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()