Skip to content
This repository was archived by the owner on Jul 29, 2026. It is now read-only.
This repository was archived by the owner on Jul 29, 2026. It is now read-only.

create --force fails whenever the target folder is non-empty #2

Description

@Schmandarine

--force is documented as "Allow scaffolding into a non-empty folder" (src/commands/create.js:25), but it never works on the default path. It only works with --from.

Orientation

node bin/brmbh.js create demo --from ../brmbh-agentic-wp-suite   # local copy path
node bin/brmbh.js create demo                                     # clone path (default)

create has two ways to get the theme files, both in materializeTheme() (src/registry.js:22):

  • --from <path>copyDir() (src/fsutil.js:36), which merges into an existing directory happily
  • default → git clone --depth 1 (src/registry.js:43-47), which refuses a non-empty destination

Repro

mkdir my-site && touch my-site/keep.txt
node bin/brmbh.js create my-site
# → ✗ Folder already exists and is not empty: … / Pass --force to scaffold anyway.   (correct)

node bin/brmbh.js create my-site --force
# → ✗ `git clone --depth 1 https://… my-site` exited with code 128                   (wrong)

git's own message — fatal: destination path 'my-site' already exists and is not an empty directory — is streamed to the terminal, but the CLI's own error is the opaque command_failed exit code. In --json mode the envelope reports {"ok":false,"code":"command_failed"} with no hint that --force is the thing that failed.

Where it goes wrong

src/commands/create.js:37-42 correctly skips the empty-folder guard when --force is set. Execution then falls through to materializeTheme(), which has no concept of --force at all — the flag is never passed to it (src/registry.js:22 takes { dest, from, ref, ctx }).

Options

  1. Clone to a temp dir, then merge — clone into fs.mkdtemp(), delete .git, copyDir() into dest, remove the temp dir. Makes --force behave identically on both paths. Most work, best result.
  2. Download a tarball instead of cloning — extraction over an existing directory just works, and removes the hard git dependency. Bigger change than this issue needs; only worth it if wanted for other reasons.
  3. Make the limitation explicit — if --force and no --from, fail early with a real message: "--force requires --from (git cannot clone into a non-empty folder)". Cheapest, honest, but leaves the flag half-useful.

Recommend option 1.

Acceptance

mkdir my-site && touch my-site/keep.txt
node bin/brmbh.js create my-site --force --skip-install
ls my-site   # → keep.txt AND the theme files

And whichever option is chosen, no path may surface a bare exited with code 128. Use ToolError (src/tool.js:24) with a code and detail so both pretty and --json modes explain the cause.

Note

There is no test suite — package.json declares "test": "node --test test/" but no test/ directory exists. This bug is a good candidate for the first test, if we want one.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions