{"id":"06ab7b0509b484e2","repo":"gohugoio/hugo","slug":"target-path-s-exists-and-is-not-empty","errorCode":null,"errorMessage":"target path \"%s\" exists and is not empty","messagePattern":"target path \"(.+?)\" exists and is not empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"commands/import.go","lineNumber":172,"sourceCode":"\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn postDirs, hasAnyPost\n}\n\nfunc (c *importCommand) createProjectFromJekyll(jekyllRoot, targetDir string, jekyllPostDirs map[string]bool) error {\n\tfs := &afero.OsFs{}\n\tif exists, _ := helpers.Exists(targetDir, fs); exists {\n\t\tif isDir, _ := helpers.IsDir(targetDir, fs); !isDir {\n\t\t\treturn errors.New(\"target path \\\"\" + targetDir + \"\\\" exists but is not a directory\")\n\t\t}\n\n\t\tisEmpty, _ := helpers.IsEmpty(targetDir, fs)\n\n\t\tif !isEmpty && !c.force {\n\t\t\treturn errors.New(\"target path \\\"\" + targetDir + \"\\\" exists and is not empty\")\n\t\t}\n\t}\n\n\tjekyllConfig := c.loadJekyllConfig(fs, jekyllRoot)\n\n\tmkdir(targetDir, \"layouts\")\n\tmkdir(targetDir, \"content\")\n\tmkdir(targetDir, \"archetypes\")\n\tmkdir(targetDir, \"static\")\n\tmkdir(targetDir, \"data\")\n\tmkdir(targetDir, \"themes\")\n\n\tc.createConfigFromJekyll(fs, targetDir, \"yaml\", jekyllConfig)\n\n\tc.copyJekyllFilesAndFolders(jekyllRoot, filepath.Join(targetDir, \"static\"), jekyllPostDirs)\n\n\treturn nil\n}","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/commands/import.go#L154-L190","documentation":"Returned by `hugo import jekyll` when the target directory already exists, contains files, and --force was not given (commands/import.go:169-173). This is a safety guard: the importer writes a whole project scaffold and converted content into the target, and refuses to mingle with or overwrite existing files unless explicitly forced.","triggerScenarios":"Running `hugo import jekyll <jekyllRoot> <target>` where <target> is an existing non-empty directory without passing `--force`. Common exact cases: re-running the import after a partial/failed first attempt, or targeting a directory that already holds a `.git` folder or README.","commonSituations":"Re-running the import to pick up fixes after the first run errored partway; targeting a freshly `git init`-ed repo (the .git directory makes it non-empty); pointing at the Jekyll source directory itself by mistake.","solutions":["If overwriting the existing contents is intended (e.g. a re-run), add --force: `hugo import jekyll <src> <target> --force`.","Otherwise choose a new empty/non-existent target directory and merge results manually afterwards.","If the only content is .git, either use --force (import won't touch .git) or import to a temp dir and move files into the repo."],"exampleFix":"# before\nhugo import jekyll ./old-blog ./new-site   # ./new-site has .git\n# after\nhugo import jekyll ./old-blog ./new-site --force","handlingStrategy":"validation","validationCode":"entries, err := os.ReadDir(target)\nif err == nil && len(entries) > 0 {\n    return fmt.Errorf(\"%q is not empty; use a fresh directory or pass --force\", target)\n}","typeGuard":"func isEmptyDir(path string) bool {\n    entries, err := os.ReadDir(path)\n    return err == nil && len(entries) == 0\n}","tryCatchPattern":null,"preventionTips":["Import into a brand-new empty directory to avoid clobbering existing content","Check emptiness with os.ReadDir before invoking the import","Use the --force flag deliberately and only after backing up the target"],"tags":["hugo","import","jekyll","cli","safety-check"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}