From d91f92802a34373e351ca43e7075fbdd7876e3ba Mon Sep 17 00:00:00 2001 From: Steve Yegge Date: Mon, 1 Dec 2025 20:39:27 -0800 Subject: [PATCH] fix(doctor): detect when on sync branch (bd-epn follow-up) Add detection for when the current branch is the configured sync branch. This is a misconfiguration that causes bd sync to fail with: fatal: 'beads-sync' is already used by worktree The doctor now reports this as an error with a clear fix: Switch to your main working branch: git checkout main Also shows current branch info in the OK case for better visibility. --- cmd/bd/doctor.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/cmd/bd/doctor.go b/cmd/bd/doctor.go index 3698ca59..5b488165 100644 --- a/cmd/bd/doctor.go +++ b/cmd/bd/doctor.go @@ -2045,18 +2045,40 @@ func checkSyncBranchConfig(path string) doctorCheck { // This is the source of truth for multi-clone setups syncBranch := syncbranch.GetFromYAML() + // Get current branch + currentBranch := "" + cmd := exec.Command("git", "symbolic-ref", "--short", "HEAD") + cmd.Dir = path + if output, err := cmd.Output(); err == nil { + currentBranch = strings.TrimSpace(string(output)) + } + + // CRITICAL: Check if we're on the sync branch - this is a misconfiguration + // that will cause bd sync to fail trying to create a worktree for a branch + // that's already checked out + if syncBranch != "" && currentBranch == syncBranch { + return doctorCheck{ + Name: "Sync Branch Config", + Status: statusError, + Message: fmt.Sprintf("On sync branch '%s'", syncBranch), + Detail: fmt.Sprintf("Currently on branch '%s' which is configured as the sync branch. bd sync cannot create a worktree for a branch that's already checked out.", syncBranch), + Fix: "Switch to your main working branch: git checkout main", + } + } + if syncBranch != "" { return doctorCheck{ Name: "Sync Branch Config", Status: statusOK, Message: fmt.Sprintf("Configured (%s)", syncBranch), + Detail: fmt.Sprintf("Current branch: %s, sync branch: %s", currentBranch, syncBranch), } } // Not configured - this is optional but recommended for multi-clone setups // Check if this looks like a multi-clone setup (has remote) hasRemote := false - cmd := exec.Command("git", "remote") + cmd = exec.Command("git", "remote") cmd.Dir = path if output, err := cmd.Output(); err == nil && len(strings.TrimSpace(string(output))) > 0 { hasRemote = true