--cleanDestinationDir and hidden files

Currently, when you run hugo --cleanDestinationDir, hidden directories are retained, but hidden files are deleted.


├── blog/
├── .git/
├── index.html
└── .keepme


├── blog/
├── .git/
└── index.html

Should the --cleanDestinationDir option be modified to retain hidden files as well as hidden directories?

I raise the question because of https://github.com/gohugoio/hugo/pull/6261#issuecomment-832705667.

IMHO no. Add a second parameter how to work with hidden files/directories like --cleanHiddenItems or --cleanDestinationDirIgnoredItems.

The public directory in Hugo can be seen as a dist directory in many projects and this basically is a directory that can be arbitrarily destroyed and recreated on builds. The amount of reasons why anything in it should require to be retained is much lower than the uses of a completely emptied directory.

If a project needs to commit the contents of the public directory in an extra repository so that some form of deployment can be done - that is “abuse” in my eyes of how Git works :wink: There are ways to add the directory to a branch without having the whole history sitting in a repo clone inside of a repo clone.

ie here:

My rationale in short is:

  • hidden files/folders in a system are there to hide system-relevant files from the UNKNOWING user and keep them available for the system
  • Hugo (the system) creates static websites by creating a public folder and outputting files in that folder.
  • Hidden files in that folder are KNOWINGLY added and not system relevant

--cleanDestinationDir should EMPTY the public directory of all elements.

1 Like

I agree, and was surprised to learn that we retain hidden directories.

That’s not what cleanDestinationDir does – it cleans out files not in /static – presumably (this was implemented by Steve) to avoid copying lots of static files on every build.

I have never used that flag, and I would rather remove it than spending time discussing nitty details.

Yeah, I am not using it either and do some rimraf thing in my deploy scripts instead. Removing would be ok.

My use case : I use cleanDestinationDir to be sure that if some file where created by my code version N-1 but no more in version N they will be removed.

1 Like

I disagree. I have KNOWINGLY made the public folder a git submodule and I definitely DO NOT want the .git folder deleted without my knowledge.