fix(host-service): resolve Against-base diff to local branch when origin/<branch> missing

AN
1mo ago
+167-0

Fixes #5298

Problem

For a stacked workspace whose base is another local branch that has never been pushed, the Changes tab rendered empty — even though a real, committed, non-empty diff existed against that base.

resolveBaseComparison resolved the "Against base" view via the remote ref origin/<base> and, when no upstream was configured, silently fell through to origin/<branch> — a ref that does not exist for an unpushed local base. The diff against a missing ref is empty, so the UI showed nothing.

Fix

In resolveBaseComparison, when no upstream is configured:

  1. if refs/remotes/origin/<branch> exists → baseRef: origin/<branch> + fetch target (unchanged behavior);
  2. new — if the remote ref is absent but refs/heads/<branch> exists (local-only base) → baseRef: <branch> with fetchTarget: null (there is nothing to fetch for a local branch);
  3. otherwise → unchanged fallback.

Validation

Two integration tests against real on-disk repos (same suite as the existing resolveBaseComparison tests):

  • local-only base (exact #5298 repro): base branch checked out locally, never pushed → resolves to baseRef: "feature/stacked", fetchTarget: null;
  • remote + local coexistence: refs/remotes/origin/feature exists → still prefers origin/feature with its fetch target.

bun test on git-helpers.integration.test.ts: 22/22 pass · tsc --noEmit: 0 errors · Biome: clean.


Summary by cubic

Fixes an empty Changes tab for stacked workspaces by resolving the “Against base” diff to a real ref when origin/<branch> is missing. Previously we fell back to origin/<branch> and showed an empty diff; now we probe remotes and use a remote match (prefer origin), otherwise the local branch, so the diff shows actual changes. Addresses #5298.

  • Updated resolveBaseComparison: probe all remotes in parallel; deterministically prioritize origin regardless of remote order; if no remote ref exists but refs/heads/<branch> does, return the local branch with fetchTarget: null.
  • Supports non-origin remotes (fork workflows) and retains preference for origin/<branch> when both remote and local refs exist.
  • Tests: integration covers the full #5298 pipeline (base→diff returns committed work), coexistence and fork cases; unit tests verify parallel probing without wall-clock delays and origin priority.

Summary by CodeRabbit

  • Bug Fixes

    • Improved branch comparison across multiple configured remotes.
    • Prioritizes the standard remote when multiple matching branches are available.
    • Detects branches hosted on other remotes when the standard remote lacks them.
    • Supports local-only branches without unnecessary fetching.
    • Retains the standard fallback when no local or remote branch is available.
  • Tests

    • Added coverage for local, standard-remote, and alternate-remote branch scenarios.