From d47801a6e3847f6974a75a25cbe080e3d1fc2ce4 Mon Sep 17 00:00:00 2001 From: Tianyi Cui <53024+tianyicui@users.noreply.github.com> Date: Mon, 27 Jul 2026 21:21:01 +0800 Subject: [PATCH] fix(dev-infra): preserve exact scope refs --- scripts/change-scope.spec.ts | 14 ++++++++++++++ scripts/change-scope.ts | 6 +++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/scripts/change-scope.spec.ts b/scripts/change-scope.spec.ts index 01829c96dd..db3a80dae7 100644 --- a/scripts/change-scope.spec.ts +++ b/scripts/change-scope.spec.ts @@ -155,6 +155,20 @@ describe('change-scope', () => { expect(report.paths).toEqual({ committed: [], staged: [], unstaged: [], untracked: [] }) }) + it('preserves legal Unicode edge whitespace in branch and upstream names', () => { + const { root } = fixture() + const branch = '\u00a0topic\u3000' + const upstreamBranch = '\u3000upstream\u00a0' + git(root, ['switch', '-c', branch]) + git(root, ['push', 'origin', `HEAD:refs/heads/${upstreamBranch}`]) + git(root, ['branch', '--set-upstream-to', `origin/${upstreamBranch}`]) + + const report = jsonReport(root, 'origin/master') + + expect(report.repository.branch).toBe(branch) + expect(report.repository.upstream).toBe(`origin/${upstreamBranch}`) + }) + it('reports an exact head above a non-master stacked base while dirty paths remain worktree-local', () => { const { root } = fixture() git(root, ['switch', '-c', 'foundation']) diff --git a/scripts/change-scope.ts b/scripts/change-scope.ts index 743346b99e..fdd1c8566d 100644 --- a/scripts/change-scope.ts +++ b/scripts/change-scope.ts @@ -153,16 +153,16 @@ function currentBranch(root: string): string | null { const result = executeGit(root, ['symbolic-ref', '--quiet', '--short', 'HEAD']) if (result.status === 1) return null if (result.status !== 0) throw new Error(`cannot inspect the current branch: ${failureDetail(result)}`) - return result.stdout.trim() + return stripGitLineTerminator(result.stdout) } function configuredUpstream(root: string, branch: string | null): string | null { if (branch === null) return null - const output = requireGit( + const output = stripGitLineTerminator(requireGit( root, ['for-each-ref', '--count=1', '--format=%(upstream:short)', `refs/heads/${branch}`], 'cannot inspect the configured upstream', - ).trim() + )) return output === '' ? null : output }