fix: Auto-configure sync.branch during bd init (bd-flil)
- bd init now auto-sets sync.branch to current git branch - Fixes 'bd sync --status' error after fresh bd init - Changed all branch detection to use 'git symbolic-ref' instead of 'git rev-parse' to work in fresh repos without commits - Updated init.go, init_team.go, sync.go, version.go 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -210,7 +210,16 @@ With --no-db: creates .beads/ directory and issues.jsonl file instead of SQLite
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Set sync.branch if specified
|
||||
// Set sync.branch: use explicit --branch flag, or auto-detect current branch
|
||||
// This ensures bd sync --status works after bd init (bd-flil)
|
||||
if branch == "" && isGitRepo() {
|
||||
// Auto-detect current branch if not specified
|
||||
currentBranch, err := getGitBranch()
|
||||
if err == nil && currentBranch != "" {
|
||||
branch = currentBranch
|
||||
}
|
||||
}
|
||||
|
||||
if branch != "" {
|
||||
if err := syncbranch.Set(ctx, store, branch); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: failed to set sync branch: %v\n", err)
|
||||
|
||||
@@ -188,13 +188,14 @@ func runTeamWizard(ctx context.Context, store storage.Storage) error {
|
||||
}
|
||||
|
||||
// getGitBranch returns the current git branch name
|
||||
// Uses symbolic-ref instead of rev-parse to work in fresh repos without commits (bd-flil)
|
||||
func getGitBranch() (string, error) {
|
||||
cmd := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD")
|
||||
cmd := exec.Command("git", "symbolic-ref", "--short", "HEAD")
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
||||
return strings.TrimSpace(string(output)), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -470,7 +470,8 @@ func gitPull(ctx context.Context) error {
|
||||
}
|
||||
|
||||
// Get current branch name
|
||||
branchCmd := exec.CommandContext(ctx, "git", "rev-parse", "--abbrev-ref", "HEAD")
|
||||
// Use symbolic-ref to work in fresh repos without commits (bd-flil)
|
||||
branchCmd := exec.CommandContext(ctx, "git", "symbolic-ref", "--short", "HEAD")
|
||||
branchOutput, err := branchCmd.Output()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get current branch: %w", err)
|
||||
@@ -678,8 +679,9 @@ func exportToJSONL(ctx context.Context, jsonlPath string) error {
|
||||
}
|
||||
|
||||
// getCurrentBranch returns the name of the current git branch
|
||||
// Uses symbolic-ref instead of rev-parse to work in fresh repos without commits (bd-flil)
|
||||
func getCurrentBranch(ctx context.Context) (string, error) {
|
||||
cmd := exec.CommandContext(ctx, "git", "rev-parse", "--abbrev-ref", "HEAD")
|
||||
cmd := exec.CommandContext(ctx, "git", "symbolic-ref", "--short", "HEAD")
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to get current branch: %w", err)
|
||||
|
||||
@@ -151,7 +151,8 @@ func resolveBranch() string {
|
||||
}
|
||||
|
||||
// Fallback: try to get branch from git at runtime
|
||||
cmd := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD")
|
||||
// Use symbolic-ref to work in fresh repos without commits (bd-flil)
|
||||
cmd := exec.Command("git", "symbolic-ref", "--short", "HEAD")
|
||||
cmd.Dir = "."
|
||||
if output, err := cmd.Output(); err == nil {
|
||||
if branch := strings.TrimSpace(string(output)); branch != "" && branch != "HEAD" {
|
||||
|
||||
Reference in New Issue
Block a user