Revert "Remove the --cleanDestinationDir flag", there is a better fix.
authorAlexander Borsuk <me@alex.bio>
Wed, 10 Jan 2018 15:53:40 +0000 (18:53 +0300)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 10 Jan 2018 17:26:42 +0000 (18:26 +0100)
This reverts commit 768ec5df9fa8f91610ee80a9e6194f94a7dbe117.

commands/hugo.go
hugolib/config.go

index 01afaaa4c0a7c14e633a6176542e3dcd19a1dcbe..0e7b755f79b9bc2b9457f9971082f1a7261b97f4 100644 (file)
@@ -237,6 +237,7 @@ func initRootPersistentFlags() {
 // initHugoBuildCommonFlags initialize common flags related to the Hugo build.
 // Called by initHugoBuilderFlags.
 func initHugoBuildCommonFlags(cmd *cobra.Command) {
+       cmd.Flags().Bool("cleanDestinationDir", false, "remove files from destination not found in static directories")
        cmd.Flags().BoolP("buildDrafts", "D", false, "include content marked as draft")
        cmd.Flags().BoolP("buildFuture", "F", false, "include content with publishdate in the future")
        cmd.Flags().BoolP("buildExpired", "E", false, "include expired content")
@@ -483,6 +484,7 @@ func createLogger(cfg config.Provider) (*jww.Notepad, error) {
 func (c *commandeer) initializeFlags(cmd *cobra.Command) {
        persFlagKeys := []string{"debug", "verbose", "logFile"}
        flagKeys := []string{
+               "cleanDestinationDir",
                "buildDrafts",
                "buildFuture",
                "buildExpired",
@@ -722,6 +724,9 @@ func (c *commandeer) copyStaticTo(dirs *src.Dirs, publishDir string) (uint64, er
        syncer.NoChmod = c.Cfg.GetBool("noChmod")
        syncer.SrcFs = fs
        syncer.DestFs = c.Fs.Destination
+       // Now that we are using a unionFs for the static directories
+       // We can effectively clean the publishDir on initial sync
+       syncer.Delete = c.Cfg.GetBool("cleanDestinationDir")
 
        if syncer.Delete {
                c.Logger.INFO.Println("removing all files from destination that don't exist in static dirs")
index ce0f5bac97f26f1ba9c77a18f63139a632caf521..8e06d3e8e9227d88d43391f4ed7ba6859d6e0a15 100644 (file)
@@ -164,6 +164,7 @@ func loadDefaultSettingsFor(v *viper.Viper) error {
                return err
        }
 
+       v.SetDefault("cleanDestinationDir", false)
        v.SetDefault("watch", false)
        v.SetDefault("metaDataFormat", "toml")
        v.SetDefault("disable404", false)