fix(server): refreshing a checked-out branch keeps trailing Unicode whitespace in its name #48254
main fromrefs/pull/48254/head·opened View on GitHubProblem#
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.preparePullRequestThreadrefreshes 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),readHeadRefreturns"refs/heads/feature"instead of"refs/heads/feature\u00A0". The refresh refuses to advance the branch and reportsonTarget: falseeven when already on target.GitManagerforwardsrefreshed.onTargetasisOnPullRequestHead(apps/server/src/git/GitManager.ts:4242), andgit.preparePullRequestThreadreturns 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), wherebranchis omitted,git update-reftargets the truncated refrefs/heads/featureinstead ofrefs/heads/feature\u00A0, either failing or moving the wrong branch.
Deterministic repro on tested base commit 7b6a2c96f646 (7b6a2c96f646830f10183339c2031141dd2801ca):
- Initialize a repo with two commits on
origin(originalHead->remoteHead), clone/fetch so the local checkout sits atoriginalHead, create a sibling branchfeatureatoriginalHead, and check out the trailing-NBSP branch:git branch feature "$originalHead" git switch -c $'feature\xc2\xa0' "$originalHead" - Call
GitVcsDriver.refreshCheckedOutBranch({ cwd, branch: "feature\u00A0", targetCommit: remoteHead })(named refresh) orrefreshCheckedOutBranch({ cwd, targetCommit: remoteHead })(unnamed refresh). - Observed:
readHeadRefreturns"refs/heads/feature", so the named refresh returns{ headCommit: originalHead, moved: false, onTarget: false }instead of advancingfeature\u00A0, and the unnamed refresh movesrefs/heads/featureinstead ofrefs/heads/feature\u00A0. - Expected:
readHeadRefpreserves"refs/heads/feature\u00A0", advancingrefs/heads/feature\u00A0toremoteHead(onTarget: true, eliminating the false off-head warning on web/desktop and queued-message restore on mobile) while leavingrefs/heads/featureatoriginalHead.
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-> head40a718547694):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:changedon head40a718547694: 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.preparePullRequestThreadforwardsrefreshed.onTargettoisOnPullRequestHead(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:changedexit-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
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XS
Approvability#
Verdict: Approved at
27602fbMacroscope'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).No actionable comments were generated in the recent review.
Walkthrough
-
refreshCheckedOutBranchnow trims ASCII whitespace from symbolicHEADoutput. 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 HEADparsing and refresh coverage
apps/server/src/vcs/GitVcsDriverCore.ts,apps/server/src/vcs/GitVcsDriverCore.test.tsrefreshCheckedOutBranchusestrimAsciiWhitespaceto parse symbolicHEAD. The test checks that explicit and implicit refreshes preserve the branch name ending in a non-breaking space and do not move the separatefeaturebranch.Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers:
stienswout
Merge Risk:
Minimal · up to27602-
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:
4-
Check name Status Explanation Title check 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 … Description check 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-pa… Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check 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-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: main
- File: .coderabbit.config.ts
- Commit: a75e74e
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
94b5c9ff-1898-4631-998e-de1eb4a67b86
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.tsapps/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.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes