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

@@ -57,9 +57,17 @@ func gitHasUpstream() bool {
}
branch := strings.TrimSpace(string(branchOutput))
// Check if remote and merge refs are configured
remoteCmd := exec.Command("git", "config", "--get", fmt.Sprintf("branch.%s.remote", branch)) //nolint:gosec // G204: branch from git symbolic-ref
mergeCmd := exec.Command("git", "config", "--get", fmt.Sprintf("branch.%s.merge", branch)) //nolint:gosec // G204: branch from git symbolic-ref
return gitBranchHasUpstream(branch)
}
// gitBranchHasUpstream checks if a specific branch has an upstream configured.
// Unlike gitHasUpstream(), this works even when HEAD is detached (e.g., jj/jujutsu).
// This is critical for sync-branch workflows where the sync branch has upstream
// tracking but the main working copy may be in detached HEAD state.
func gitBranchHasUpstream(branch string) bool {
// Check if remote and merge refs are configured for the branch
remoteCmd := exec.Command("git", "config", "--get", fmt.Sprintf("branch.%s.remote", branch)) //nolint:gosec // G204: branch from caller
mergeCmd := exec.Command("git", "config", "--get", fmt.Sprintf("branch.%s.merge", branch)) //nolint:gosec // G204: branch from caller
remoteErr := remoteCmd.Run()
mergeErr := mergeCmd.Run()