* feat(init): add --init-if-missing for idempotent init (#3490)
bd init aborts with exit 1 when the workspace is already initialized,
forcing scaffold scripts to pre-stat .beads/embeddeddolt/<prefix> to tell
"already initialized" (benign) apart from real errors. Add an opt-in
--init-if-missing flag: when the workspace already exists, init prints a
benign "Skipping init: workspace already initialized." to stderr and exits 0.
Default behavior (flag absent) is unchanged - exit 1 with the existing
"already initialized ... Aborting" message.
The flag is intercepted only at the existing checkExistingBeadsData guard
call site; detection logic and the --force/--reinit-local paths are untouched.
Docs regenerated via scripts/generate-cli-docs.sh and generate-llms-full.sh.
Co-authored-by: Cursor <cursoragent@cursor.com>
* fix(init): abort --init-if-missing on explicit prefix mismatch
--init-if-missing silently skipped whenever a workspace already existed,
even if the caller passed an explicit --prefix that differed from the
existing workspace. That masked a real mismatch: `bd init --prefix bar
--init-if-missing` against an existing `foo` workspace exited 0 and
ignored the requested prefix.
Now, when --prefix is set explicitly (and --database is not), compare the
requested prefix against the existing workspace's recorded DoltDatabase
and abort on a genuine mismatch; matching or undeterminable cases still
skip benignly. Extracts the prefix->dbName normalization into shared
helpers so the guard derives exactly the same name init records, and
factors the decision into a pure, unit-tested helper.
Refs #3490
Co-authored-by: Cursor <cursoragent@cursor.com>
* fix(init): don't mask operational errors or --database mismatch under --init-if-missing
Two idempotent-init correctness fixes on top of #4332 (reviewer Bernoulli):
1. checkExistingBeadsData now distinguishes the benign "already initialized"
outcome (errWorkspaceAlreadyInitialized, carried by a workspaceExistsError
that keeps the user-facing message) from operational errors such as an
unreadable .beads/embeddeddolt directory. --init-if-missing skips only the
benign case; an operational error still aborts instead of being masked as a
successful idempotent skip.
2. An explicit --database mismatch now aborts --init-if-missing, mirroring the
existing --prefix guard. --database is the authoritative database selector,
so it is checked even when --prefix is also set.
Tests: initIfMissingDatabaseMismatch table; checkExistingBeadsDataAt returns a
sentinel-matching error for an existing database and a non-matching
(operational) error when embeddeddolt is unreadable.
Agent-Signature: claude-opus-4-8-high on behalf of maphew
---------
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: matt wilkie <maphew@gmail.com>