Files
beads/cmd/bd/doctor/fix/sync_branch.go
Steve Yegge 76e3f27eb0 fix: CI test failures and lint errors
- Fixed test file naming: issues.jsonl -> beads.jsonl
  - beads_test.go: Update expected path in TestFindJSONLPath
  - internal/beads/beads_test.go: Update TestFindJSONLPathDefault
  - cmd/bd/main_test.go: Update TestAutoFlushJSONLContent

- Fixed lint errors (gosec):
  - G304: Added nosec comments for file operations with user-provided paths
  - G204: Added nosec comment for subprocess with controlled binary path

- Fixed lint errors (errcheck):
  - cmd/bd/test_wait_helper.go: Acknowledge error return values with _
  - cmd/bd/onboard.go: Handle fmt.Fprintf error return

All tests passing locally. All lint checks passing.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-24 00:21:01 -08:00

45 lines
1.1 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
// #nosec G204 - bdBinary is controlled by getBdBinary() which returns os.Executable()
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
}