fix: prevent sync.branch from being set to main/master (#807)

Two issues fixed:
1. `bd init` was auto-detecting current branch (e.g., main) as sync.branch
   when no --branch flag was specified. This caused worktree conflicts.
2. Added validation to reject main/master as sync.branch values.

When sync.branch is set to main, the worktree mechanism creates a checkout
of main at .git/beads-worktrees/main/, which prevents git checkout main
from working in the user's working directory.

The sync branch feature should use a dedicated branch like 'beads-sync'.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Executed-By: beads/crew/dave
Rig: beads
Role: crew
This commit is contained in:
Steve Yegge
2025-12-30 16:45:37 -08:00
parent 6d84701a5f
commit 994512654c
3 changed files with 56 additions and 11 deletions

View File

@@ -287,16 +287,13 @@ With --stealth: configures per-repository git settings for invisible beads usage
os.Exit(1)
}
// Set sync.branch: use explicit --branch flag, or auto-detect current branch
// This ensures bd sync --status works after bd init
if branch == "" && isGitRepo() {
// Auto-detect current branch if not specified
currentBranch, err := getGitBranch()
if err == nil && currentBranch != "" {
branch = currentBranch
}
}
// Set sync.branch only if explicitly specified via --branch flag
// GH#807: Do NOT auto-detect current branch - if sync.branch is set to main/master,
// the worktree created by bd sync will check out main, preventing the user from
// checking out main in their working directory (git error: "'main' is already checked out")
//
// When --branch is not specified, bd sync will commit directly to the current branch
// (the original behavior before sync branch feature)
if branch != "" {
if err := syncbranch.Set(ctx, store, branch); err != nil {
fmt.Fprintf(os.Stderr, "Error: failed to set sync branch: %v\n", err)