feat(sync): read sync-branch from config.yaml (bd-io0)
sync.branch config was lost on clone because it was only stored in the database (which is gitignored). Now syncbranch.Get() checks: 1. BEADS_SYNC_BRANCH env var (highest) 2. config.yaml sync-branch (tracked, persists across clones) 3. Database config (local override) 4. Empty (use current branch) Changes: - Update syncbranch.Get() to check config.yaml - Update config.yaml template with sync-branch option - Set sync-branch: beads-sync in this repo config.yaml 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -37,6 +37,11 @@ issue-prefix: "bd"
|
||||
# Debounce interval for auto-flush (can also use BEADS_FLUSH_DEBOUNCE)
|
||||
# flush-debounce: "5s"
|
||||
|
||||
# Git branch for beads commits (bd sync will commit to this branch)
|
||||
# IMPORTANT: This setting persists across clones (unlike database config).
|
||||
# Can also use BEADS_SYNC_BRANCH env var for local override.
|
||||
sync-branch: "beads-sync"
|
||||
|
||||
# Integration settings (access with 'bd config get/set')
|
||||
# These are stored in the database, not in this file:
|
||||
# - jira.url
|
||||
@@ -45,4 +50,3 @@ issue-prefix: "bd"
|
||||
# - linear.api-key
|
||||
# - github.org
|
||||
# - github.repo
|
||||
# - sync.branch - Git branch for beads commits (use BEADS_SYNC_BRANCH env var or bd config set)
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1038,6 +1038,13 @@ func createConfigYaml(beadsDir string, noDbMode bool) error {
|
||||
# Debounce interval for auto-flush (can also use BEADS_FLUSH_DEBOUNCE)
|
||||
# flush-debounce: "5s"
|
||||
|
||||
# Git branch for beads commits (bd sync will commit to this branch)
|
||||
# IMPORTANT: Set this for team projects so all clones use the same sync branch.
|
||||
# This setting persists across clones (unlike database config which is gitignored).
|
||||
# Can also use BEADS_SYNC_BRANCH env var for local override.
|
||||
# If not set, bd sync will require you to run 'bd config set sync.branch <branch>'.
|
||||
# sync-branch: "beads-sync"
|
||||
|
||||
# Multi-repo configuration (experimental - bd-307)
|
||||
# Allows hydrating from multiple repositories and routing writes to the correct JSONL
|
||||
# repos:
|
||||
@@ -1054,7 +1061,6 @@ func createConfigYaml(beadsDir string, noDbMode bool) error {
|
||||
# - linear.api-key
|
||||
# - github.org
|
||||
# - github.repo
|
||||
# - sync.branch - Git branch for beads commits (use BEADS_SYNC_BRANCH env var or bd config set)
|
||||
`, noDbLine)
|
||||
|
||||
if err := os.WriteFile(configYamlPath, []byte(configYamlTemplate), 0600); err != nil {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
"regexp"
|
||||
|
||||
"github.com/steveyegge/beads/internal/config"
|
||||
"github.com/steveyegge/beads/internal/storage"
|
||||
)
|
||||
|
||||
@@ -57,10 +58,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 (tracked in git, persists across clones)
|
||||
// 3. sync.branch from database config (local override)
|
||||
// 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 +70,16 @@ func Get(ctx context.Context, store storage.Storage) (string, error) {
|
||||
return envBranch, nil
|
||||
}
|
||||
|
||||
// Check database config
|
||||
// Check config.yaml (tracked in git, persists across clones)
|
||||
// This is the recommended way to configure sync branch for teams
|
||||
if yamlBranch := config.GetString("sync-branch"); yamlBranch != "" {
|
||||
if err := ValidateBranchName(yamlBranch); err != nil {
|
||||
return "", fmt.Errorf("invalid sync-branch in config.yaml: %w", err)
|
||||
}
|
||||
return yamlBranch, nil
|
||||
}
|
||||
|
||||
// Check database config (local override, doesn't persist across clones)
|
||||
dbBranch, err := store.GetConfig(ctx, ConfigKey)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to get %s from config: %w", ConfigKey, err)
|
||||
|
||||
Reference in New Issue
Block a user