Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): refreshing a checked-out branch keeps trailing Unicode whitespace in its name #48254

Opensaphid(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/48254/headopened View on GitHub

Problem

Refreshing a checked-out Git branch whose name ends with valid Unicode whitespace (such as feature\u00A0) fails in GitVcsDriverCore.refreshCheckedOutBranch: readHeadRef trims git symbolic-ref --quiet HEAD with JavaScript's .trim(), stripping trailing Unicode whitespace from the ref name.

In a same-repository Forgejo/Gitea PR whose head branch preserves trailing Unicode whitespace:

  • When GitManager.preparePullRequestThread refreshes a reused worktree (apps/server/src/git/GitManager.ts:4214) or refreshes a newly created worktree for an existing branch (apps/server/src/git/GitManager.ts:4351), readHeadRef returns "refs/heads/feature" instead of "refs/heads/feature\u00A0". The refresh refuses to advance the branch and reports onTarget: false even when already on target. GitManager forwards refreshed.onTarget as isOnPullRequestHead (apps/server/src/git/GitManager.ts:4242), and git.preparePullRequestThread returns that boolean unchanged: web/desktop shows the off-head warning toast (apps/web/src/components/PullRequestThreadDialog.tsx:184), and mobile restores the queued message instead of starting the turn (apps/mobile/src/state/threadOutboxDelivery.ts:1155).
  • On a Local PR checkout (apps/server/src/git/GitManager.ts:4040), where branch is omitted, git update-ref targets the truncated ref refs/heads/feature instead of refs/heads/feature\u00A0, either failing or moving the wrong branch.

Deterministic repro on tested base commit 7b6a2c96f646 (7b6a2c96f646830f10183339c2031141dd2801ca):

  1. Initialize a repo with two commits on origin (originalHead -> remoteHead), clone/fetch so the local checkout sits at originalHead, create a sibling branch feature at originalHead, and check out the trailing-NBSP branch:
    git branch feature "$originalHead"
    git switch -c $'feature\xc2\xa0' "$originalHead"
  2. Call GitVcsDriver.refreshCheckedOutBranch({ cwd, branch: "feature\u00A0", targetCommit: remoteHead }) (named refresh) or refreshCheckedOutBranch({ cwd, targetCommit: remoteHead }) (unnamed refresh).
  3. Observed: readHeadRef returns "refs/heads/feature", so the named refresh returns { headCommit: originalHead, moved: false, onTarget: false } instead of advancing feature\u00A0, and the unnamed refresh moves refs/heads/feature instead of refs/heads/feature\u00A0.
  4. Expected: readHeadRef preserves "refs/heads/feature\u00A0", advancing refs/heads/feature\u00A0 to remoteHead (onTarget: true, eliminating the false off-head warning on web/desktop and queued-message restore on mobile) while leaving refs/heads/feature at originalHead.

Change

Replace result.stdout.trim() with trimAsciiWhitespace(result.stdout) in readHeadRef inside apps/server/src/vcs/GitVcsDriverCore.ts (matching every other git symbolic-ref reader in the same driver), and add a regression test in apps/server/src/vcs/GitVcsDriverCore.test.ts covering named refreshes (both moving and already-on-target) and unnamed refreshes on a branch ending in U+00A0. This fix is scoped to the shared VCS driver (reachable through preserving adapters such as Forgejo/Gitea); GitHub (packages/source-control-github/src/server/gitHubPullRequests.ts:33) and GitCafe have separate upstream branch-name decoders that trim Unicode whitespace before this driver runs and are intentionally left out of this diff.

Scope

Small fix for an obvious bug; no issue needed under CONTRIBUTING.md.

Verification

  • Driver regression test (tested base 7b6a2c96f646 -> head 40a718547694): vp test run apps/server/src/vcs/GitVcsDriverCore.test.ts -t "refreshes a checked-out branch with trailing Unicode whitespace" failed on base (expected { headCommit: remoteHead, moved: true, onTarget: true }, received { headCommit: originalHead, moved: false, onTarget: false }) and passed on head (1 passed).
  • vp run check:changed on head 40a718547694: exit 0 (format, lint, knip, graphql, typecheck across 3 packages, and 433 tests across 2 files passed).
  • Caller-visible path (source trace): Verified in source that GitManager.preparePullRequestThread forwards refreshed.onTarget to isOnPullRequestHead (apps/server/src/git/GitManager.ts:4242), which drives the web/desktop off-head warning (apps/web/src/components/PullRequestThreadDialog.tsx:184) and mobile queued-message restore (apps/mobile/src/state/threadOutboxDelivery.ts:1155).
  • Evidence transcript (real Git CLI + driver before/after test output + check:changed exit-0 summary): https://gist.github.com/saphid/c01091f6792b11e0561a728e3dec7c6f
  • Not shown: The Forgejo/Gitea PR workflow and web/desktop/mobile UI reactions were traced in source rather than executed against a live forge or live client session; no full repo-wide test suite was run; upstream GitHub/GitCafe branch-name decoders that trim Unicode whitespace before the driver runs are not changed here.

Authored by Gemini 4 Neon (Antigravity); reviewed by GPT-6.2 Sol (Codex).

Not shown

  • PR body:15 — Replace the fixture shorthand with a copy-pasteable repro that creates the two commits, a same-repository PR, and an existing worktree on the NBSP branch, then invokes git.preparePullRequestThread and asserts isOnPullRequestHead. The published driver transcript does not execute the app path.
  • PR body:19 — Qualify the Local checkout claim: the unnamed driver regression is covered, but the Forgejo fj checkout path uses pulls/, not the original NBSP branch. Limit the wrong-ref claim to checkout routes that leave the NBSP branch checked out, and list that route as unverified in Not shown.
  • before-after-transcript.md:50 — The linked gist ends at the targeted test pass and does not contain the advertised vp run check:changed output. Append the command, exact HEAD, and exit status, or describe that result as reported rather than linked evidence.
    1. tanstack-source added labelsbug

    2. Approvability

      Verdict: Approved at 27602fb

      Macroscope's review found this PR approvable — Preserves Unicode whitespace in checked-out branch names during refresh by using the existing ASCII-only trimming helper. Existing checkout and branch-update safeguards remain unchanged.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. Explain Change →

      No actionable comments were generated in the recent review.

      Walkthrough

      refreshCheckedOutBranch now trims ASCII whitespace from symbolic HEAD output. A regression test checks explicit and implicit refreshes for a branch name ending in a non-breaking space.

      Changes: Branch refresh

      Layer / File(s)Summary
      Symbolic HEAD parsing and refresh coverage
      apps/server/src/vcs/GitVcsDriverCore.ts, apps/server/src/vcs/GitVcsDriverCore.test.ts
      refreshCheckedOutBranch uses trimAsciiWhitespace to parse symbolic HEAD. The test checks that explicit and implicit refreshes preserve the branch name ending in a non-breaking space and do not move the separate feature branch.

      Estimated code review effort: 2 (Simple) | ~10 minutes

      Change: Bug fix

      Suggested reviewers: stienswout

      Merge Risk: Minimal · up to 27602

      This fixes refreshes of checked-out branches whose names end in Unicode whitespace, which were previously truncated. The change is small and covered by a targeted regression test, so merge risk is minimal.

      Pre-merge checks: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe title names the main change: refreshing a checked-out branch no longer strips trailing Unicode whitespace from the branch name. It follows the conventional commit form and matches the diff, which …
      Description checkPassedThe description follows the template sections (Problem, Change, Scope, Verification) and explains the bug, the one-line fix, and the regression test. Verification is detailed, with the failing-then-pa…
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Full details: Title check

      Explanation

      The title names the main change: refreshing a checked-out branch no longer strips trailing Unicode whitespace from the branch name. It follows the conventional commit form and matches the diff, which replaces the JavaScript trim() in readHeadRef with an ASCII-only trim and adds a regression test.

      Full details: Description check

      Explanation

      The description follows the template sections (Problem, Change, Scope, Verification) and explains the bug, the one-line fix, and the regression test. Verification is detailed, with the failing-then-passing test and the check:changed result. The reviewer notes list gaps: the app-path repro is not copy-pasteable, the Local checkout wrong-ref claim is not fully qualified, the linked gist does not contain the check:changed output, and the Forgejo fj path is unverified. These are gaps in an otherwise complete description, so the check passes with these items to address.

      Finishing Touches

      Generate unit tests (beta)

      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Recent review info

      Run configuration

      Commits

      Reviewing files that changed from the base of the PR and between a75e74eb48d6bb7b758401bc85a8d24d9c690bfa and 27602fb6acd1ba0563aaa1e719d08491ab94bb67.

      Files selected for processing: 2

      • apps/server/src/vcs/GitVcsDriverCore.test.ts
      • apps/server/src/vcs/GitVcsDriverCore.ts

      Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

Sign in to join this conversation.