fix(ci): preserve line breaks in Git blob paths (#12227)

This commit is contained in:
ShuaixinHuang authored and GitHub committed 2026-11-19 06:34:57 -05:00
1 parent 1a89383a79
commit fedf33eb59
2 files changed
+21 -3

No files matched your search

+3 -3
View File
@@ -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();
@@ -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"],
]),
);
});