Преглед на файлове

fix(dev-infra): preserve exact scope refs

Tianyi Cui преди 1 месец
родител
ревизия
d47801a6e3
променени са 2 файла, в които са добавени 17 реда и са изтрити 3 реда
  1. 14 0
      scripts/change-scope.spec.ts
  2. 3 3
      scripts/change-scope.ts

+ 14 - 0
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'])

+ 3 - 3
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
 }