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.
This commit is contained in:
@@ -2045,18 +2045,40 @@ func checkSyncBranchConfig(path string) doctorCheck {
|
|||||||
// This is the source of truth for multi-clone setups
|
// This is the source of truth for multi-clone setups
|
||||||
syncBranch := syncbranch.GetFromYAML()
|
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 != "" {
|
if syncBranch != "" {
|
||||||
return doctorCheck{
|
return doctorCheck{
|
||||||
Name: "Sync Branch Config",
|
Name: "Sync Branch Config",
|
||||||
Status: statusOK,
|
Status: statusOK,
|
||||||
Message: fmt.Sprintf("Configured (%s)", syncBranch),
|
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
|
// Not configured - this is optional but recommended for multi-clone setups
|
||||||
// Check if this looks like a multi-clone setup (has remote)
|
// Check if this looks like a multi-clone setup (has remote)
|
||||||
hasRemote := false
|
hasRemote := false
|
||||||
cmd := exec.Command("git", "remote")
|
cmd = exec.Command("git", "remote")
|
||||||
cmd.Dir = path
|
cmd.Dir = path
|
||||||
if output, err := cmd.Output(); err == nil && len(strings.TrimSpace(string(output))) > 0 {
|
if output, err := cmd.Output(); err == nil && len(strings.TrimSpace(string(output))) > 0 {
|
||||||
hasRemote = true
|
hasRemote = true
|
||||||
|
|||||||
Reference in New Issue
Block a user