diff --git a/cmd/bd/init.go b/cmd/bd/init.go index 055d5498..5403f6af 100644 --- a/cmd/bd/init.go +++ b/cmd/bd/init.go @@ -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) diff --git a/cmd/bd/init_team.go b/cmd/bd/init_team.go index be6b1c18..0a36b341 100644 --- a/cmd/bd/init_team.go +++ b/cmd/bd/init_team.go @@ -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 } diff --git a/cmd/bd/sync.go b/cmd/bd/sync.go index bfb17f0c..0d5f8869 100644 --- a/cmd/bd/sync.go +++ b/cmd/bd/sync.go @@ -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) diff --git a/cmd/bd/version.go b/cmd/bd/version.go index 42d290b0..1e01baa7 100644 --- a/cmd/bd/version.go +++ b/cmd/bd/version.go @@ -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" { diff --git a/internal/storage/sqlite/bench_helpers_test.go b/internal/storage/sqlite/bench_helpers_test.go index 27d8c00b..ce4871ae 100644 --- a/internal/storage/sqlite/bench_helpers_test.go +++ b/internal/storage/sqlite/bench_helpers_test.go @@ -92,14 +92,11 @@ func getCachedOrGenerateDB(b *testing.B, cacheKey string, generateFn func(contex ctx := context.Background() - store, err := New(ctx, dbPath) if err != nil { b.Fatalf("Failed to create storage: %v", err) } - ctx := context.Background() - // Initialize database with prefix if err := store.SetConfig(ctx, "issue_prefix", "bd-"); err != nil { store.Close() diff --git a/internal/storage/sqlite/compact_bench_test.go b/internal/storage/sqlite/compact_bench_test.go index d54359db..4caf6065 100644 --- a/internal/storage/sqlite/compact_bench_test.go +++ b/internal/storage/sqlite/compact_bench_test.go @@ -127,7 +127,6 @@ func setupBenchDB(tb testing.TB) (*SQLiteStorage, func()) { tb.Fatalf("Failed to create storage: %v", err) } - ctx := context.Background() if err := store.SetConfig(ctx, "issue_prefix", "bd"); err != nil { tb.Fatalf("Failed to set issue_prefix: %v", err) }