fix(sync): handle detached HEAD in bd sync --status

Add getCurrentBranchOrHEAD() which returns "HEAD" when in detached HEAD
state instead of failing. This fixes bd sync --status for jj/jujutsu users.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Phredrick Phool
2026-01-12 07:09:25 -06:00
parent 465f39b366
commit 228b7195b1
2 changed files with 93 additions and 1 deletions

View File

@@ -22,6 +22,18 @@ func getCurrentBranch(ctx context.Context) (string, error) {
return strings.TrimSpace(string(output)), nil
}
// getCurrentBranchOrHEAD returns the current branch name, or "HEAD" if in detached HEAD state.
// This is useful for jj/jujutsu compatibility where HEAD is always detached but we still
// need a reference for git operations like log and diff.
func getCurrentBranchOrHEAD(ctx context.Context) (string, error) {
branch, err := getCurrentBranch(ctx)
if err != nil {
// Detached HEAD - return "HEAD" as the reference
return "HEAD", nil
}
return branch, nil
}
// getSyncBranch returns the configured sync branch name
func getSyncBranch(ctx context.Context) (string, error) {
// Ensure store is initialized
@@ -47,7 +59,7 @@ func showSyncStatus(ctx context.Context) error {
return fmt.Errorf("not in a git repository")
}
currentBranch, err := getCurrentBranch(ctx)
currentBranch, err := getCurrentBranchOrHEAD(ctx)
if err != nil {
return err
}