Problem: Existing beads repositories initialized before commit a4c38d5 don't have sync.branch configured. This causes 'bd sync --status' to fail with a confusing error.
Solution: Added new check in 'bd doctor' that detects when sync.branch is not configured and provides automatic fix via 'bd doctor --fix'. The fix automatically sets sync.branch to the current branch using 'git symbolic-ref --short HEAD'.
Changes:
- Added checkSyncBranchConfig() function in doctor.go
- Created fix/sync_branch.go with SyncBranchConfig() fix handler
- Added comprehensive test coverage in doctor_test.go
- Integrated check into applyFixes() switch statement
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package fix
|
|
|
|
import (
|
|
"fmt"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
// SyncBranchConfig fixes missing sync.branch configuration by auto-setting it to the current branch
|
|
func SyncBranchConfig(path string) error {
|
|
if err := validateBeadsWorkspace(path); err != nil {
|
|
return err
|
|
}
|
|
|
|
// Get current branch
|
|
cmd := exec.Command("git", "symbolic-ref", "--short", "HEAD")
|
|
cmd.Dir = path
|
|
output, err := cmd.Output()
|
|
if err != nil {
|
|
return fmt.Errorf("failed to get current branch: %w", err)
|
|
}
|
|
|
|
currentBranch := strings.TrimSpace(string(output))
|
|
if currentBranch == "" {
|
|
return fmt.Errorf("current branch is empty")
|
|
}
|
|
|
|
// Get bd binary
|
|
bdBinary, err := getBdBinary()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Set sync.branch using bd config set
|
|
setCmd := exec.Command(bdBinary, "config", "set", "sync.branch", currentBranch)
|
|
setCmd.Dir = path
|
|
if output, err := setCmd.CombinedOutput(); err != nil {
|
|
return fmt.Errorf("failed to set sync.branch: %w\nOutput: %s", err, string(output))
|
|
}
|
|
|
|
fmt.Printf(" Set sync.branch = %s\n", currentBranch)
|
|
return nil
|
|
}
|