fix(dev-infra): preserve worktree path whitespace

This commit is contained in:
Tianyi Cui
2026-07-27 20:07:45 +08:00
parent 4aa7c9d0e1
commit 10b82b78ce
5 changed files with 26 additions and 9 deletions
+10 -1
View File
@@ -159,8 +159,17 @@ function diffPaths(root: string, args: string[], context: string): string[] {
], context))
}
function stripGitLineTerminator(output: string): string {
const withoutLineFeed = output.endsWith('\n') ? output.slice(0, -1) : output
return process.platform === 'win32' && withoutLineFeed.endsWith('\r')
? withoutLineFeed.slice(0, -1)
: withoutLineFeed
}
function collectReport(options: ChangeScopeOptions, cwd: string): ChangeScopeReport {
const root = requireGit(cwd, ['rev-parse', '--show-toplevel'], 'cannot locate a Git worktree').trim()
const root = stripGitLineTerminator(
requireGit(cwd, ['rev-parse', '--show-toplevel'], 'cannot locate a Git worktree'),
)
const baseSha = resolveCommit(root, 'base', options.base)
const headSha = resolveCommit(root, 'head', options.head)
const mergeBaseSha = resolveMergeBase(root, baseSha, headSha)