Skip to content

fix(review): detect remote default branch via ls-remote fallback#609

Merged
backnotprop merged 1 commit intomainfrom
fix/default-branch-detection
Apr 24, 2026
Merged

fix(review): detect remote default branch via ls-remote fallback#609
backnotprop merged 1 commit intomainfrom
fix/default-branch-detection

Conversation

@backnotprop
Copy link
Copy Markdown
Owner

Summary

  • When origin/HEAD isn't set (common in worktrees, manual remotes, long-lived repos), the base picker defaulted to local main instead of upstream origin/main. This made the "prefer upstream" behavior from feat(review): custom base branch for code review (#599) #602 silently ineffective for many users.
  • Adds git ls-remote --symref origin HEAD as a network-based fallback with a 3-second timeout. Detects any default branch name (develop, trunk, etc.) without hardcoded guesses.
  • ReviewGitRuntime.runGit gains an optional timeoutMs param — Bun uses proc.kill() timer, Pi uses spawnSync({ timeout }).

Detection chain (in order)

  1. symbolic-ref origin/HEAD — local, instant. Works when set.
  2. ls-remote --symref origin HEAD — network, 3s timeout. Works for any branch name.
  3. Verify refs/remotes/origin/<detected> exists locally.
  4. Fall back to local main / master — no remote at all.

Test plan

  • Repo without origin/HEAD set: Branch diff / PR Diff should default to origin/main (not local main).
  • Repo with origin/HEAD set: behavior unchanged (step 1 catches it).
  • Offline: 3s delay on first review open, then falls through to local main. No hang, no crash.
  • Repo with non-standard default (e.g. develop): ls-remote detects it correctly.

For provenance purposes, this PR was AI assisted.

@backnotprop backnotprop force-pushed the fix/default-branch-detection branch from 509897c to ee05c9e Compare April 24, 2026 00:58
getDefaultBranch relied on `symbolic-ref refs/remotes/origin/HEAD`
which is commonly unset in worktrees, manual remote setups, and
long-lived repos. When absent, the code fell through to local
`main`/`master`, silently losing the upstream-preference behavior.

Adds `detectRemoteDefaultBranch()` — queries the remote via
`git ls-remote --symref origin HEAD` to find the actual default
branch name (works for any name: develop, trunk, etc.).

The call is fire-and-forget at server startup: non-blocking, runs
concurrently while the browser loads. By the time the user opens
Branch diff or PR Diff (usually 1-2 seconds later), the result has
arrived and `currentBase` has been silently upgraded to the upstream
ref. If offline or slow, the 5-second timeout fires and the local
fallback sticks. If the user has already switched bases manually,
their choice is never overwritten.

`ReviewGitRuntime.runGit` gains an optional `timeoutMs` param. Bun
kills the process via setTimeout + proc.kill(). Pi uses spawnSync's
native `timeout` option. Both treat timeout as a non-zero exit.

For provenance purposes, this commit was AI assisted.
@backnotprop backnotprop force-pushed the fix/default-branch-detection branch from ee05c9e to cbfa0c7 Compare April 24, 2026 01:06
@backnotprop backnotprop merged commit b0c5db9 into main Apr 24, 2026
7 checks passed
@backnotprop backnotprop deleted the fix/default-branch-detection branch April 24, 2026 01:13
backnotprop added a commit that referenced this pull request Apr 24, 2026
Pi's reviewRuntime.runGit used spawnSync, which blocked the Node.js event
loop during git operations. The ls-remote call from #609 could freeze the
HTTP server for up to 5 seconds on slow networks. Now mirrors the Bun
server's async pattern: spawn with piped stdio, kill timer for timeouts,
stream-based stdout/stderr collection.

For provenance purposes, this commit was AI assisted.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant