feat: Respect BEADS_SYNC_BRANCH environment variable

Fixes daemon and bd sync to honor BEADS_SYNC_BRANCH environment variable
as documented in PROTECTED_BRANCHES.md for CI/CD temporary overrides.

Changes:
- Updated internal/syncbranch.Get() to prioritize env var over DB config
- Both daemon sync and bd sync CLI now use syncbranch.Get()
- Added comprehensive tests for env var override behavior
- Validates branch names using git-style rules

This enables CI/CD workflows to override sync branch per-job without
mutating database config.

Based on PR #364 by Charles P. Cross <cpdata@users.noreply.github.com>
Co-authored-by: Charles P. Cross <cpdata@users.noreply.github.com>
This commit is contained in:
Steve Yegge
2025-11-22 18:17:19 -08:00
parent 72aa0d1097
commit 0dc8452c56
6 changed files with 220 additions and 69 deletions

View File

@@ -11,6 +11,7 @@ import (
"github.com/steveyegge/beads/internal/git"
"github.com/steveyegge/beads/internal/storage"
"github.com/steveyegge/beads/internal/syncbranch"
)
// syncBranchCommitAndPush commits JSONL to the sync branch using a worktree
@@ -21,13 +22,13 @@ func syncBranchCommitAndPush(ctx context.Context, store storage.Storage, autoPus
return true, nil // Skip sync branch commit/push in local-only mode
}
// Get sync.branch config
syncBranch, err := store.GetConfig(ctx, "sync.branch")
// Get sync branch configuration (supports BEADS_SYNC_BRANCH override)
syncBranch, err := syncbranch.Get(ctx, store)
if err != nil {
return false, fmt.Errorf("failed to get sync.branch config: %w", err)
return false, fmt.Errorf("failed to get sync branch: %w", err)
}
// If no sync.branch configured, caller should use regular commit logic
// If no sync branch configured, caller should use regular commit logic
if syncBranch == "" {
return false, nil
}
@@ -189,13 +190,13 @@ func syncBranchPull(ctx context.Context, store storage.Storage, log daemonLogger
return true, nil // Skip sync branch pull in local-only mode
}
// Get sync.branch config
syncBranch, err := store.GetConfig(ctx, "sync.branch")
// Get sync branch configuration (supports BEADS_SYNC_BRANCH override)
syncBranch, err := syncbranch.Get(ctx, store)
if err != nil {
return false, fmt.Errorf("failed to get sync.branch config: %w", err)
return false, fmt.Errorf("failed to get sync branch: %w", err)
}
// If no sync.branch configured, caller should use regular pull logic
// If no sync branch configured, caller should use regular pull logic
if syncBranch == "" {
return false, nil
}