* fix(init): refuse --force when remote has Dolt history
bd init --force in a repo whose origin has refs/dolt/data silently
skipped the bootstrap-from-remote path and then wired origin as a Dolt
remote anyway. The next write auto-pushed an orphan history, failing
with "no common ancestor". Recovery options were all destructive.
This change:
- Adds --reinit-local (named-intent replacement for --force) and
--discard-remote (explicit cross-boundary authorization).
- Routes --force to --reinit-local with a DeprecationWarning. --force
continues to work for ≥2 releases.
- Refuses bd init --force / --reinit-local when origin has
refs/dolt/data, unless --discard-remote is also passed. Exit code 10
(ExitRemoteDivergenceRefused).
- Adds stable numeric exit codes for init refusals (10/11/12).
- Adds bd init-safety documenting the full flag surface and the
destroy-token format.
- Adds an internal race-safety re-check: if remote state changes
during the TTY confirmation window, abort rather than overwrite.
- Retrofits the existing destroy-token echo at init.go:231 to not
print a copy-pasteable destructive invocation, matching the new
error-text-no-echo ADR invariant.
Adds:
- cmd/bd/init_safety.go — CheckRemoteSafety chokepoint (pure fn).
- cmd/bd/init_safety_test.go — guard matrix (13 cases) + subprocess
regression test with a synthetic refs/dolt/data fixture.
- docs/adr/0002-init-safety-invariants.md — ADR encoding the five
invariants (single-source identity, scope-bound --force, central
chokepoint, error-text-no-echo, race-safety).
- docs/RECOVERY.md — named recovery playbooks per refusal exit code.
- .github/CODEOWNERS — review ownership for init*.go pointing at the
ADR so future flags must extend the guard matrix.
Historical pattern (git log for cmd/bd/init.go): 8+ prior commits
patched individual surfaces of this class without encoding the
invariant. The guard matrix test is the structural hedge — adding a
new flag or data source is a signal to extend the table, not to add
another `&& !someFlag` at the call site.
(bd-q83)
* fix(init): satisfy lint for origin safety helpers (bd-main-nwo)
---------
Co-authored-by: matt wilkie <maphew@gmail.com>
When running `bd bootstrap` in a fresh clone, probe origin for
refs/dolt/data and automatically clone the existing beads database
instead of creating unrelated state. `bd init` warns if the ref
exists and suggests using `bd bootstrap` instead.
Fixes#2580
Use sync.Once to create a single git repo template at test startup, then
copy the .git directory for each test instead of spawning git init. Reduces
subprocess overhead across cmd/bd, cmd/bd/doctor, and cmd/bd/doctor/fix
packages (-283 lines net).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Executed-By: beads/polecats/quartz
Rig: beads
Role: polecats
Tests were calling stubbed JSONL functions (writeJSONLAtomic, autoImportIfNewer,
validateJSONLIntegrity, etc.) that now return nil/empty after the JSONL sync
removal. Also fixes: --no-daemon flag re-registered as hidden no-op for backward
compat, getProjectRoot uses runtime.Caller to avoid CWD sensitivity, removed
--no-daemon from init test args, added v0.49.6 changelog entries.
Deleted: direct_mode_test.go, jsonl_integrity_test.go, jsonl_lock_test.go,
rename_prefix_jsonl_update_test.go. Trimmed: main_test.go, nodb_test.go,
show_watch_test.go, staleness_test.go.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove dead code that was inadvertently orphaned when PR #918 refactored
the sync flow. The function was never called since v0.47.0.
The function caused GH#1100 by running `git checkout HEAD -- .beads/`
which restored the entire .beads/ directory, overwriting uncommitted
config.yaml changes.
Add regression test (TestConfigPreservedDuringSync) to prevent similar
restoration logic from being reintroduced.
Fixes#1100
Centralizes repository context resolution via RepoContext API, fixing bugs where git commands run in the wrong repo when BEADS_DIR points elsewhere or in worktree scenarios.
- sync_git_test.go: getCurrentBranchOrHEAD now returns 1 value (not 2)
- daemon_basics_test.go: getPIDFileForSocket uses dbPath not socketPath
- daemon_autostart.go: mark unused socketPath param with underscore
These tests were broken by recent refactors that changed function signatures
but didn't update the corresponding test files.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add getCurrentBranchOrHEAD() which returns "HEAD" when in detached HEAD
state instead of failing. This fixes bd sync --status for jj/jujutsu users.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When sync-branch is configured, check that branch's upstream instead of
current HEAD's upstream. This fixes --auto-push with jj/jujutsu which
always operates in detached HEAD mode.
Adds gitBranchHasUpstream(branch) to check specific branch's upstream
tracking, independent of current HEAD state.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add tests for gitHasBeadsChanges and gitHasUncommittedBeadsChanges
functions when .beads directory is redirected to another repo:
- Test non-redirected case (baseline functionality)
- Test redirected case with no changes (clean target repo)
- Test redirected case with changes (modified file in target)
These tests cover the redirect detection logic added in a61cbde6
that uses `git -C <targetRepoDir>` when beadsDir is redirected.
Closes: bd-hxcf
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>