mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
fix(scripts): the comment check names a git too old for check-attr --source (#7750)
This commit is contained in:
@@ -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"],
|
||||
|
||||
@@ -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"/,
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user