fix: bd sync works when on sync branch (GH#519)
When sync.branch is set to the current branch (e.g., main), bd sync now commits directly instead of failing with a worktree error. Changes: - sync.go: Detect when current branch == sync branch and skip worktree - sync.go: Show appropriate messages for direct-mode commits/pulls - doctor.go: Change from Error to OK status when on sync branch The fix allows users to work directly on the sync branch without having to switch to a different branch for bd sync to work. Closes: GH#519 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2
.beads/.gitignore
vendored
2
.beads/.gitignore
vendored
@@ -30,3 +30,5 @@ beads.right.meta.json
|
|||||||
!issues.jsonl
|
!issues.jsonl
|
||||||
!metadata.json
|
!metadata.json
|
||||||
!config.json
|
!config.json
|
||||||
|
deletions.jsonl
|
||||||
|
deletions.jsonl.migrated
|
||||||
|
|||||||
1754
.beads/issues.jsonl
1754
.beads/issues.jsonl
File diff suppressed because one or more lines are too long
@@ -2498,16 +2498,14 @@ func checkSyncBranchConfig(path string) doctorCheck {
|
|||||||
currentBranch = strings.TrimSpace(string(output))
|
currentBranch = strings.TrimSpace(string(output))
|
||||||
}
|
}
|
||||||
|
|
||||||
// CRITICAL: Check if we're on the sync branch - this is a misconfiguration
|
// GH#519: Check if we're on the sync branch - this is supported but worth noting
|
||||||
// that will cause bd sync to fail trying to create a worktree for a branch
|
// bd sync will commit directly instead of using worktree when on sync branch
|
||||||
// that's already checked out
|
|
||||||
if syncBranch != "" && currentBranch == syncBranch {
|
if syncBranch != "" && currentBranch == syncBranch {
|
||||||
return doctorCheck{
|
return doctorCheck{
|
||||||
Name: "Sync Branch Config",
|
Name: "Sync Branch Config",
|
||||||
Status: statusError,
|
Status: statusOK,
|
||||||
Message: fmt.Sprintf("On sync branch '%s'", syncBranch),
|
Message: fmt.Sprintf("On sync branch '%s' (direct mode)", syncBranch),
|
||||||
Detail: fmt.Sprintf("Currently on branch '%s' which is configured as the sync branch. bd sync cannot create a worktree for a branch that's already checked out.", syncBranch),
|
Detail: fmt.Sprintf("Currently on sync branch '%s'. bd sync will commit directly instead of using worktree.", syncBranch),
|
||||||
Fix: "Switch to your main working branch: git checkout main",
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -377,6 +377,7 @@ Use --merge to merge the sync branch back to main branch.`,
|
|||||||
var syncBranchName string
|
var syncBranchName string
|
||||||
var repoRoot string
|
var repoRoot string
|
||||||
var useSyncBranch bool
|
var useSyncBranch bool
|
||||||
|
var onSyncBranch bool // GH#519: track if we're on the sync branch
|
||||||
if err := ensureStoreActive(); err == nil && store != nil {
|
if err := ensureStoreActive(); err == nil && store != nil {
|
||||||
syncBranchName, _ = syncbranch.Get(ctx, store)
|
syncBranchName, _ = syncbranch.Get(ctx, store)
|
||||||
if syncBranchName != "" && syncbranch.HasGitRemote(ctx) {
|
if syncBranchName != "" && syncbranch.HasGitRemote(ctx) {
|
||||||
@@ -385,7 +386,16 @@ Use --merge to merge the sync branch back to main branch.`,
|
|||||||
fmt.Fprintf(os.Stderr, "Warning: sync.branch configured but failed to get repo root: %v\n", err)
|
fmt.Fprintf(os.Stderr, "Warning: sync.branch configured but failed to get repo root: %v\n", err)
|
||||||
fmt.Fprintf(os.Stderr, "Falling back to current branch commits\n")
|
fmt.Fprintf(os.Stderr, "Falling back to current branch commits\n")
|
||||||
} else {
|
} else {
|
||||||
useSyncBranch = true
|
// GH#519: Check if current branch is the sync branch
|
||||||
|
// If so, commit directly instead of using worktree (which would fail)
|
||||||
|
currentBranch, _ := getCurrentBranch(ctx)
|
||||||
|
if currentBranch == syncBranchName {
|
||||||
|
onSyncBranch = true
|
||||||
|
// Don't use worktree - commit directly to current branch
|
||||||
|
useSyncBranch = false
|
||||||
|
} else {
|
||||||
|
useSyncBranch = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -404,6 +414,9 @@ Use --merge to merge the sync branch back to main branch.`,
|
|||||||
if dryRun {
|
if dryRun {
|
||||||
if useSyncBranch {
|
if useSyncBranch {
|
||||||
fmt.Printf("→ [DRY RUN] Would commit changes to sync branch '%s' via worktree\n", syncBranchName)
|
fmt.Printf("→ [DRY RUN] Would commit changes to sync branch '%s' via worktree\n", syncBranchName)
|
||||||
|
} else if onSyncBranch {
|
||||||
|
// GH#519: on sync branch, commit directly
|
||||||
|
fmt.Printf("→ [DRY RUN] Would commit changes directly to sync branch '%s'\n", syncBranchName)
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("→ [DRY RUN] Would commit changes to git")
|
fmt.Println("→ [DRY RUN] Would commit changes to git")
|
||||||
}
|
}
|
||||||
@@ -424,7 +437,12 @@ Use --merge to merge the sync branch back to main branch.`,
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Regular commit to current branch
|
// Regular commit to current branch
|
||||||
fmt.Println("→ Committing changes to git...")
|
// GH#519: if on sync branch, show appropriate message
|
||||||
|
if onSyncBranch {
|
||||||
|
fmt.Printf("→ Committing changes directly to sync branch '%s'...\n", syncBranchName)
|
||||||
|
} else {
|
||||||
|
fmt.Println("→ Committing changes to git...")
|
||||||
|
}
|
||||||
if err := gitCommitBeadsDir(ctx, message); err != nil {
|
if err := gitCommitBeadsDir(ctx, message); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Error committing: %v\n", err)
|
fmt.Fprintf(os.Stderr, "Error committing: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@@ -440,6 +458,9 @@ Use --merge to merge the sync branch back to main branch.`,
|
|||||||
if dryRun {
|
if dryRun {
|
||||||
if useSyncBranch {
|
if useSyncBranch {
|
||||||
fmt.Printf("→ [DRY RUN] Would pull from sync branch '%s' via worktree\n", syncBranchName)
|
fmt.Printf("→ [DRY RUN] Would pull from sync branch '%s' via worktree\n", syncBranchName)
|
||||||
|
} else if onSyncBranch {
|
||||||
|
// GH#519: on sync branch, regular git pull
|
||||||
|
fmt.Printf("→ [DRY RUN] Would pull directly on sync branch '%s'\n", syncBranchName)
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("→ [DRY RUN] Would pull from remote")
|
fmt.Println("→ [DRY RUN] Would pull from remote")
|
||||||
}
|
}
|
||||||
@@ -506,7 +527,12 @@ Use --merge to merge the sync branch back to main branch.`,
|
|||||||
// Check merge driver configuration before pulling
|
// Check merge driver configuration before pulling
|
||||||
checkMergeDriverConfig()
|
checkMergeDriverConfig()
|
||||||
|
|
||||||
fmt.Println("→ Pulling from remote...")
|
// GH#519: show appropriate message when on sync branch
|
||||||
|
if onSyncBranch {
|
||||||
|
fmt.Printf("→ Pulling from remote on sync branch '%s'...\n", syncBranchName)
|
||||||
|
} else {
|
||||||
|
fmt.Println("→ Pulling from remote...")
|
||||||
|
}
|
||||||
err := gitPull(ctx)
|
err := gitPull(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Check if it's a rebase conflict on beads.jsonl that we can auto-resolve
|
// Check if it's a rebase conflict on beads.jsonl that we can auto-resolve
|
||||||
|
|||||||
Reference in New Issue
Block a user