fix(dev-infra): preserve exact scope refs

This commit is contained in:
Tianyi Cui
2026-07-27 21:21:01 +08:00
parent 007e1f4b5a
commit d47801a6e3
2 changed files with 17 additions and 3 deletions

View File

@@ -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'])

View File

@@ -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
}