Repository navigation
Description
What I observed
parseRemoteRefWithRemoteNames (apps/server/src/git/remoteRefs.ts:20,30) and extractBranchNameFromRemoteRef (apps/server/src/git/remoteRefs.ts:51,70) call JS String.prototype.trim(), which strips legal Git non-ASCII Unicode whitespace such as NBSP (\u00a0, e.g. macOS Option+Space) and CJK full-width space (\u3000, common under Japanese/Chinese IMEs).
Git itself accepts those characters in branch names (git check-ref-format --branch succeeds), and T3 Code's own sanitizeNewRefName (packages/shared/src/git.ts:313) explicitly preserves \u00a0. However, trimming them in remoteRefs.ts corrupts the parsed branch name (or returns null if the branch name is solely \u00a0/\u3000), breaking startFromOrigin worktree fetches, remote-tracking commit lookups, listRefs default-branch matching, and PR branch matching.
Reproduction
- Commit:
main @ 9d3054a7bb - Environment: macOS 27.2.1, Node v26.13.1, git 2.56.1
Run from the repo root (creates a real Git branch with a trailing CJK full-width space \u3000; also reproduces with \u00a0):
node --experimental-strip-types -e '
import { execFileSync } from "node:child_process";
import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import {
extractBranchNameFromRemoteRef,
parseRemoteNames,
parseRemoteRefWithRemoteNames,
} from "./apps/server/src/git/remoteRefs.ts";
const dir = mkdtempSync(join(tmpdir(), "repro-ref-"));
try {
execFileSync("git", ["init", "-q"], { cwd: dir });
execFileSync("git", ["config", "user.email", "a@b.c"], { cwd: dir });
execFileSync("git", ["config", "user.name", "a"], { cwd: dir });
execFileSync("git", ["commit", "-q", "--allow-empty", "-m", "init"], { cwd: dir });
const branch = "feature/メモ\u3000";
execFileSync("git", ["branch", branch], { cwd: dir });
const remoteNames = parseRemoteNames("origin\n");
console.log("git branch created:", JSON.stringify(branch));
console.log("parseRemoteRefWithRemoteNames:", parseRemoteRefWithRemoteNames(`origin/${branch}`, remoteNames));
console.log("extractBranchNameFromRemoteRef:", JSON.stringify(extractBranchNameFromRemoteRef(`refs/remotes/origin/${branch}`, { remoteNames })));
} finally {
rmSync(dir, { recursive: true, force: true });
}
'Expected behavior
Both parseRemoteRefWithRemoteNames and extractBranchNameFromRemoteRef preserve the exact Git branch name "feature/メモ\u3000" (stripping only ASCII whitespace / line endings if needed rather than Unicode whitespace).
Actual behavior
JS .trim() strips the trailing \u3000 (or \u00a0), returning "feature/メモ" instead of "feature/メモ\u3000". Live callers (GitVcsDriverCore.ts resolveWorktreeBaseRemote / fetchWorktreeBaseCommit / resolveRemoteTrackingCommit / listRefs, and GitManager.ts PR head/base branch lookup) then pass the truncated branch name to git fetch / git rev-parse / forge queries and fail.
Evidence
Output from the command above:
git branch created: "feature/メモ "
parseRemoteRefWithRemoteNames: { remoteRef: 'origin/feature/メモ', remoteName: 'origin', branchName: 'feature/メモ' }
extractBranchNameFromRemoteRef: "feature/メモ"
Additional investigation
- How found: Property-based testing of
apps/server/src/git/remoteRefs.tsagainst Unicode branch names, minimized to the plain Node +gitsnippet above. - Verified: Confirmed on
origin/main(9d3054a7bb). Note for any fix:VcsRefinpackages/contracts/src/git.tsalso usesTrimmedNonEmptyStringSchema, which applies.trim()across the RPC boundary and would similarly strip leading/trailing Unicode whitespace if passed over RPC. - Duplicate check: Searched open and closed issues/PRs for
remoteRefs trim,parseRemoteRefWithRemoteNames,extractBranchNameFromRemoteRef, andnon-breaking space branch— no matching issue found. - Impact: Minor edge case affecting repos with remote branch names containing leading/trailing NBSP (
\u00a0) or CJK full-width space (\u3000).
Activity
test(server): remote branch names keep non-ASCII edge whitespace (#41226
fix(contracts): branch names keep Unicode whitespace across the wire
fix(contracts): worktree handoff base ref keeps Unicode whitespace