2026-02-01 08:57:18 +08:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
|
|
import spawn from "nano-spawn";
|
|
|
|
|
|
|
|
|
|
async function getChangedFiles() {
|
|
|
|
|
const { stdout } = await spawn("git", ["diff", "--name-only"]);
|
2026-03-05 01:26:48 +08:00
|
|
|
return stdout ? stdout.split("\n") : [];
|
2026-02-01 08:57:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function ensureNoFilesChanged() {
|
|
|
|
|
const changedFiles = await getChangedFiles();
|
|
|
|
|
|
|
|
|
|
if (changedFiles.length === 0) {
|
|
|
|
|
console.log("✅ No files changed.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log(
|
|
|
|
|
`❌ ${changedFiles.length} file${changedFiles.length === 1 ? "" : "s"} changed:`,
|
|
|
|
|
);
|
|
|
|
|
console.log(changedFiles.map((file) => ` - ${file}`).join("\n"));
|
|
|
|
|
console.log();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await spawn("git", ["diff", "--exit-code"], { stdio: "inherit" });
|
|
|
|
|
} catch (error) {
|
|
|
|
|
process.exitCode = error.exitCode;
|
|
|
|
|
}
|
2026-03-05 01:26:48 +08:00
|
|
|
|
|
|
|
|
process.exitCode ||= 1;
|
2026-02-01 08:57:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await ensureNoFilesChanged();
|