From 5e6b269c412cd564c3ea33c74453192efc9aa044 Mon Sep 17 00:00:00 2001 From: Ahamed_Meyan <116168645+Ahamed1846@users.noreply.github.com> Date: Sun, 16 Nov 2025 15:40:20 +0530 Subject: [PATCH] static: Preserve .gitignore and .gitattributes in --cleanDestinationDir Fixes #14097 --- commands/hugobuilder.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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() -- 2.39.5