{"record":{"id":"0ae130fd92cc3222","repo":"gohugoio/hugo","slug":"createpath-already-exists-and-is-not-empty-see","errorCode":null,"errorMessage":"{createpath} already exists and is not empty. See --force.","messagePattern":"(.+?) already exists and is not empty\\. See --force\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"create/skeletons/skeletons.go","lineNumber":106,"sourceCode":"\t\treturn err\n\t}\n\n\treturn copyFiles(createpath, sourceFs, themeFs)\n}\n\n// CreateProject creates a project skeleton.\nfunc CreateProject(createpath string, sourceFs afero.Fs, force bool, format string) error {\n\tformat = strings.ToLower(format)\n\tif exists, _ := helpers.Exists(createpath, sourceFs); exists {\n\t\tif isDir, _ := helpers.IsDir(createpath, sourceFs); !isDir {\n\t\t\treturn errors.New(createpath + \" already exists but not a directory\")\n\t\t}\n\n\t\tisEmpty, _ := helpers.IsEmpty(createpath, sourceFs)\n\n\t\tswitch {\n\t\tcase !isEmpty && !force:\n\t\t\treturn errors.New(createpath + \" already exists and is not empty. See --force.\")\n\t\tcase !isEmpty && force:\n\t\t\tvar all []string\n\t\t\tfs.WalkDir(projectFs, \".\", func(path string, d fs.DirEntry, err error) error {\n\t\t\t\tif d.IsDir() && path != \".\" {\n\t\t\t\t\tall = append(all, path)\n\t\t\t\t}\n\t\t\t\treturn nil\n\t\t\t})\n\t\t\tall = append(all, filepath.Join(createpath, \"hugo.\"+format))\n\t\t\tfor _, path := range all {\n\t\t\t\tif exists, _ := helpers.Exists(path, sourceFs); exists {\n\t\t\t\t\treturn errors.New(path + \" already exists\")\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprojectConfig := map[string]any{","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/create/skeletons/skeletons.go#L88-L124","documentation":"CreateProject will not scaffold into a non-empty existing directory unless --force is passed. This guard prevents clobbering an existing project's contents.","triggerScenarios":"`hugo new site .` (or any existing non-empty directory) without --force.","commonSituations":"Re-scaffolding into an already-populated project; targeting a directory that holds a git repo or other files.","solutions":["Pass --force to allow scaffolding into a non-empty directory.","Target an empty directory instead.","Remove the conflicting contents before scaffolding."],"exampleFix":"// before\nhugo new site .   # directory not empty\n// after\nhugo new site . --force","handlingStrategy":"validation","validationCode":"// Reject non-empty target unless force is intended\nif entries, err := os.ReadDir(createpath); err == nil && len(entries) > 0 && !force {\n    return fmt.Errorf(\"%s not empty; pass --force to proceed\", createpath)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass --force to scaffold into populated directories.","Target empty directories when possible.","Back up existing projects before re-scaffolding."],"tags":["hugo","cli","filesystem","scaffold"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}