feat(config): move sync-branch to config.yaml as source of truth

Previously sync.branch was stored in the database via bd config set.
Now it is in config.yaml (version controlled, shared across clones):

  sync-branch: "beads-sync"

Changes:
- Add sync-branch to .beads/config.yaml
- Update syncbranch.Get() to check config.yaml before database
- Add syncbranch.GetFromYAML() and IsConfigured() for fast checks
- Update hooks to read sync-branch from config.yaml directly
- Update bd doctor to check config.yaml instead of database
- Remove auto-fix (config.yaml changes should be committed)

Precedence: BEADS_SYNC_BRANCH env > config.yaml > database (legacy)

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-11-30 11:15:49 -08:00
parent d02905a4fa
commit 978cb1c31f
8 changed files with 117 additions and 158 deletions

View File

@@ -6,6 +6,7 @@ import (
"os"
"regexp"
"github.com/steveyegge/beads/internal/config"
"github.com/steveyegge/beads/internal/storage"
)
@@ -13,6 +14,9 @@ const (
// ConfigKey is the database config key for sync branch
ConfigKey = "sync.branch"
// ConfigYAMLKey is the config.yaml key for sync branch
ConfigYAMLKey = "sync-branch"
// EnvVar is the environment variable for sync branch
EnvVar = "BEADS_SYNC_BRANCH"
)
@@ -57,10 +61,11 @@ func ValidateBranchName(name string) error {
// Get retrieves the sync branch configuration with the following precedence:
// 1. BEADS_SYNC_BRANCH environment variable
// 2. sync.branch from database config
// 3. Empty string (meaning use current branch)
// 2. sync-branch from config.yaml (version controlled, shared across clones)
// 3. sync.branch from database config (legacy, for backward compatibility)
// 4. Empty string (meaning use current branch)
func Get(ctx context.Context, store storage.Storage) (string, error) {
// Check environment variable first
// Check environment variable first (highest priority)
if envBranch := os.Getenv(EnvVar); envBranch != "" {
if err := ValidateBranchName(envBranch); err != nil {
return "", fmt.Errorf("invalid %s: %w", EnvVar, err)
@@ -68,7 +73,15 @@ func Get(ctx context.Context, store storage.Storage) (string, error) {
return envBranch, nil
}
// Check database config
// Check config.yaml (version controlled, shared across clones)
if yamlBranch := config.GetString(ConfigYAMLKey); yamlBranch != "" {
if err := ValidateBranchName(yamlBranch); err != nil {
return "", fmt.Errorf("invalid %s in config.yaml: %w", ConfigYAMLKey, err)
}
return yamlBranch, nil
}
// Check database config (legacy, for backward compatibility)
dbBranch, err := store.GetConfig(ctx, ConfigKey)
if err != nil {
return "", fmt.Errorf("failed to get %s from config: %w", ConfigKey, err)
@@ -83,6 +96,23 @@ func Get(ctx context.Context, store storage.Storage) (string, error) {
return dbBranch, nil
}
// GetFromYAML retrieves sync branch from config.yaml only (no database lookup).
// This is useful for hooks and checks that need to know if sync-branch is configured
// in the version-controlled config without database access.
func GetFromYAML() string {
// Check environment variable first
if envBranch := os.Getenv(EnvVar); envBranch != "" {
return envBranch
}
return config.GetString(ConfigYAMLKey)
}
// IsConfigured returns true if sync-branch is configured in config.yaml or env var.
// This is a fast check that doesn't require database access.
func IsConfigured() bool {
return GetFromYAML() != ""
}
// Set stores the sync branch configuration in the database
func Set(ctx context.Context, store storage.Storage, branch string) error {
if err := ValidateBranchName(branch); err != nil {