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

@@ -48,6 +48,36 @@ func TestValidateBranchName(t *testing.T) {
}
}
func TestValidateSyncBranchName(t *testing.T) {
tests := []struct {
name string
branch string
wantErr bool
}{
// Valid sync branches
{"beads-sync is valid", "beads-sync", false},
{"feature branch is valid", "feature-branch", false},
{"empty is valid", "", false},
// GH#807: main and master should be rejected for sync branch
{"main is invalid for sync", "main", true},
{"master is invalid for sync", "master", true},
// Standard branch name validation still applies
{"invalid: HEAD", "HEAD", true},
{"invalid: contains ..", "feature..branch", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := ValidateSyncBranchName(tt.branch)
if (err != nil) != tt.wantErr {
t.Errorf("ValidateSyncBranchName(%q) error = %v, wantErr %v", tt.branch, err, tt.wantErr)
}
})
}
}
func newTestStore(t *testing.T) *sqlite.SQLiteStorage {
t.Helper()
store, err := sqlite.New(context.Background(), "file::memory:?mode=memory&cache=private")