fix(scripts): the comment check names a git too old for check-attr --source (#7750)

This commit is contained in:
Miguel Ángel
2026-11-14 17:00:47 +00:00
committed by GitHub
parent 29533f631f
commit 8e0f196a8b
2 changed files with 40 additions and 1 deletions
+11
View File
@@ -885,8 +885,19 @@ export function checkComments(root, files, scope = { kind: "all" }) {
return { failures: [...failures, ...blockFailures], warnings, examined };
}
function requireCheckAttrSource(root) {
const version = execFileSync("git", ["version"], { cwd: root, encoding: "utf8" }).trim();
const [major, minor] = (version.match(/(\d+)\.(\d+)/) ?? []).slice(1).map(Number);
if (major < 2 || (major === 2 && minor < 40)) {
throw new Error(
`The comment check reads attributes at a ref with \`git check-attr --source\`, which needs git 2.40 or newer; found "${version}".`,
);
}
}
export function generatedPaths(root, ref, paths) {
if (paths.length === 0) return new Set();
requireCheckAttrSource(root);
const attributes = execFileSync(
"git",
["check-attr", `--source=${ref}`, "-z", "--stdin", "linguist-generated"],
+29 -1
View File
@@ -9,7 +9,7 @@ import path from "node:path";
import { test } from "node:test";
import { fileURLToPath } from "node:url";
import { PROBE, checkComments } from "./check-comment-citations.mjs";
import { PROBE, checkComments, generatedPaths } from "./check-comment-citations.mjs";
const CHECKER = fileURLToPath(new URL("./check-comment-citations.mjs", import.meta.url));
@@ -1013,3 +1013,31 @@ test("a TypeScript private field is code, not a standalone comment", (t) => {
});
assert.deepEqual(warnings, []);
});
test("a git too old for check-attr --source is named, not hidden behind EPIPE", (t) => {
const bin = mkdtempSync(path.join(tmpdir(), "old-git-"));
t.after(() => rmSync(bin, { recursive: true, force: true }));
const git = path.join(bin, "git");
writeFileSync(
git,
[
"#!/bin/sh",
'if [ "$1" = version ]; then echo "git version 2.39.5"; exit 0; fi',
'echo "error: unknown option \\`source=HEAD\'" >&2',
"exit 129",
"",
].join("\n"),
{ mode: 0o755 },
);
const savedPath = process.env.PATH;
process.env.PATH = `${bin}${path.delimiter}${savedPath}`;
t.after(() => {
process.env.PATH = savedPath;
});
const paths = Array.from({ length: 20_000 }, (_, i) => `packages/core/src/file-${i}.ts`);
assert.throws(
() => generatedPaths(bin, "HEAD", paths),
/needs git 2\.40 or newer; found "git version 2\.39\.5"/,
);
});