Skip to content

Commit 5e6b269

Browse files
authored
static: Preserve .gitignore and .gitattributes in --cleanDestinationDir
Fixes #14097
1 parent 94a6233 commit 5e6b269

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

‎commands/hugobuilder.go‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,15 @@ func (c *hugoBuilder) copyStaticTo(sourceFs *filesystems.SourceFilesystem) (uint
464464
infol.Logf("removing all files from destination that don't exist in static dirs")
465465

466466
syncer.DeleteFilter = func(f fsync.FileInfo) bool {
467-
return f.IsDir() && strings.HasPrefix(f.Name(), ".")
467+
name := f.Name()
468+
469+
// Keep .gitignore and .gitattributes anywhere
470+
if name == ".gitignore" || name == ".gitattributes" {
471+
return true
472+
}
473+
474+
// Keep Hugo's original dot-directory behavior
475+
return f.IsDir() && strings.HasPrefix(name, ".")
468476
}
469477
}
470478
start := time.Now()

0 commit comments

Comments
 (0)