fix(daemon): check sync-branch upstream for jj/jujutsu compatibility

When sync-branch is configured, check that branch's upstream instead of
current HEAD's upstream. This fixes --auto-push with jj/jujutsu which
always operates in detached HEAD mode.

Adds gitBranchHasUpstream(branch) to check specific branch's upstream
tracking, independent of current HEAD state.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Phredrick Phool
2026-01-12 06:32:21 -06:00
parent 28ff9fe991
commit 78fec4bc45
3 changed files with 157 additions and 7 deletions

View File

@@ -17,6 +17,7 @@ import (
"github.com/steveyegge/beads/internal/daemon"
"github.com/steveyegge/beads/internal/rpc"
"github.com/steveyegge/beads/internal/storage/sqlite"
"github.com/steveyegge/beads/internal/syncbranch"
)
var daemonCmd = &cobra.Command{
@@ -173,10 +174,22 @@ Run 'bd daemon' with no flags to see available options.`,
}
// Check for upstream if auto-push enabled
if autoPush && !gitHasUpstream() {
fmt.Fprintf(os.Stderr, "Error: no upstream configured (required for --auto-push)\n")
fmt.Fprintf(os.Stderr, "Hint: git push -u origin <branch-name>\n")
os.Exit(1)
// When sync-branch is configured, check that branch's upstream instead of current HEAD.
// This fixes compatibility with jj/jujutsu which always operates in detached HEAD mode.
if autoPush {
hasUpstream := false
if syncBranch := syncbranch.GetFromYAML(); syncBranch != "" {
// sync-branch configured: check that branch's upstream
hasUpstream = gitBranchHasUpstream(syncBranch)
} else {
// No sync-branch: check current HEAD's upstream (original behavior)
hasUpstream = gitHasUpstream()
}
if !hasUpstream {
fmt.Fprintf(os.Stderr, "Error: no upstream configured (required for --auto-push)\n")
fmt.Fprintf(os.Stderr, "Hint: git push -u origin <branch-name>\n")
os.Exit(1)
}
}
// Warn if starting daemon in a git worktree