From fedf33eb597538b4e8d60ac0058350bfb2e16650 Mon Sep 17 00:00:00 2001 From: ShuaixinHuang <1836656514@qq.com> Date: Thu, 19 Nov 2026 19:34:57 +0800 Subject: [PATCH] fix(ci): preserve line breaks in Git blob paths (#12227) --- scripts/ci/change-plan.mjs | 6 +++--- .../boundary/filesystem/ciChangeScope.test.ts | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/scripts/ci/change-plan.mjs b/scripts/ci/change-plan.mjs index d27fb015b8..7478b0f97b 100644 --- a/scripts/ci/change-plan.mjs +++ b/scripts/ci/change-plan.mjs @@ -450,11 +450,11 @@ export const gitRepository = (cwd = process.cwd()) => { git("ls-tree", "-r", "-z", "--name-only", revision, "--", ...directories) .split("\0") .filter(Boolean), - // One batch process reads every requested blob. + // NUL-terminate requests so a line break in a path remains part of its name. readFiles: (revision, paths) => { - const output = execFileSync("git", ["cat-file", "--batch"], { + const output = execFileSync("git", ["cat-file", "--batch", "-z"], { cwd, - input: paths.map((path) => `${revision}:${path}\n`).join(""), + input: paths.map((path) => `${revision}:${path}\0`).join(""), maxBuffer: 512 * 1024 * 1024, }); const contents = new Map(); diff --git a/tests/boundary/filesystem/ciChangeScope.test.ts b/tests/boundary/filesystem/ciChangeScope.test.ts index 79381f20e9..1f10422ac4 100644 --- a/tests/boundary/filesystem/ciChangeScope.test.ts +++ b/tests/boundary/filesystem/ciChangeScope.test.ts @@ -2275,3 +2275,21 @@ it.each([ }); }, ); + +it("reads a Git blob whose path contains a line break alongside an ordinary blob", async ({ + skip, +}) => { + skip( + process.platform === "win32", + "Windows paths cannot contain line breaks", + ); + const { directory } = await fixture(); + const path = "src/two\nlines.test.ts"; + const head = await change(directory, [path], "multiline path\n"); + expect(gitRepository(directory).readFiles(head, [path, "README.md"])).toEqual( + new Map([ + [path, "multiline path\n"], + ["README.md", "Initial fixture content\n"], + ]), + ); +});